From 9d8d698238eed298615fceb0cc894abf6518ac5a Mon Sep 17 00:00:00 2001 From: shaw Date: Wed, 30 Jul 2025 12:25:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(admin-spa):=20=E4=BF=AE=E5=A4=8D=E6=97=B6?= =?UTF-8?q?=E5=8C=BA=E8=AE=A1=E7=AE=97=E9=97=AE=E9=A2=98=20-=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=9B=BA=E5=AE=9A=E7=9A=84UTC+8=E6=97=B6=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 getSystemTimezoneDay:正确计算UTC+8时区的起止时间 - 修复自定义时间转换:使用固定的UTC+8时区偏移 - 解决了时区数据未初始化导致的计算错误 --- web/admin-spa/src/stores/dashboard.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/web/admin-spa/src/stores/dashboard.js b/web/admin-spa/src/stores/dashboard.js index 35d07d45..728cb74c 100644 --- a/web/admin-spa/src/stores/dashboard.js +++ b/web/admin-spa/src/stores/dashboard.js @@ -94,7 +94,8 @@ export const useDashboardStore = defineStore('dashboard', () => { // 输入:一个本地时间的日期对象(如用户选择的日期) // 输出:该日期在系统时区的0点/23:59对应的UTC时间 function getSystemTimezoneDay(localDate, startOfDay = true) { - const systemTz = dashboardData.value.systemTimezone || 8 + // 固定使用UTC+8,因为后端系统时区是UTC+8 + const systemTz = 8 // 获取本地日期的年月日(这是用户想要查看的日期) const year = localDate.getFullYear() @@ -103,12 +104,12 @@ export const useDashboardStore = defineStore('dashboard', () => { if (startOfDay) { // 创建UTC时间,使其在系统时区(UTC+8)显示为 YYYY-MM-DD 00:00:00 - // 例如:要在UTC+8显示为 2025-07-28 00:00:00,UTC时间应该是 2025-07-27 16:00:00 - const utcDate = new Date(Date.UTC(year, month, day, 0 - systemTz, 0, 0, 0)) + // 例如:要在UTC+8显示为 2025-07-29 00:00:00,UTC时间应该是 2025-07-28 16:00:00 + const utcDate = new Date(Date.UTC(year, month, day - 1, 24 - systemTz, 0, 0, 0)) return utcDate } else { // 创建UTC时间,使其在系统时区(UTC+8)显示为 YYYY-MM-DD 23:59:59.999 - // 例如:要在UTC+8显示为 2025-07-28 23:59:59,UTC时间应该是 2025-07-28 15:59:59 + // 例如:要在UTC+8显示为 2025-07-29 23:59:59,UTC时间应该是 2025-07-29 15:59:59 const utcDate = new Date(Date.UTC(year, month, day, 24 - systemTz - 1, 59, 59, 999)) return utcDate } @@ -181,7 +182,8 @@ export const useDashboardStore = defineStore('dashboard', () => { if (dateFilter.value.customRange && dateFilter.value.customRange.length === 2) { // 使用自定义时间范围 - 需要将系统时区时间转换为UTC const convertToUTC = (systemTzTimeStr) => { - const systemTz = dashboardData.value.systemTimezone || 8 + // 固定使用UTC+8,因为后端系统时区是UTC+8 + const systemTz = 8 // 解析系统时区时间字符串 const [datePart, timePart] = systemTzTimeStr.split(' ') const [year, month, day] = datePart.split('-').map(Number) @@ -273,7 +275,8 @@ export const useDashboardStore = defineStore('dashboard', () => { if (dateFilter.value.customRange && dateFilter.value.customRange.length === 2) { // 使用自定义时间范围 - 需要将系统时区时间转换为UTC const convertToUTC = (systemTzTimeStr) => { - const systemTz = dashboardData.value.systemTimezone || 8 + // 固定使用UTC+8,因为后端系统时区是UTC+8 + const systemTz = 8 // 解析系统时区时间字符串 const [datePart, timePart] = systemTzTimeStr.split(' ') const [year, month, day] = datePart.split('-').map(Number)