feat(总排行榜): 使用网络图片,并对接图片的缓存,预加载等功能

This commit is contained in:
hzj 2025-12-02 18:44:53 +08:00
parent f95db045c9
commit 63ec2371b7
2 changed files with 44 additions and 34 deletions

View File

@ -1,22 +1,26 @@
<!-- src/views/Ranking/Overall/Ranking.vue -->
<template>
<div class="fullPage" :style="{ backgroundColor }">
<!-- 背景图 -->
<div style="position: absolute; top: 0; left: 0; width: 100vw; z-index: 3">
<img
v-show="rankingType == 'Wealth'"
:src="images.bgWealth"
v-smart-img
:src="imageUrl('bgWealth')"
alt=""
style="display: block; width: 100%; object-fit: cover"
/>
<img
v-show="rankingType == 'Charm'"
:src="images.bgCharm"
v-smart-img
:src="imageUrl('bgCharm')"
alt=""
style="display: block; width: 100%; object-fit: cover"
/>
<img
v-show="rankingType == 'Room'"
:src="images.bgRoom"
v-smart-img
:src="imageUrl('bgRoom')"
alt=""
style="display: block; width: 100%; object-fit: cover"
/>
@ -332,6 +336,7 @@ import { useRoute } from 'vue-router'
import { isInApp, closePage, viewUserInfo, gotoRoom } from '@/utils/appBridge.js'
import { connectToApp } from '@/utils/appConnector.js'
import { preloadImages } from '@/utils/imagePreloader'
import { getPngUrl } from '@/config/imagePaths.js'
import { getWealthRanking, getCharmRanking, getRoomRanking, getMyRanking } from '@/api/ranking'
@ -339,19 +344,8 @@ import TopUser from './components/topUser.vue'
const route = useRoute()
//vite
const imageModules = import.meta.glob('@/assets/images/Ranking/*.{png,jpg,svg}', { eager: true })
//
const images = Object.fromEntries(
Object.entries(imageModules).map(([path, module]) => {
const fileName = path.split('/').pop().split('.')[0]
return [fileName, module.default]
})
)
// const preloadAllRankingImages = () => {
// preloadImages(images, { useSmartCache: true })
// }
// OSSURL
const imageUrl = (filename) => getPngUrl('Ranking/Overall/', filename)
const isInAppEnvironment = ref(false) // APP
const rankingType = ref(route.query.first || 'Wealth') //
@ -365,6 +359,24 @@ const totalRanking = ref({})
const showRanking = ref([])
const myRanking = ref({}) //
//
const preloadCriticalImages = () => {
const criticalImages = [
imageUrl('bgWealth'),
imageUrl('bgCharm'),
imageUrl('bgRoom'),
imageUrl('top1-wealth'),
imageUrl('top1-charm'),
imageUrl('top1-room'),
imageUrl('top2'),
imageUrl('top3'),
imageUrl('top2-room'),
imageUrl('top3-room'),
]
preloadImages(criticalImages, { useSmartCache: true })
}
//
const updateTimeRanking = () => {
console.log('updateTimeRanking()//筛选展示榜单')
@ -470,9 +482,9 @@ const stickyHeader = ref(null)
watchEffect(() => {
if (rankingType.value == 'Wealth') {
backgroundColor.value = '#230F0A'
topBorderBg.value = images['top1-wealth']
top2BorderBg.value = images['top2']
top3BorderBg.value = images['top3']
topBorderBg.value = imageUrl('top1-wealth')
top2BorderBg.value = imageUrl('top2')
top3BorderBg.value = imageUrl('top3')
border.value = '1px solid rgba(221, 114, 0, 0.39)'
background.value = 'rgba(252, 194, 147, 0.20)'
rankItemBackground.value =
@ -483,9 +495,9 @@ watchEffect(() => {
}
if (rankingType.value == 'Charm') {
backgroundColor.value = '#112C1E'
topBorderBg.value = images['top1-charm']
top2BorderBg.value = images['top2']
top3BorderBg.value = images['top3']
topBorderBg.value = imageUrl('top1-charm')
top2BorderBg.value = imageUrl('top2')
top3BorderBg.value = imageUrl('top3')
border.value = '1px solid rgba(0, 221, 74, 0.39)'
background.value = 'rgba(147, 252, 166, 0.20)'
rankItemBackground.value =
@ -496,9 +508,9 @@ watchEffect(() => {
}
if (rankingType.value == 'Room') {
backgroundColor.value = '#211031'
topBorderBg.value = images['top1-room']
top2BorderBg.value = images['top2-room']
top3BorderBg.value = images['top3-room']
topBorderBg.value = imageUrl('top1-room')
top2BorderBg.value = imageUrl('top2-room')
top3BorderBg.value = imageUrl('top3-room')
border.value = '1px solid rgba(155, 0, 221, 0.39)'
background.value = 'rgba(219, 147, 252, 0.20)'
rankItemBackground.value =
@ -583,6 +595,7 @@ const connectToAppHandler = async () => {
await connectToApp(() => {
//
initData() //
preloadCriticalImages() //
})
}
@ -591,8 +604,6 @@ onMounted(() => {
isInAppEnvironment.value = isInApp()
observer.observe(sentinel.value)
// preloadAllRankingImages()
})
</script>

View File

@ -1,3 +1,4 @@
<!-- src/views/Ranking/Overall/components/topUser.vue -->
<template>
<div style="width: 100%">
<div style="position: relative">
@ -65,13 +66,7 @@
</div>
</div>
<div style="width: 60%; position: relative">
<img
v-smart-img
src="/src/assets/images/Ranking/coinNumBg.png"
alt=""
width="100%"
style="display: block"
/>
<img v-smart-img :src="coinNumBgUrl" alt="" width="100%" style="display: block" />
<div
style="position: absolute; inset: 0; display: flex; align-items: center; padding: 3% 5%"
>
@ -104,6 +99,10 @@
<script setup>
import { computed, watch } from 'vue'
import { getPngUrl } from '@/config/imagePaths.js'
// OSSURL
const coinNumBgUrl = getPngUrl('Ranking/Overall/', 'coinNumBg')
const props = defineProps({
Type: {