Skip to content

Commit

Permalink
fix: 🐛初始为空数据时,表头无法渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 24, 2023
1 parent f04d632 commit 0ee9a56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
36 changes: 18 additions & 18 deletions demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -537,24 +537,24 @@ export default defineComponent({
// 添加2号数据
this.dataList2 = [
{
index: INDEX++,
startDate: '2021-11-01',
endDate: '2021-11-10',
name: '2号数据: 1'
},
{
index: INDEX++,
startDate: '2021-11-11',
endDate: '2021-11-20',
name: '2号数据: 2'
},
{
index: INDEX++,
startDate: '2021-11-21',
endDate: '2021-11-30',
name: '2号数据: 3'
}
// {
// index: INDEX++,
// startDate: '2021-11-01',
// endDate: '2021-11-10',
// name: '2号数据: 1'
// },
// {
// index: INDEX++,
// startDate: '2021-11-11',
// endDate: '2021-11-20',
// name: '2号数据: 2'
// },
// {
// index: INDEX++,
// startDate: '2021-11-21',
// endDate: '2021-11-30',
// name: '2号数据: 3'
// }
];
// 添加3号数据
Expand Down
16 changes: 8 additions & 8 deletions src/models/param/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ class GanttHeader extends Header {
/**
* 甘特的起始时间(数据起始时间请使用 data.start)
*/
start?: XDate;
start: XDate = new XDate();

/**
* 甘特的结束时间(数据结束时间请使用 data.end)
*/
end?: XDate;
end: XDate = new XDate().getOffset(Variables.time.millisecondOf.day);
unit: HeaderDateUnit = 'day';
minLength: number = 0;

Expand Down Expand Up @@ -249,8 +249,8 @@ class GanttHeader extends Header {
return;

this.unit = unit;
this.start = _start;
this.end = _end;
this.start = _start ?? new XDate();
this.end = _end ?? new XDate().getOffset(Variables.time.millisecondOf.day);
this.minLength = minLen;

this.generate();
Expand All @@ -262,8 +262,8 @@ class GanttHeader extends Header {
// 通过 start 和 end 以及 unit 来生成 columns
const columns: GanttColumn[] = [];

const start = this.start!.date.getTime();
const end = this.end!.date.getTime();
const start = this.start.date.getTime();
const end = this.end.date.getTime();

// TODO 这里可以优化一下,直接一次循环就可以组成 headers。因为是固定格式
let s: number;
Expand Down Expand Up @@ -330,8 +330,8 @@ class GanttHeader extends Header {
setDatesByUnit() {
this.datesByUnit = [];

const start = this.start!.date.getTime();
const end = this.end!.date.getTime();
const start = this.start.date.getTime();
const end = this.end.date.getTime();

let s: number;
for (s = start; s <= end; ) {
Expand Down

0 comments on commit 0ee9a56

Please sign in to comment.