diff --git a/.eslintrc.js b/.eslintrc.js index 3ef7a83..cc76f52 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -38,6 +38,8 @@ module.exports = { 'prettier/prettier': ['error', { endOfLine: 'auto' }], 'no-plusplus': 'off', + 'no-fallthrough': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/strict-boolean-expressions': 'off', '@typescript-eslint/no-non-null-assertion': 'off', diff --git a/src/composables/useToday.ts b/src/composables/useToday.ts index df49008..8db1771 100644 --- a/src/composables/useToday.ts +++ b/src/composables/useToday.ts @@ -10,11 +10,11 @@ export default () => { const { $styleBox } = useStyle(); const today = new XDate(); - today.startOf(); + today.startOf(ganttHeader.unit); const todayLeft = computed(() => { const start = ganttHeader.start?.clone(); - start?.startOf(); + start?.startOf(ganttHeader.unit); return ( (today.intervalTo(start) / currentMillisecond.value) * ganttColumnWidth.value diff --git a/src/models/param/date.ts b/src/models/param/date.ts index 4d32503..87ae473 100644 --- a/src/models/param/date.ts +++ b/src/models/param/date.ts @@ -129,12 +129,25 @@ export class XDate { } /** - * 将日期置为当日最开始(0点0分0秒) + * 件日期置为单位的起始位置 */ - startOf() { - this.date.setHours(0); - this.date.setMinutes(0); - this.date.setSeconds(0); - this.date.setMilliseconds(0); + startOf(unit: DateUnit) { + switch (unit) { + case 'year': + this.date.setMonth(0); + case 'month': + this.date.setDate(1); + case 'week': + this.date.setDate(this.date.getDate() - day(this.date).day()); + case 'day': + this.date.setHours(0); + case 'hour': + this.date.setMinutes(0); + case 'minute': + this.date.setSeconds(0); + case 'second': + this.date.setMilliseconds(0); + break; + } } } diff --git a/src/models/param/header.ts b/src/models/param/header.ts index 0a42a05..827908e 100644 --- a/src/models/param/header.ts +++ b/src/models/param/header.ts @@ -215,6 +215,7 @@ class GanttHeader extends Header { ) { this.unit = unit; this.start = start?.getOffset(-Variables.time.millisecondOf[this.unit]); + this.start?.startOf(this.unit); this.end = end; this.minLength = minLen;