feat(周星排行榜页): 新增图片预加载缓冲动画,并修复切换按钮的显示问题

This commit is contained in:
hzj 2025-12-25 15:27:40 +08:00
parent ffa3b2e3d2
commit 6f14020d6f

View File

@ -1,6 +1,14 @@
<!-- src/views/Ranking/WeeklyStar/WeeklyStar.vue --> <!-- src/views/Ranking/WeeklyStar/WeeklyStar.vue -->
<template> <template>
<div class="fullPage" :style="{ '--bg-url': `url(${imageUrl('bg')})` }"> <div class="fullPage" :style="{ '--bg-url': `url(${imageUrl('bg')})` }">
<!-- 预加载状态 -->
<div v-if="isLoading" class="loading-container">
<div class="loading-spinner"></div>
<p>{{ $t('loading') }}...</p>
</div>
<!-- 主要内容 -->
<div v-else>
<!-- 状态栏占位区域仅在APP中显示 --> <!-- 状态栏占位区域仅在APP中显示 -->
<div v-if="isInAppEnvironment" style="height: 30px"></div> <div v-if="isInAppEnvironment" style="height: 30px"></div>
@ -124,7 +132,9 @@
</div> </div>
<!-- 主体内容 --> <!-- 主体内容 -->
<div style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; padding: 30% 8% 13%"> <div
style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; padding: 30% 8% 13%"
>
<!-- 前3名 --> <!-- 前3名 -->
<div style="margin-top: 3%"> <div style="margin-top: 3%">
<!-- 第一 --> <!-- 第一 -->
@ -397,7 +407,9 @@
alt="" alt=""
style="width: 15%; display: block; margin-right: 5px" style="width: 15%; display: block; margin-right: 5px"
/> />
<div style="font-weight: 590; font-size: 1.3em">:{{ myFragment.quantity || 0 }}</div> <div style="font-weight: 590; font-size: 1.3em">
:{{ myFragment.quantity || 0 }}
</div>
</div> </div>
<!-- 礼品 --> <!-- 礼品 -->
@ -616,7 +628,12 @@
<!-- 名字 --> <!-- 名字 -->
<div style="position: relative; width: 25%"> <div style="position: relative; width: 25%">
<!-- 背景图 --> <!-- 背景图 -->
<img v-smart-img :src="imageUrl('nameBg')" alt="" style="width: 100%; display: block" /> <img
v-smart-img
:src="imageUrl('nameBg')"
alt=""
style="width: 100%; display: block"
/>
<div <div
style=" style="
position: absolute; position: absolute;
@ -776,6 +793,7 @@
</div> </div>
</maskLayer> </maskLayer>
</div> </div>
</div>
</template> </template>
<script setup> <script setup>
@ -804,6 +822,9 @@ import itemCenter from '@/components/itemCenter.vue'
import maskLayer from '@/components/MaskLayer.vue' import maskLayer from '@/components/MaskLayer.vue'
import TopUser from './components/topUser.vue' import TopUser from './components/topUser.vue'
//
const isLoading = ref(true)
// OSSURL // OSSURL
const imageUrl = (filename) => getPngUrl('Ranking/WeeklyStar/', filename) const imageUrl = (filename) => getPngUrl('Ranking/WeeklyStar/', filename)
@ -811,9 +832,7 @@ const imageUrl = (filename) => getPngUrl('Ranking/WeeklyStar/', filename)
const connectToAppHandler = async () => { const connectToAppHandler = async () => {
await connectToApp(() => { await connectToApp(() => {
// //
getUserInfo() completePreloading() //
updatePageData() //
preloadCriticalImages() //
}) })
} }
@ -1097,19 +1116,20 @@ const getThisWeekMyFragment = async () => {
} }
// //
const updatePageData = () => { const updatePageData = async () => {
getThisWeekRanking() // await Promise.all([
getHistoryRankingTop1() // top1 getThisWeekRanking(), //
getHistoryRankingTop1(), // top1
getThisWeekRewards() // getThisWeekRewards(), //
getThisWeekGifts() // getThisWeekGifts(), //
getThisWeekExchangeGoods() // getThisWeekExchangeGoods(), //
])
} }
// //
const preloadCriticalImages = () => { const preloadCriticalImages = async () => {
const criticalImages = [ const criticalImages = [
imageUrl('bg'), // imageUrl('bg'),
imageUrl('history'), imageUrl('history'),
imageUrl('gifts'), imageUrl('gifts'),
imageUrl('dayBg'), imageUrl('dayBg'),
@ -1140,7 +1160,7 @@ const preloadCriticalImages = () => {
imageUrl('timeNext'), imageUrl('timeNext'),
] ]
preloadImages(criticalImages) await preloadImages(criticalImages)
} }
const debouceGetThisWeekRanking = useThrottle(() => { const debouceGetThisWeekRanking = useThrottle(() => {
@ -1158,6 +1178,19 @@ const observer = new IntersectionObserver((entries) => {
}) })
}) })
//
const completePreloading = async () => {
try {
//
await Promise.all([getUserInfo(), updatePageData(), preloadCriticalImages()])
} catch (error) {
console.error('预加载过程中发生错误:', error)
} finally {
//
isLoading.value = false
}
}
// //
onMounted(() => { onMounted(() => {
connectToAppHandler() connectToAppHandler()
@ -1226,6 +1259,36 @@ onUnmounted(() => {
font-size: 0.8em; font-size: 0.8em;
} }
/* 添加加载动画样式 */
.loading-container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: #666;
}
.loading-spinner {
width: 32px;
height: 32px;
border: 3px solid #f3f3f3;
border-top: 3px solid #f59e0b;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-bottom: 12px;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@media screen and (max-width: 360px) { @media screen and (max-width: 360px) {
* { * {
font-size: 10px; font-size: 10px;