fix:修复了几个显示不完整的问题,移除了原有的缓存逻辑,避免无限增长缓存的问题。

This commit is contained in:
tsui110 2025-12-31 12:37:00 +08:00
parent 054b849374
commit e24f05f6ac
3 changed files with 106 additions and 31 deletions

View File

@ -29,9 +29,17 @@ onMounted(() => {
const today = new Date()
const dateStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`
//
const splashKey = `splash_count_${dateStr}`
const todayCount = uni.getStorageSync(splashKey) || 0
// JSON
const splashKey = 'splash_count'
let splashData = uni.getStorageSync(splashKey)
//
if (!splashData || typeof splashData !== 'object') {
splashData = {}
}
//
const todayCount = splashData[dateStr] || 0
// 10
if (todayCount < 10) {
@ -39,7 +47,8 @@ onMounted(() => {
visible.value = true
//
uni.setStorageSync(splashKey, todayCount + 1)
splashData[dateStr] = todayCount + 1
uni.setStorageSync(splashKey, splashData)
// 5
setTimeout(() => {

View File

@ -459,6 +459,37 @@ function cleanUrl(u) {
return s.replace(/[`'\"]/g, '').trim()
}
function cleanAvatar(avatar) {
if (!avatar) return ''
// base64
const avatarStr = String(avatar).trim()
// data:image
if (avatarStr.startsWith('data:image/')) {
return avatarStr
}
// http(s) URL
if (avatarStr.startsWith('http://') || avatarStr.startsWith('https://')) {
return avatarStr
}
//
if (avatarStr.startsWith('/')) {
return avatarStr
}
// base64
// data:image png
if (avatarStr.match(/^[A-Za-z0-9+/=]+$/)) {
// base64
return `data:image/png;base64,${avatarStr}`
}
return avatarStr
}
const MATCHING_GAME_CACHE_KEY = 'matching_game_cache_v1'
function getMatchingGameCache() {
@ -672,24 +703,19 @@ async function fetchWinRecords(actId, issId) {
try {
const res = await getIssueDrawLogs(actId, issId)
const list = (res && res.list) || (Array.isArray(res) ? res : [])
//
const aggregate = {}
list.forEach(it => {
const key = it.reward_id || it.id
if (!aggregate[key]) {
aggregate[key] = {
id: key,
title: it.reward_name || it.title || it.name || '-',
image: it.reward_image || it.image || '',
count: 0
}
}
aggregate[key].count += 1
})
const total = list.length || 1
winRecords.value = Object.values(aggregate).map(it => ({
...it,
percent: ((it.count / total) * 100).toFixed(1)
// 使
winRecords.value = list.map(it => ({
id: it.id,
title: it.reward_name || it.title || it.name || '-',
image: it.reward_image || it.image || '',
count: 1,
//
user_id: it.user_id,
user_name: it.user_name || '匿名用户',
avatar: cleanAvatar(it.avatar),
//
created_at: it.created_at
}))
} catch (e) {
console.error('fetchWinRecords error', e)
@ -1063,9 +1089,9 @@ async function finishAndReport() {
console.log('[对对碰] currentIssueRewards:', currentIssueRewards.value?.length, 'items')
console.log('[对对碰] rewardsMap keys:', Object.keys(rewardsMap.value || {}))
// - { reward: { reward_id, name, level } }
// - { reward: { reward_id, name, level, product_image } }
let wonItems = []
// reward
if (checkRes?.reward && checkRes.reward.reward_id) {
const reward = checkRes.reward
@ -1073,14 +1099,16 @@ async function finishAndReport() {
// rewardsMap
const allRewards = rewardsMap.value[issueId] || currentIssueRewards.value || []
console.log('[对对碰] 本地奖励数据:', allRewards.length, 'items')
const foundReward = allRewards.find(r =>
String(r.id) === String(reward.reward_id) ||
const foundReward = allRewards.find(r =>
String(r.id) === String(reward.reward_id) ||
String(r.reward_id) === String(reward.reward_id)
)
console.log('[对对碰] 匹配到的奖励:', foundReward)
// 使 product_image使 logo
const rewardImage = cleanUrl(reward.product_image || foundReward?.image || foundReward?.pic || foundReward?.img || foundReward?.product_image || '')
wonItems = [{
title: reward.name || foundReward?.name || foundReward?.title || '神秘奖励',
image: foundReward?.image || foundReward?.pic || foundReward?.img || foundReward?.product_image || '',
image: rewardImage || '/static/logo.png',
reward_id: reward.reward_id
}]
}
@ -1106,13 +1134,15 @@ async function finishAndReport() {
// title使
if (item.title) return item
//
const found = allRewards.find(r =>
String(r.id) === String(item.reward_id) ||
const found = allRewards.find(r =>
String(r.id) === String(item.reward_id) ||
String(r.reward_id) === String(item.reward_id)
)
// 使 product_image使 logo
const itemImage = cleanUrl(item.product_image || item.image || item.img || found?.image || found?.pic || found?.product_image || '')
return {
title: item.title || item.name || found?.name || found?.title || '神秘奖励',
image: cleanUrl(item.image || item.img || found?.image || found?.pic || found?.product_image || ''),
image: itemImage || '/static/logo.png',
reward_id: item.reward_id || item.id
}
})

View File

@ -36,7 +36,7 @@ export function useRecords() {
// 用户信息
user_id: it.user_id,
user_name: it.user_name || '匿名用户',
avatar: it.avatar,
avatar: cleanAvatar(it.avatar), // 清理 avatar 数据
// 时间信息
created_at: it.created_at,
@ -60,6 +60,42 @@ export function useRecords() {
return alpha + '赏'
}
/**
* 清理和验证 avatar 数据
* @param {string} avatar - 原始 avatar 数据可能是 base64 URL
* @returns {string} - 清理后的 avatar 数据
*/
function cleanAvatar(avatar) {
if (!avatar) return ''
// 如果是 base64 格式,确保格式正确
const avatarStr = String(avatar).trim()
// 检查是否已经是 data:image 格式
if (avatarStr.startsWith('data:image/')) {
return avatarStr
}
// 如果是 http(s) URL直接返回
if (avatarStr.startsWith('http://') || avatarStr.startsWith('https://')) {
return avatarStr
}
// 如果是相对路径,直接返回
if (avatarStr.startsWith('/')) {
return avatarStr
}
// 其他情况,可能是不完整的 base64尝试修复
// 如果不包含 data:image 前缀,添加默认的 png 前缀
if (avatarStr.match(/^[A-Za-z0-9+/=]+$/)) {
// 看起来像 base64 编码
return `data:image/png;base64,${avatarStr}`
}
return avatarStr
}
function clearRecords() {
winRecords.value = []
}