feat(充值奖励): 使用网络图片,并对接图片的缓存,预加载等功能

This commit is contained in:
hzj 2025-12-02 17:48:25 +08:00
parent 2933224f18
commit e47f2b9299

View File

@ -1,12 +1,13 @@
<!-- src/views/Activities/Reward/RechargeReward.vue -->
<template> <template>
<div> <div>
<!-- Rewards0.png 使用相对定位容器 --> <!-- Rewards0.png 使用相对定位容器 -->
<div style="position: relative"> <div style="position: relative">
<img :src="images.Rewards0" alt="" style="width: 100%; display: block" /> <img v-smart-img :src="imageUrl('Rewards0')" alt="" style="width: 100%; display: block" />
<!-- 帮助按钮 --> <!-- 帮助按钮 -->
<img <img
v-smart-img v-smart-img
:src="images.help" :src="imageUrl('help')"
alt="" alt=""
style=" style="
position: absolute; position: absolute;
@ -35,7 +36,8 @@
<div style="display: grid; grid-template-columns: 4fr 6fr"> <div style="display: grid; grid-template-columns: 4fr 6fr">
<div style="width: 100%; aspect-ratio: 1/1; position: relative"> <div style="width: 100%; aspect-ratio: 1/1; position: relative">
<img <img
:src="images.frame" v-smart-img
:src="imageUrl('frame')"
alt="" alt=""
style="width: 100%; display: block; aspect-ratio: 1/1; position: relative; z-index: 1" style="width: 100%; display: block; aspect-ratio: 1/1; position: relative; z-index: 1"
/> />
@ -50,6 +52,7 @@
" "
> >
<img <img
v-smart-img
:src="userInfo.userAvatar || ''" :src="userInfo.userAvatar || ''"
alt="" alt=""
style=" style="
@ -109,41 +112,34 @@
</div> </div>
<!-- 其他图片直接引入 --> <!-- 其他图片直接引入 -->
<img v-smart-img :src="images.Rewards1" alt="" style="width: 100%; display: block" /> <img v-smart-img :src="imageUrl('Rewards1')" alt="" style="width: 100%; display: block" />
<img v-smart-img :src="images.Rewards2" alt="" style="width: 100%; display: block" /> <img v-smart-img :src="imageUrl('Rewards2')" alt="" style="width: 100%; display: block" />
<img v-smart-img :src="images.Rewards3" alt="" style="width: 100%; display: block" /> <img v-smart-img :src="imageUrl('Rewards3')" alt="" style="width: 100%; display: block" />
<img v-smart-img :src="images.Rewards4" alt="" style="width: 100%; display: block" /> <img v-smart-img :src="imageUrl('Rewards4')" alt="" style="width: 100%; display: block" />
<img v-smart-img :src="images.Rewards5" alt="" style="width: 100%; display: block" /> <img v-smart-img :src="imageUrl('Rewards5')" alt="" style="width: 100%; display: block" />
<!-- 弹窗遮罩层 --> <!-- 弹窗遮罩层 -->
<maskLayer :maskLayerShow="maskLayerShow" @click="maskLayerShow = false"> <maskLayer :maskLayerShow="maskLayerShow" @click="maskLayerShow = false">
<!-- help弹窗 --> <!-- help弹窗 -->
<div style="margin: 20% 0" @click.stop> <div style="margin: 20% 0" @click.stop>
<img v-smart-img :src="images.helpInfo" alt="" style="display: block; width: 100%" /> <img v-smart-img :src="imageUrl('helpInfo')" alt="" style="display: block; width: 100%" />
</div> </div>
</maskLayer> </maskLayer>
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, watch, onMounted } from 'vue' import { ref, onMounted } from 'vue'
import { connectToApp } from '@/utils/appConnector.js' import { connectToApp } from '@/utils/appConnector.js'
import { getPngUrl } from '@/config/imagePaths.js'
import { preloadImages } from '@/utils/imagePreloader.js'
import { getMemberProfile, getTotalRecharge } from '@/api/wallet' import { getMemberProfile, getTotalRecharge } from '@/api/wallet'
import maskLayer from '@/components/MaskLayer.vue' import maskLayer from '@/components/MaskLayer.vue'
// 使Lottery.vue // OSSURL
const imageModules = import.meta.glob('@/assets/images/RechargeReward/*.{jpg,png,svg}', { const imageUrl = (filename) => getPngUrl('Activities/RechargeReward/', filename)
eager: true,
})
//
const images = Object.fromEntries(
Object.entries(imageModules).map(([path, module]) => {
const fileName = path.split('/').pop().split('.')[0]
return [fileName, module.default]
})
)
const maskLayerShow = ref(false) // const maskLayerShow = ref(false) //
@ -181,10 +177,28 @@ const defaultAvatarUrl = (e) => {
e.target.src = new URL('/src/assets/icon/defaultAvatar.png', import.meta.url).href e.target.src = new URL('/src/assets/icon/defaultAvatar.png', import.meta.url).href
} }
//
const preloadCriticalImages = () => {
const criticalImages = [
imageUrl('Rewards0'),
imageUrl('Rewards1'),
imageUrl('Rewards2'),
imageUrl('Rewards3'),
imageUrl('Rewards4'),
imageUrl('Rewards5'),
imageUrl('help'),
imageUrl('helpInfo'),
imageUrl('frame'),
]
preloadImages(criticalImages, { useSmartCache: true })
}
// 使APP // 使APP
const connectToAppHandler = async () => { const connectToAppHandler = async () => {
await connectToApp(() => { await connectToApp(() => {
getTotalRechargeInfo() // getTotalRechargeInfo() //
preloadCriticalImages() //
}) })
} }