-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be8e167
commit c926e9d
Showing
11 changed files
with
199 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
:colspan="c.colSpan" | ||
:rowspan="c.rowSpan" | ||
> | ||
{{ c.date }} | ||
{{ c.label }} | ||
</th> | ||
</tr> | ||
</thead> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useStore } from '@/store'; | ||
import { computed } from 'vue'; | ||
|
||
export default () => { | ||
const store = useStore(); | ||
|
||
const ganttWidth = computed(() => { | ||
return store.ganttHeader.headers[1].length * 30; | ||
}); | ||
|
||
return { ganttWidth }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { day } from '@/utils/date'; | ||
|
||
export enum DateEnum { | ||
'year', | ||
'month', | ||
'day', | ||
'hour', | ||
'minute', | ||
'second', | ||
'millisecond' | ||
} | ||
|
||
/** | ||
* 内部使用的日期对象,所有日期都是用该对象包装 | ||
*/ | ||
export class XDate { | ||
date: Date; | ||
|
||
constructor(date?: Date | number | string) { | ||
this.date = day(date).toDate(); | ||
} | ||
|
||
/** | ||
* 设置一个新日期 | ||
*/ | ||
setDate(date: Date) { | ||
this.date = day(date).toDate(); | ||
} | ||
|
||
/** | ||
* 获取日期的周数文本 | ||
*/ | ||
toWeek() { | ||
return `第 ${day(this.date).week()} 周`; | ||
} | ||
|
||
/** | ||
* 获取日期的月份文本 | ||
*/ | ||
toMonth() { | ||
return `${day(this.date).month() + 1} 月`; | ||
} | ||
|
||
/** | ||
* 获取日期在当月的具体日期的文本 | ||
*/ | ||
toDate() { | ||
return day(this.date).date().toString(); | ||
} | ||
|
||
/** | ||
* 获取两个时间的间隔时间戳 | ||
*/ | ||
intervalTo(date: XDate) { | ||
return this.date.getTime() - date.date.getTime(); | ||
} | ||
|
||
/** | ||
* 比较大小,返回字符,l 左小,r 右小,e 相等 | ||
*/ | ||
compareTo(date: XDate) { | ||
const l = this.date.getTime(); | ||
const r = date.date.getTime(); | ||
if (l < r) return 'l'; | ||
if (l > r) return 'r'; | ||
return 'e'; | ||
} | ||
|
||
/** | ||
* 比较日期大小。 | ||
* @param date 要比较的日期 | ||
* @param precision 精度,可以通过不同单位来调整判断精度 | ||
* @returns 返回字符,l 左小,r 右小,e 相等或比较类似的字符串或等等。 | ||
*/ | ||
isSame(date: XDate, precision: DateUnit) { | ||
if (precision === 'week') { | ||
return day(this.date).week() === day(date.date).week(); | ||
} | ||
|
||
return ( | ||
this.date.toISOString().split(/T|-|:|\./)[DateEnum[precision]] === | ||
date.date.toISOString().split(/T|-|:|\./)[DateEnum[precision]] | ||
); | ||
} | ||
|
||
/** | ||
* 获取一个位移后的日期对象。该对象不会影响原始对象。 | ||
*/ | ||
getOffset(offset: number) { | ||
return new XDate(day(this.date.getTime() + offset).toDate()); | ||
} | ||
|
||
/** | ||
* 通过不同单位获取当前时间的不同精度值 | ||
*/ | ||
getBy(unit: DateUnit) { | ||
if (unit === 'week') return day(this.date).week(); | ||
|
||
return parseInt( | ||
this.date.toLocaleString().split(/\s|\/|:/)[DateEnum[unit]] | ||
); | ||
} | ||
|
||
/** | ||
* 返回一个可格式化的日期字符串 | ||
*/ | ||
toString(format: string = 'YYYY-MM-DD') { | ||
return day(this.date).format(format); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare type HeaderDateUnit = 'week' | 'day' | 'hour' | 'minute' | 'second'; | ||
|
||
declare type DateUnit = 'year' | 'month' | HeaderDateUnit | 'millisecond'; |
Oops, something went wrong.