hookehuyr

fix(海报检查): 修复海报背景图变化时缓存处理问题

修复当海报背景图发生变化时未正确清除缓存导致海报未重新生成的问题。添加了更详细的日志输出以便调试,并确保在背景图变化或上传新背景图时强制重新生成海报。
......@@ -160,6 +160,7 @@ const posterConfigHashes = ref({}) // 每个海报的配置哈希值,用于检
// 页面参数
const pageParams = ref({
from: '',
id: '',
})
......@@ -454,9 +455,20 @@ onMounted(() => {
watch(backgroundImages, (newVal, oldVal) => {
// 只有当前海报的背景图发生变化时才重新生成
const currentIndex = currentPosterIndex.value
if (newVal[currentIndex] !== oldVal?.[currentIndex]) {
const newBgImage = newVal[currentIndex]
const oldBgImage = oldVal?.[currentIndex]
if (newBgImage !== oldBgImage) {
console.log('背景图发生变化:', { currentIndex, newBgImage, oldBgImage })
// 标记当前海报需要重新生成
posterGeneratedFlags.value[currentIndex] = false
delete posterConfigHashes.value[currentIndex]
// 清除当前海报路径
posterPath.value = ''
// 重新生成海报
generateCurrentPoster()
}
}, { deep: true })
......@@ -498,17 +510,32 @@ const generateCurrentPosterIfNeeded = () => {
const currentHash = generateConfigHash()
const isGenerated = posterGeneratedFlags.value[currentIndex]
const lastHash = posterConfigHashes.value[currentIndex]
const hasCustomBackground = !!backgroundImages.value[currentIndex]
console.log('检查是否需要生成海报:', {
currentIndex,
isGenerated,
hasCustomBackground,
currentHash,
lastHash,
hashChanged: lastHash !== currentHash
})
// 如果海报未生成过,或者配置发生了变化,则需要重新生成
if (!isGenerated || lastHash !== currentHash) {
console.log('需要重新生成海报')
posterConfigHashes.value[currentIndex] = currentHash
generateCurrentPoster()
} else {
// 海报已存在且配置未变化,直接使用缓存的海报
const cachedPoster = posterList.value[currentIndex]
if (cachedPoster && cachedPoster.path) {
console.log('使用缓存的海报:', cachedPoster.path)
posterPath.value = cachedPoster.path
posterGenerateFailed.value = false
} else {
console.log('缓存的海报路径不存在,重新生成')
generateCurrentPoster()
}
}
}
......@@ -597,8 +624,21 @@ const uploadBackgroundImage = (filePath) => {
Taro.hideLoading()
const data = JSON.parse(uploadRes.data)
if (data.code === 0 && data.data) {
const currentIndex = currentPosterIndex.value
// 为当前海报设置背景图
backgroundImages.value[currentPosterIndex.value] = data.data.src
backgroundImages.value[currentIndex] = data.data.src
// 强制标记当前海报需要重新生成
posterGeneratedFlags.value[currentIndex] = false
delete posterConfigHashes.value[currentIndex]
// 清除当前海报路径,强制重新生成
posterPath.value = ''
// 立即重新生成海报
generateCurrentPoster()
Taro.showToast({ title: '上传成功', icon: 'success' })
} else {
Taro.showToast({ title: data.msg || '上传失败', icon: 'none' })
......@@ -625,7 +665,17 @@ const onPosterSuccess = (result) => {
}
posterGeneratedFlags.value[currentIndex] = true
// 保存当前配置的哈希值
posterConfigHashes.value[currentIndex] = generateConfigHash()
shouldGeneratePoster.value = false
console.log('海报生成成功:', {
currentIndex,
posterPath: result.tempFilePath,
hasCustomBackground: !!backgroundImages.value[currentIndex]
})
Taro.showToast({ title: '海报生成成功', icon: 'success' })
}
......