feat(游戏王打榜页): 新增图片预加载缓冲动画,并修复切换按钮的显示问题

This commit is contained in:
hzj 2025-12-25 14:22:27 +08:00
parent e4d532af3e
commit 268adf5c31

View File

@ -1,6 +1,14 @@
<!-- src/views/Activities/Game/index.vue --> <!-- src/views/Activities/Game/index.vue -->
<template> <template>
<div class="fullPage"> <div class="fullPage">
<!-- 预加载状态 -->
<div v-if="isLoading" class="loading-container">
<div class="loading-spinner"></div>
<p>{{ $t('loading') }}...</p>
</div>
<!-- 主要内容 -->
<div v-else>
<!-- 新增的背景图层 --> <!-- 新增的背景图层 -->
<img <img
v-smart-img v-smart-img
@ -78,42 +86,42 @@
<div> <div>
<div style="display: flex; justify-content: space-around; margin-top: 2vw"> <div style="display: flex; justify-content: space-around; margin-top: 2vw">
<!-- 排行榜按钮 --> <!-- 排行榜按钮 -->
<div style="width: 40%; position: relative"> <div style="width: 40%; position: relative" @click="rankingShow = true">
<img <img
v-show="!rankingShow"
v-smart-img v-smart-img
class="toggle-image"
:src="imageUrl(getImgName('rankingBt'))" :src="imageUrl(getImgName('rankingBt'))"
alt="" alt=""
style="display: block; width: 100%" style="display: block; width: 100%"
:style="{ opacity: rankingShow ? 0 : 1 }"
@click="rankingShow = true"
/> />
<img <img
v-show="rankingShow"
v-smart-img v-smart-img
class="toggle-image"
:src="imageUrl(getImgName('rankingBtActive'))" :src="imageUrl(getImgName('rankingBtActive'))"
alt="" alt=""
style="display: block; width: 100%; position: absolute; top: 0; left: 0" style="display: block; width: 100%"
:style="{ opacity: rankingShow ? 1 : 0 }"
@click="rankingShow = true"
/> />
</div> </div>
<!-- 奖励按钮 --> <!-- 奖励按钮 -->
<div style="width: 40%; position: relative"> <div style="width: 40%; position: relative" @click="rankingShow = false">
<img <img
v-show="rankingShow"
v-smart-img v-smart-img
class="toggle-image"
:src="imageUrl(getImgName('rewardsBt'))" :src="imageUrl(getImgName('rewardsBt'))"
alt="" alt=""
style="display: block; width: 100%" style="display: block; width: 100%"
:style="{ opacity: rankingShow ? 1 : 0 }"
@click="rankingShow = false"
/> />
<img <img
v-show="!rankingShow"
v-smart-img v-smart-img
class="toggle-image"
:src="imageUrl(getImgName('rewardBtActive'))" :src="imageUrl(getImgName('rewardBtActive'))"
alt="" alt=""
style="display: block; width: 100%; position: absolute; top: 0; left: 0" style="display: block; width: 100%"
:style="{ opacity: rankingShow ? 0 : 1 }"
@click="rankingShow = false"
/> />
</div> </div>
</div> </div>
@ -122,13 +130,7 @@
<!-- 展示内容 --> <!-- 展示内容 -->
<div> <div>
<!-- Ranking --> <!-- Ranking -->
<div v-show="rankingShow" style="position: relative; width: 100%"> <div v-show="rankingShow" style="position: relative; width: 100%; margin: 10px 0">
<!-- 背景图 -->
<!-- <div
class="ranking-bg"
:style="{ '--ranking-bg-url': `url(${imageUrl('RankingBg')})` }"
></div> -->
<div style="position: relative; z-index: 1"> <div style="position: relative; z-index: 1">
<!-- 第2-4 --> <!-- 第2-4 -->
<itemCenter <itemCenter
@ -404,7 +406,9 @@
align-items: center; align-items: center;
" "
> >
<div style="color: #f9e447; text-align: center; font-size: 1.2em; font-weight: 900"> <div
style="color: #f9e447; text-align: center; font-size: 1.2em; font-weight: 900"
>
7Days 7Days
</div> </div>
</div> </div>
@ -571,6 +575,7 @@
</maskLayer> </maskLayer>
</div> </div>
</div> </div>
</div>
</template> </template>
<script setup> <script setup>
@ -591,6 +596,9 @@ import maskLayer from '@/components/MaskLayer.vue'
const isInAppEnvironment = ref(false) // APP const isInAppEnvironment = ref(false) // APP
const maskLayerShow = ref(false) // const maskLayerShow = ref(false) //
//
const isLoading = ref(true)
const langStore = useLangStore() const langStore = useLangStore()
// //
const currentLangType = computed(() => { const currentLangType = computed(() => {
@ -741,13 +749,15 @@ const getRewardsAndGifts = async () => {
} }
// //
const initData = () => { const initData = async () => {
getListAndMy() // await Promise.all([
getRewardsAndGifts() // getListAndMy(), //
getRewardsAndGifts(), //
])
} }
// //
const preloadCriticalImages = () => { const preloadCriticalImages = async () => {
const criticalImages = [ const criticalImages = [
imageUrl('bg'), imageUrl('bg'),
imageUrl('bg2'), imageUrl('bg2'),
@ -803,9 +813,22 @@ const preloadCriticalImages = () => {
] ]
if (currentLangType.value == 'en') { if (currentLangType.value == 'en') {
preloadImages(criticalImages) await preloadImages(criticalImages)
} else if (currentLangType.value == 'ar') { } else if (currentLangType.value == 'ar') {
preloadImages(criticalImages_ar) await preloadImages(criticalImages_ar)
}
}
//
const completePreloading = async () => {
try {
//
await Promise.all([initData(), preloadCriticalImages()])
} catch (error) {
console.error('预加载过程中发生错误:', error)
} finally {
//
isLoading.value = false
} }
} }
@ -813,8 +836,7 @@ const preloadCriticalImages = () => {
const connectToAppHandler = async () => { const connectToAppHandler = async () => {
await connectToApp(() => { await connectToApp(() => {
// //
initData() // completePreloading() //
preloadCriticalImages() //
}) })
} }
@ -850,17 +872,6 @@ onUnmounted(() => {
z-index: 1; z-index: 1;
} }
.ranking-bg {
background-color: #400000;
background-image: var(--ranking-bg-url);
background-size: 100% auto;
background-repeat: no-repeat;
position: absolute;
inset: 10vw 2% 1vw;
z-index: 1;
}
.timeText { .timeText {
color: #fff; color: #fff;
font-weight: 590; font-weight: 590;
@ -903,6 +914,40 @@ onUnmounted(() => {
margin-top: 10vw; margin-top: 10vw;
} }
/* 添加加载动画样式 */
.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;
}
.toggle-image {
transition: opacity 0.3s ease-in-out;
}
@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;