dootask/resources/assets/js/pages/manage/components/dashboard-time-mixin.js
2026-07-18 01:13:43 +00:00

81 lines
2.4 KiB
JavaScript
Vendored
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 仪表盘截止时间人性化显示(个人视角 / 团队概览共用)
*/
export default {
data() {
return {
nowTime: $A.dayjs().unix(),
nowInter: null,
}
},
methods: {
/**
* 截止时间状态 class
* @param endAt
* @returns {string} end-overdue|end-today|''
*/
deadlineClass(endAt) {
if (!endAt) {
return ''
}
const end = $A.dayjs(endAt)
const now = $A.daytz(this.nowTime)
if (end <= now) {
return 'end-overdue'
}
if (end.format('YYYY-MM-DD') === now.format('YYYY-MM-DD')) {
return 'end-today'
}
return ''
},
/**
* 截止时间文案(逾期 N 天 / 今天 HH:mm / 明天 HH:mm / MM-DD
* @param endAt
* @returns {string}
*/
deadlineText(endAt) {
if (!endAt) {
return ''
}
const end = $A.dayjs(endAt)
const now = $A.daytz(this.nowTime)
if (end <= now) {
const days = now.startOf('day').diff(end.startOf('day'), 'day')
if (days > 0) {
return this.$L('逾期 (*) 天', days)
}
return this.$L('逾期 (*) 小时', Math.max(now.diff(end, 'hour'), 1))
}
if (end.format('YYYY-MM-DD') === now.format('YYYY-MM-DD')) {
return `${this.$L('今天')} ${end.format('HH:mm')}`
}
if (end.format('YYYY-MM-DD') === now.clone().add(1, 'day').format('YYYY-MM-DD')) {
return `${this.$L('明天')} ${end.format('HH:mm')}`
}
if (end.year() === now.year()) {
return end.format('MM-DD')
}
return end.format('YYYY-MM-DD')
},
/**
* 时间刷新定时器(驱动 deadline 文案更新)
* @param load
*/
loadInterval(load) {
if (this.nowInter) {
clearInterval(this.nowInter)
this.nowInter = null
}
if (load === false) {
return
}
this.nowInter = setInterval(_ => {
this.nowTime = $A.dayjs().unix()
}, 10 * 1000)
},
}
}