Skip to content

Commit

Permalink
fix: 🐛修正重设时间后 slider 位置不准确
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 13, 2023
1 parent ab6cced commit 5ad9253
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useToday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions src/models/param/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
1 change: 1 addition & 0 deletions src/models/param/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 5ad9253

Please sign in to comment.