fix(admin-spa): 修复时区计算问题 - 使用固定的UTC+8时区

- 修复 getSystemTimezoneDay:正确计算UTC+8时区的起止时间
- 修复自定义时间转换:使用固定的UTC+8时区偏移
- 解决了时区数据未初始化导致的计算错误
This commit is contained in:
shaw
2025-07-30 12:25:51 +08:00
parent 1e82a6af8b
commit 9d8d698238

View File

@@ -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:00UTC时间应该是 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:00UTC时间应该是 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:59UTC时间应该是 2025-07-28 15:59:59
// 例如要在UTC+8显示为 2025-07-29 23:59:59UTC时间应该是 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)