diff --git a/src/assets/images/Lottery/countdownBg.png b/src/assets/images/Lottery/countdownBg.png new file mode 100644 index 0000000..b7ac802 Binary files /dev/null and b/src/assets/images/Lottery/countdownBg.png differ diff --git a/src/views/Activities/Lottery/Lottery.vue b/src/views/Activities/Lottery/Lottery.vue index ac9844b..ba3cdf6 100644 --- a/src/views/Activities/Lottery/Lottery.vue +++ b/src/views/Activities/Lottery/Lottery.vue @@ -9,6 +9,26 @@ + +
+ +
+ {{ formattedCountdown }} +
+
+
@@ -935,8 +955,12 @@ const withdrawShow = ref(false) const selectedCoin = ref(null) -const appConnected = ref(false) -const headerInfo = ref({}) +// 倒计时相关数据 +const Days = ref(0) +const Hours = ref(0) +const Minutes = ref(0) +const Seconds = ref(0) +let countdownTimer = null // 抽屉展示 const drawerShowBt = (type) => { @@ -955,6 +979,52 @@ const handleBt = (type) => { selectedCoin.value = null // 清除选择币种 } +// 获取目标时间(2025年11月10日上午10点,北京时间) +const getTargetTime = () => { + // 直接设置为2025年11月10日上午10点(北京时间) + const target = new Date(2025, 10, 10, 10, 0, 0) // 月份从0开始,10代表11月 + return target.getTime() +} + +// 计算倒计时 +const calculateCountdown = () => { + const now = Date.now() + const targetTime = getTargetTime() + let diff = targetTime - now + + // 如果已过期,清零并停止计时器 + if (diff <= 0) { + Days.value = 0 + Hours.value = '00' + Minutes.value = '00' + Seconds.value = '00' + + if (countdownTimer) { + clearInterval(countdownTimer) + countdownTimer = null + } + return + } + + // 计算天、小时、分钟、秒 + const totalSeconds = Math.floor(diff / 1000) + Days.value = Math.floor(totalSeconds / (24 * 3600)) + Hours.value = String(Math.floor((totalSeconds % (24 * 3600)) / 3600)).padStart(2, '0') + Minutes.value = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0') + Seconds.value = String(Math.floor(totalSeconds % 60)).padStart(2, '0') +} + +// 格式化显示倒计时 +const formattedCountdown = computed(() => { + return `${Days.value}D ${Hours.value}:${Minutes.value}:${Seconds.value}` +}) + +// 启动倒计时 +const startCountdown = () => { + calculateCountdown() // 立即执行一次 + countdownTimer = setInterval(calculateCountdown, 1000) +} + const taskList = ref([]) // 展示任务目标 @@ -1363,6 +1433,7 @@ const connectToAppHandler = async () => { await connectToApp(() => { // 连接成功回调 initData() + startCountdown() // 启动倒计时 }) } @@ -1372,6 +1443,10 @@ onMounted(() => { }) onUnmounted(() => { + if (countdownTimer) { + clearInterval(countdownTimer) + countdownTimer = null + } clearPayee() //清空收款人信息 })