diff --git a/src/views/Activities/LuckyDollars/Season3/index.vue b/src/views/Activities/LuckyDollars/Season3/index.vue index 5d79bf5..be4c9c8 100644 --- a/src/views/Activities/LuckyDollars/Season3/index.vue +++ b/src/views/Activities/LuckyDollars/Season3/index.vue @@ -2137,14 +2137,42 @@ const showRanking = computed(() => { // return [] }) -// 获取沙特时间的3月19号早上0点的时间戳(直接使用北京时间) -const getTargetTime = () => { - // 沙特时间3月19日0点 = 北京时间3月19日5点(沙特比北京晚5小时) - const targetDate = new Date(2026, 2, 19, 5, 0, 0) +// 沙特时间的3月19号早上0点的截止 +// 获取每周一早上5点的时间戳(沙特时间0点 = 北京时间5点) +const getNextMondayInBeijing = () => { + 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() } -const targetTime = ref(getTargetTime()) +const targetTime = ref(getNextMondayInBeijing()) // 闭包保存目标时间 (核心修正) // 格式化时间 const formatTime = (value) => { @@ -2156,26 +2184,19 @@ const getCountdown = () => { const now = Date.now() let diff = targetTime.value - now - // 如果已过期,显示全零 if (diff <= 0) { - Days.value = 0 - Hours.value = '00' - Minutes.value = '00' - Second.value = '00' + // 初始化数据 + initData() - // 清除定时器 - if (timer) { - clearInterval(timer) - timer = null - } - return + targetTime.value += 7 * 86400000 // +7天 (更新闭包变量) + diff = targetTime.value - now } const totalSeconds = Math.floor(diff / 1000) Days.value = Math.floor(totalSeconds / (24 * 3600)) Hours.value = formatTime(Math.floor((totalSeconds % (24 * 3600)) / 3600)) Minutes.value = formatTime(Math.floor((totalSeconds % 3600) / 60)) - Second.value = formatTime(Math.floor(totalSeconds % 60)) + Seconds.value = formatTime(Math.floor(totalSeconds % 60)) } // 抽屉展示