feat(活动页): 完成每周倒计时

This commit is contained in:
hzj 2025-09-15 16:57:54 +08:00
parent 1bc454319a
commit c61aa22009
3 changed files with 116 additions and 12 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -91,8 +91,60 @@
</div>
</div>
<!-- 刷新倒计时 -->
<div style="display: flex; justify-content: center; margin-top: 20px">
<!-- 天数 -->
<div style="width: 10%; position: relative; margin-right: 10px">
<img
src="/src/assets/images/TopList/dayBg.png"
alt=""
width="100%"
style="display: block"
/>
<div
style="
position: absolute;
inset: 0;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-weight: 860;
"
>
{{ Days }}D
</div>
</div>
<!-- 当天时间倒计时 -->
<div style="width: 23.75%; position: relative">
<img
src="/src/assets/images/TopList/timeBg.png"
alt=""
width="100%"
style="display: block"
/>
<div
style="
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-weight: 860;
"
>
{{ Hours }} : {{ Minutes }} : {{ Second }}
</div>
</div>
</div>
<!-- rewards -->
<div style="display: flex; justify-content: flex-end">
<div style="display: flex; justify-content: flex-end; margin-top: -8%">
<img
src="/src/assets/images/TopList/rewards.png"
alt=""
@ -570,10 +622,7 @@
"
>
<div style="flex: 1; display: flex; align-items: center">
<div style="color: #edb247; font-weight: 700">
<!-- {{ myRanking.ranking }} -->
100
</div>
<div style="color: #edb247; font-weight: 700">{{ myRanking.rank || 0 }}</div>
<div
style="
width: 30%;
@ -621,7 +670,7 @@
<script setup>
import { isInApp } from '../../utils/appBridge.js'
import { computed, onMounted, ref } from 'vue'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import borderImg from '../../components/TopList/borderImg.vue'
import maskLayer from '../../components/MaskLayer.vue'
import {
@ -735,6 +784,50 @@ const debouceGetQueenList = useThrottle(() => {
const gifts = ref([])
//
const Days = ref(0)
const Hours = ref(0)
const Minutes = ref(0)
const Second = ref(0)
let timer = null
const getNextMonday = () => {
const now = new Date()
const day = now.getDay() //0()-6()
//
const daysToAdd = day === 1 ? 7 : (1 + 7 - day) % 7
const nextMonday = new Date(now) //
nextMonday.setDate(now.getDate() + daysToAdd) //
nextMonday.setHours(0, 0, 0, 0) // 00:00:00.000
return nextMonday.getTime() //00:00:00.000
}
// 2
const formatTime = (value) => {
return value < 10 ? `0${value}` : value
}
//
const getCountdown = () => {
const now = Date.now()
const targetTime = getNextMonday()
let diff = targetTime - now
if (diff <= 0) {
diff = getNextMonday() - now
updatePageData() //
}
//
const totalSeconds = Math.floor(diff / 1000)
Days.value = Math.floor(totalSeconds / (3600 * 24)) //totalSeconds / (3600 * 24)取余留天数并用Math.floor取整
Hours.value = formatTime(Math.floor((totalSeconds % (3600 * 24)) / 3600)) //(totalSeconds % (3600 * 24)
Minutes.value = formatTime(Math.floor((totalSeconds % 3600) / 60)) //(totalSeconds % 3600)
Second.value = formatTime(Math.floor(totalSeconds % 60)) //
}
//
const getTopList = async (params) => {
const resWeekTopList = await getWeekTopList(params)
@ -807,15 +900,23 @@ const observer = new IntersectionObserver((entries) => {
})
})
//
onMounted(() => {
isInAppEnvironment.value = isInApp()
//
const updatePageData = () => {
getTopList(kingListParams.value) //
getTopList(queenListParams.value) //
getMyContribution() //
getRewardsAndGifts() //top
getAllTopOne() //
}
//
onMounted(() => {
isInAppEnvironment.value = isInApp()
getCountdown()
timer = setInterval(getCountdown, 1000) //
updatePageData() //
if (kingListLoadmore.value) {
observer.observe(kingListLoadmore.value)
@ -825,13 +926,16 @@ onMounted(() => {
observer.observe(queenListloadmore.value)
} //
})
onUnmounted(() => {
clearInterval(timer)
})
</script>
<style scoped>
* {
color: black;
font-family: 'SF Pro';
font-size: 16px;
}
.fullPage {
@ -864,7 +968,7 @@ onMounted(() => {
@media screen and (min-width: 360px) {
* {
font-size: 12px;
font-size: 16px;
}
.topName {