From 4695a82b38a77879ce8dec7659b5427e362794a1 Mon Sep 17 00:00:00 2001 From: sjl <1716605279@qq.com> Date: Thu, 7 Nov 2024 19:40:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83=E6=97=B6=E9=97=B4=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/TimeControl/index.vue | 49 +++++++++++++++---- frontend/src/views/machine/device/index.vue | 2 +- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/TimeControl/index.vue b/frontend/src/components/TimeControl/index.vue index e9e3448..eda6a32 100644 --- a/frontend/src/components/TimeControl/index.vue +++ b/frontend/src/components/TimeControl/index.vue @@ -140,16 +140,38 @@ const updateDateRange = () => { endDate.value = getEndOfWeek(today.value) console.log(endDate.value.toLocaleDateString()) } else if (timeUnit.value === '月') { - startDate.value = new Date(today.value.getFullYear(), today.value.getMonth(), 1) - endDate.value = new Date(today.value.getFullYear(), today.value.getMonth() + 1, 0) - } else if (timeUnit.value === '季度') { - const quarter = Math.floor(today.value.getMonth() / 3) - startDate.value = new Date(today.value.getFullYear(), quarter * 3, 1) - endDate.value = new Date(today.value.getFullYear(), quarter * 3 + 3, 0) - } else if (timeUnit.value === '年') { - startDate.value = new Date(today.value.getFullYear(), 0, 1) - endDate.value = new Date(today.value.getFullYear(), 11, 31) + // 获取本月的开始和结束日期 + startDate.value = new Date(today.value.getFullYear(), today.value.getMonth(), 1); + endDate.value = new Date(today.value.getFullYear(), today.value.getMonth() + 1, 0); + + // 确保结束日期不超过今天 + if (endDate.value > today.value) { + endDate.value = new Date(today.value); + endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999 +} + +} else if (timeUnit.value === '季度') { + const quarter = Math.floor(today.value.getMonth() / 3); + startDate.value = new Date(today.value.getFullYear(), quarter * 3, 1); + endDate.value = new Date(today.value.getFullYear(), quarter * 3 + 3, 0); + + // 确保结束日期不超过今天 + if (endDate.value > today.value) { + endDate.value = new Date(today.value); + endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999 } + +} else if (timeUnit.value === '年') { + startDate.value = new Date(today.value.getFullYear(), 0, 1); + endDate.value = new Date(today.value.getFullYear(), 11, 31); + + // 确保结束日期不超过今天 + if (endDate.value > today.value) { + endDate.value = new Date(today.value); + endDate.value.setHours(23, 59, 59, 999); // 设置结束时间为今天的23:59:59.999 + } +} + updateNextButtonStatus() } const getStartOfWeek = (date: Date) => { @@ -164,7 +186,14 @@ const getEndOfWeek = (date: Date) => { const day = endOfWeek.getDay() const diff = day === 0 ? 0 : 7 - day // 星期天的情况 endOfWeek.setDate(endOfWeek.getDate() + diff) - return endOfWeek + + // 获取今天的日期 + const today = new Date(); + today.setHours(23, 59, 59, 999); // 设置今天的结束时间(23:59:59.999) + + // 返回不超过今天的结束时间 + return endOfWeek > today ? today : endOfWeek; + //return endOfWeek } const prevPeriod = () => { const prevStartDate = new Date(startDate.value) diff --git a/frontend/src/views/machine/device/index.vue b/frontend/src/views/machine/device/index.vue index 17a8792..1665129 100644 --- a/frontend/src/views/machine/device/index.vue +++ b/frontend/src/views/machine/device/index.vue @@ -106,7 +106,7 @@ const columns = reactive[]>([ return (