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

View File

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

View File

@ -36,7 +36,7 @@ export function useRecords() {
// 用户信息 // 用户信息
user_id: it.user_id, user_id: it.user_id,
user_name: it.user_name || '匿名用户', user_name: it.user_name || '匿名用户',
avatar: it.avatar, avatar: cleanAvatar(it.avatar), // 清理 avatar 数据
// 时间信息 // 时间信息
created_at: it.created_at, created_at: it.created_at,
@ -60,6 +60,42 @@ export function useRecords() {
return alpha + '赏' 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() { function clearRecords() {
winRecords.value = [] winRecords.value = []
} }