diff --git a/scripts/start.mjs b/scripts/start.mjs index 424f9a065..c8e5cc314 100644 --- a/scripts/start.mjs +++ b/scripts/start.mjs @@ -103,7 +103,8 @@ try { id: -2, workTitle: '距离下班还有', restTitle: '休息啦', - date: dayjs.tz(new Date(2024, 7, 26, 18, 0, 0)).valueOf(), + startDate: new Date(2018, 3, 26, 9, 0, 0).getTime(), + date: new Date(2018, 3, 26, 18, 0, 0).getTime(), } if (idx >= 0) { components[idx] = { diff --git a/src/components/off-work/drawer/index.component.html b/src/components/off-work/drawer/index.component.html index ce288f06e..d3a48747b 100644 --- a/src/components/off-work/drawer/index.component.html +++ b/src/components/off-work/drawer/index.component.html @@ -20,7 +20,13 @@ - {{ $t('_time') }} + {{ $t('_workHours') }} + + + + + + {{ $t('_breakTime') }} diff --git a/src/components/off-work/drawer/index.component.ts b/src/components/off-work/drawer/index.component.ts index 0997a6221..8c3632e34 100644 --- a/src/components/off-work/drawer/index.component.ts +++ b/src/components/off-work/drawer/index.component.ts @@ -5,6 +5,7 @@ import { Component, EventEmitter, Output } from '@angular/core' import { $t } from 'src/locale' import { FormBuilder, FormGroup } from '@angular/forms' +import { NzMessageService } from 'ng-zorro-antd/message' @Component({ selector: 'offwork-drawer', @@ -19,10 +20,11 @@ export class OffWorkDrawerComponent { validateForm!: FormGroup index = 0 - constructor(private fb: FormBuilder) { + constructor(private fb: FormBuilder, private message: NzMessageService) { this.validateForm = this.fb.group({ workTitle: [''], restTitle: [''], + startDate: [null], date: [null], }) } @@ -41,9 +43,15 @@ export class OffWorkDrawerComponent { handleSubmit() { const values = this.validateForm.value + const startDate = new Date(values.startDate).getTime() + const date = new Date(values.date).getTime() + if (startDate >= date) { + return this.message.error('休息时间需要比工作时间大') + } this.ok.emit({ ...values, - date: new Date(values.date).getTime(), + startDate, + date, index: this.index, }) this.handleClose() diff --git a/src/components/off-work/index.component.ts b/src/components/off-work/index.component.ts index f19d09a82..a782f4225 100644 --- a/src/components/off-work/index.component.ts +++ b/src/components/off-work/index.component.ts @@ -55,25 +55,35 @@ export class OffWorkComponent { if (component) { this.component = component const now = new Date() + const nowTime = now.getTime() + const startDate = new Date(component['startDate']) + startDate.setFullYear(now.getFullYear()) + startDate.setMonth(now.getMonth()) + startDate.setDate(now.getDate()) + const startTime = startDate.getTime() const date = new Date(component['date']) date.setFullYear(now.getFullYear()) date.setMonth(now.getMonth()) date.setDate(now.getDate()) - const diffTime = (date.getTime() - now.getTime()) / 1000 + const dateTime = date.getTime() + const diffTime = (dateTime - nowTime) / 1000 const hours = diffTime / (60 * 60) const decimal = Math.floor((hours % 1) * 10) / 10 const minutes = Math.floor((diffTime / 60) % 60) const seconds = Math.floor(diffTime % 60) const hoursDecimal = Math.floor(hours) + decimal - if (diffTime <= 0) { + + if (nowTime >= startTime && nowTime <= dateTime) { + if (hoursDecimal >= 1) { + this.countdownStr = `${hoursDecimal}小时` + } else if (minutes > 0) { + this.countdownStr = `${minutes}分钟` + } else if (seconds >= 0) { + this.countdownStr = `${seconds}秒` + } + } else { this.isRest = true return clearTimeout(this.timer) - } else if (hoursDecimal >= 1) { - this.countdownStr = `${hoursDecimal}小时` - } else if (minutes > 0) { - this.countdownStr = `${minutes}分钟` - } else if (seconds >= 0) { - this.countdownStr = `${seconds}秒` } this.isRest = false } diff --git a/src/locale/english.ts b/src/locale/english.ts index ee038ffab..12e0fb2f1 100644 --- a/src/locale/english.ts +++ b/src/locale/english.ts @@ -271,6 +271,8 @@ const english: Record = { _timeColor: 'Time color', _date: 'Date', _time: 'Time', + _workHours: 'Work hours', + _breakTime: 'Break time', } export default english diff --git a/src/locale/zh_CN.ts b/src/locale/zh_CN.ts index 1bf9438ee..fb8a6153f 100644 --- a/src/locale/zh_CN.ts +++ b/src/locale/zh_CN.ts @@ -263,6 +263,8 @@ const zhCN: Record = { _timeColor: '时间颜色', _date: '日期', _time: '时间', + _workHours: '工作时间', + _breakTime: '休息时间', } export default zhCN