feat(斋月活动): 调整倒计时

This commit is contained in:
hzj 2026-02-12 15:42:28 +08:00
parent 5d40d7e3b4
commit 1002e9a65e

View File

@ -2137,14 +2137,42 @@ const showRanking = computed(() => {
// return [] // return []
}) })
// 3190使 // 3190
const getTargetTime = () => { // 50 = 5
// 3190 = 31955 const getNextMondayInBeijing = () => {
const targetDate = new Date(2026, 2, 19, 5, 0, 0) const now = new Date()
const targetDate = new Date(now.getTime()) //
//
const utcTime = now.getTime() + now.getTimezoneOffset() * 60000
const beijingTime = new Date(utcTime + 8 * 3600000) // UTC+8
const beijingDay = beijingTime.getDay() // 0=, 1=, ..., 6=
const beijingHour = beijingTime.getHours()
// 0=, 1=, ..., 6=
const normalizedDay = beijingDay === 0 ? 6 : beijingDay - 1
let daysToAdd
if (normalizedDay === 0) {
//
if (beijingHour >= 5) {
daysToAdd = 7 // 5
} else {
daysToAdd = 0 //
}
} else {
daysToAdd = 7 - normalizedDay //
}
//
targetDate.setDate(targetDate.getDate() + daysToAdd) //
targetDate.setHours(5, 0, 0, 0) // 5
return targetDate.getTime() return targetDate.getTime()
} }
const targetTime = ref(getTargetTime()) const targetTime = ref(getNextMondayInBeijing()) // ()
// //
const formatTime = (value) => { const formatTime = (value) => {
@ -2156,26 +2184,19 @@ const getCountdown = () => {
const now = Date.now() const now = Date.now()
let diff = targetTime.value - now let diff = targetTime.value - now
//
if (diff <= 0) { if (diff <= 0) {
Days.value = 0 //
Hours.value = '00' initData()
Minutes.value = '00'
Second.value = '00'
// targetTime.value += 7 * 86400000 // +7 ()
if (timer) { diff = targetTime.value - now
clearInterval(timer)
timer = null
}
return
} }
const totalSeconds = Math.floor(diff / 1000) const totalSeconds = Math.floor(diff / 1000)
Days.value = Math.floor(totalSeconds / (24 * 3600)) Days.value = Math.floor(totalSeconds / (24 * 3600))
Hours.value = formatTime(Math.floor((totalSeconds % (24 * 3600)) / 3600)) Hours.value = formatTime(Math.floor((totalSeconds % (24 * 3600)) / 3600))
Minutes.value = formatTime(Math.floor((totalSeconds % 3600) / 60)) Minutes.value = formatTime(Math.floor((totalSeconds % 3600) / 60))
Second.value = formatTime(Math.floor(totalSeconds % 60)) Seconds.value = formatTime(Math.floor(totalSeconds % 60))
} }
// //