🚸 统一管理时间, 修复计划表按时间显示的错误

This commit is contained in:
MoeSnowyFox
2025-09-14 21:57:03 +08:00
parent f98a749efa
commit 17d7e3bad0
2 changed files with 66 additions and 11 deletions

View File

@@ -0,0 +1,61 @@
/**
* 获取今天是星期几
* @returns {number} 返回数字的星期几 (0-6, 0表示星期日)
*/
export function getTodayWeekday(): number {
const today = new Date()
return today.getDay()
}
/**
* 获取指定日期是星期几
* @param {Date} utcDate UTC时间
* @returns {number} 返回数字的星期几 (0-6, 0表示星期日)
*/
export function getWeekday(utcDate: Date): number {
const today = new Date(utcDate.getTime() + 4 * 3600000)
return today.getDay()
}
/**
* 获取东12区当前时间
* @returns {Date} 返回东12区当前时间的Date对象
*/
export function _getEastTwelveZoneTime(): Date {
const now = new Date()
// 获取UTC时间然后加上12小时
const utcTime = now.getTime() + now.getTimezoneOffset() * 60000
return new Date(utcTime + 4 * 3600000)
}
/**
* 获取东12区今天是星期几
* @returns {number} 返回数字的星期几 (0-6, 0表示星期日)
*/
export function getTodayWeekdayEast12(): number {
const east12Time = _getEastTwelveZoneTime()
return east12Time.getDay()
}
/**
* 获取东12区指定UTC时间对应的星期几
* @param {Date} utcDate UTC时间
* @returns {number} 返回数字的星期几 (0-6, 0表示星期日)
*/
export function getWeekdayEast12(utcDate: Date): number {
const east12Time = new Date(utcDate.getTime() + 4 * 3600000)
return east12Time.getDay()
}
/**
* 将数字的星期几转换为中文
* @param {number} weekday 数字的星期几 (0-6, 0表示星期日)
* @returns {string} 返回中文的星期几
*/
export function getChineseDateString(weekday: number): string {
const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
if (weekday < 0 || weekday > 6) {
throw new Error('weekday must be between 0 and 6')
}
return weekdays[weekday]
}

View File

@@ -1012,6 +1012,7 @@ import { usePlanApi } from '@/composables/usePlanApi'
import { useWebSocket } from '@/composables/useWebSocket'
import { Service } from '@/api'
import { GetStageIn } from '@/api/models/GetStageIn'
import { getTodayWeekdayEast12 } from '@/utils/dateUtils'
const router = useRouter()
const route = useRoute()
@@ -1191,21 +1192,14 @@ const getPlanCurrentConfig = (planData: any) => {
if (mode === 'ALL') {
return planData.ALL || null
} else if (mode === 'Weekly') {
// 获取+12时区的当前时间
const now = new Date()
const utc12Time = new Date(now.getTime() + 12 * 60 * 60 * 1000)
// 如果是凌晨4点前算作前一天
if (utc12Time.getHours() < 4) {
utc12Time.setDate(utc12Time.getDate() - 1)
}
// 使用dateUtils工具直接获取+12时区的今天是星期几已经是数字0-6
const todayWeekday = getTodayWeekdayEast12()
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
const today = weekdays[utc12Time.getDay()]
const today = weekdays[todayWeekday]
console.log('计划表周模式调试:', {
原始时间: now.toISOString(),
UTC12时间: utc12Time.toISOString(),
东12区星期几: todayWeekday,
星期: today,
计划数据: planData,
})