Skip to content

Commit

Permalink
fix(日期): 🐛 修复日期在特定情况下表头异常错位
Browse files Browse the repository at this point in the history
fixed: #53
  • Loading branch information
jeremyjone committed Jul 5, 2023
1 parent b908713 commit 89d5730
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/composables/useGanttHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export default () => {
function setGanttHeaders() {
store.ganttHeader.setDate(
// 使用 window 的宽度减去 table 的宽度,就是最小需要的列数,再加一个阈值即可
(window.innerWidth - tableWidth.value) /
getGanttUnitColumnWidth(new Date()) +
5,
Math.ceil(
(window.innerWidth - tableWidth.value) /
getGanttUnitColumnWidth(new Date()) +
5
),
store.$data.start,
store.$data.end,
store.$styleBox.unit
Expand Down
12 changes: 7 additions & 5 deletions src/models/param/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ export class XDate {
case 'year':
this.date.setMonth(date?.date ? day(date.date).month() : 0);
case 'month':
this.date.setDate(date?.date ? day(date.date).date() : 1);
case 'week':
this.date.setDate(
(date?.date ?? this.date).getDate() -
day(date?.date ?? this.date).day()
);
if (unit === 'month')
this.date.setDate(date?.date ? day(date.date).date() : 1);
else if (unit === 'week')
this.date.setDate(
(date?.date ?? this.date).getDate() -
day(date?.date ?? this.date).day()
);
case 'day':
this.date.setHours(date?.date ? day(date.date).hour() : 0);
case 'hour':
Expand Down
8 changes: 6 additions & 2 deletions src/models/param/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,17 @@ class GanttHeader extends Header {
// TODO 这里可以优化一下,直接一次循环就可以组成 headers。因为是固定格式
let s: number;
for (s = start; s <= end; ) {
this.dates.push(new XDate(s));
const d = new XDate(s);
d.startOf(this.unit);
this.dates.push(d);
s += getMillisecondBy(this.unit, s);
}

// 保证要占满所有宽度
while (this.dates.length < this.minLength) {
this.dates.push(new XDate(s));
const d = new XDate(s);
d.startOf(this.unit);
this.dates.push(d);
s += getMillisecondBy(this.unit, s);
}

Expand Down

0 comments on commit 89d5730

Please sign in to comment.