fix(海报检查): 修复海报背景图变化时缓存处理问题
修复当海报背景图发生变化时未正确清除缓存导致海报未重新生成的问题。添加了更详细的日志输出以便调试,并确保在背景图变化或上传新背景图时强制重新生成海报。
Showing
1 changed file
with
52 additions
and
2 deletions
| ... | @@ -160,6 +160,7 @@ const posterConfigHashes = ref({}) // 每个海报的配置哈希值,用于检 | ... | @@ -160,6 +160,7 @@ const posterConfigHashes = ref({}) // 每个海报的配置哈希值,用于检 |
| 160 | 160 | ||
| 161 | // 页面参数 | 161 | // 页面参数 |
| 162 | const pageParams = ref({ | 162 | const pageParams = ref({ |
| 163 | + from: '', | ||
| 163 | id: '', | 164 | id: '', |
| 164 | }) | 165 | }) |
| 165 | 166 | ||
| ... | @@ -454,9 +455,20 @@ onMounted(() => { | ... | @@ -454,9 +455,20 @@ onMounted(() => { |
| 454 | watch(backgroundImages, (newVal, oldVal) => { | 455 | watch(backgroundImages, (newVal, oldVal) => { |
| 455 | // 只有当前海报的背景图发生变化时才重新生成 | 456 | // 只有当前海报的背景图发生变化时才重新生成 |
| 456 | const currentIndex = currentPosterIndex.value | 457 | const currentIndex = currentPosterIndex.value |
| 457 | - if (newVal[currentIndex] !== oldVal?.[currentIndex]) { | 458 | + const newBgImage = newVal[currentIndex] |
| 459 | + const oldBgImage = oldVal?.[currentIndex] | ||
| 460 | + | ||
| 461 | + if (newBgImage !== oldBgImage) { | ||
| 462 | + console.log('背景图发生变化:', { currentIndex, newBgImage, oldBgImage }) | ||
| 463 | + | ||
| 458 | // 标记当前海报需要重新生成 | 464 | // 标记当前海报需要重新生成 |
| 459 | posterGeneratedFlags.value[currentIndex] = false | 465 | posterGeneratedFlags.value[currentIndex] = false |
| 466 | + delete posterConfigHashes.value[currentIndex] | ||
| 467 | + | ||
| 468 | + // 清除当前海报路径 | ||
| 469 | + posterPath.value = '' | ||
| 470 | + | ||
| 471 | + // 重新生成海报 | ||
| 460 | generateCurrentPoster() | 472 | generateCurrentPoster() |
| 461 | } | 473 | } |
| 462 | }, { deep: true }) | 474 | }, { deep: true }) |
| ... | @@ -498,17 +510,32 @@ const generateCurrentPosterIfNeeded = () => { | ... | @@ -498,17 +510,32 @@ const generateCurrentPosterIfNeeded = () => { |
| 498 | const currentHash = generateConfigHash() | 510 | const currentHash = generateConfigHash() |
| 499 | const isGenerated = posterGeneratedFlags.value[currentIndex] | 511 | const isGenerated = posterGeneratedFlags.value[currentIndex] |
| 500 | const lastHash = posterConfigHashes.value[currentIndex] | 512 | const lastHash = posterConfigHashes.value[currentIndex] |
| 513 | + const hasCustomBackground = !!backgroundImages.value[currentIndex] | ||
| 514 | + | ||
| 515 | + console.log('检查是否需要生成海报:', { | ||
| 516 | + currentIndex, | ||
| 517 | + isGenerated, | ||
| 518 | + hasCustomBackground, | ||
| 519 | + currentHash, | ||
| 520 | + lastHash, | ||
| 521 | + hashChanged: lastHash !== currentHash | ||
| 522 | + }) | ||
| 501 | 523 | ||
| 502 | // 如果海报未生成过,或者配置发生了变化,则需要重新生成 | 524 | // 如果海报未生成过,或者配置发生了变化,则需要重新生成 |
| 503 | if (!isGenerated || lastHash !== currentHash) { | 525 | if (!isGenerated || lastHash !== currentHash) { |
| 526 | + console.log('需要重新生成海报') | ||
| 504 | posterConfigHashes.value[currentIndex] = currentHash | 527 | posterConfigHashes.value[currentIndex] = currentHash |
| 505 | generateCurrentPoster() | 528 | generateCurrentPoster() |
| 506 | } else { | 529 | } else { |
| 507 | // 海报已存在且配置未变化,直接使用缓存的海报 | 530 | // 海报已存在且配置未变化,直接使用缓存的海报 |
| 508 | const cachedPoster = posterList.value[currentIndex] | 531 | const cachedPoster = posterList.value[currentIndex] |
| 509 | if (cachedPoster && cachedPoster.path) { | 532 | if (cachedPoster && cachedPoster.path) { |
| 533 | + console.log('使用缓存的海报:', cachedPoster.path) | ||
| 510 | posterPath.value = cachedPoster.path | 534 | posterPath.value = cachedPoster.path |
| 511 | posterGenerateFailed.value = false | 535 | posterGenerateFailed.value = false |
| 536 | + } else { | ||
| 537 | + console.log('缓存的海报路径不存在,重新生成') | ||
| 538 | + generateCurrentPoster() | ||
| 512 | } | 539 | } |
| 513 | } | 540 | } |
| 514 | } | 541 | } |
| ... | @@ -597,8 +624,21 @@ const uploadBackgroundImage = (filePath) => { | ... | @@ -597,8 +624,21 @@ const uploadBackgroundImage = (filePath) => { |
| 597 | Taro.hideLoading() | 624 | Taro.hideLoading() |
| 598 | const data = JSON.parse(uploadRes.data) | 625 | const data = JSON.parse(uploadRes.data) |
| 599 | if (data.code === 0 && data.data) { | 626 | if (data.code === 0 && data.data) { |
| 627 | + const currentIndex = currentPosterIndex.value | ||
| 628 | + | ||
| 600 | // 为当前海报设置背景图 | 629 | // 为当前海报设置背景图 |
| 601 | - backgroundImages.value[currentPosterIndex.value] = data.data.src | 630 | + backgroundImages.value[currentIndex] = data.data.src |
| 631 | + | ||
| 632 | + // 强制标记当前海报需要重新生成 | ||
| 633 | + posterGeneratedFlags.value[currentIndex] = false | ||
| 634 | + delete posterConfigHashes.value[currentIndex] | ||
| 635 | + | ||
| 636 | + // 清除当前海报路径,强制重新生成 | ||
| 637 | + posterPath.value = '' | ||
| 638 | + | ||
| 639 | + // 立即重新生成海报 | ||
| 640 | + generateCurrentPoster() | ||
| 641 | + | ||
| 602 | Taro.showToast({ title: '上传成功', icon: 'success' }) | 642 | Taro.showToast({ title: '上传成功', icon: 'success' }) |
| 603 | } else { | 643 | } else { |
| 604 | Taro.showToast({ title: data.msg || '上传失败', icon: 'none' }) | 644 | Taro.showToast({ title: data.msg || '上传失败', icon: 'none' }) |
| ... | @@ -625,7 +665,17 @@ const onPosterSuccess = (result) => { | ... | @@ -625,7 +665,17 @@ const onPosterSuccess = (result) => { |
| 625 | } | 665 | } |
| 626 | posterGeneratedFlags.value[currentIndex] = true | 666 | posterGeneratedFlags.value[currentIndex] = true |
| 627 | 667 | ||
| 668 | + // 保存当前配置的哈希值 | ||
| 669 | + posterConfigHashes.value[currentIndex] = generateConfigHash() | ||
| 670 | + | ||
| 628 | shouldGeneratePoster.value = false | 671 | shouldGeneratePoster.value = false |
| 672 | + | ||
| 673 | + console.log('海报生成成功:', { | ||
| 674 | + currentIndex, | ||
| 675 | + posterPath: result.tempFilePath, | ||
| 676 | + hasCustomBackground: !!backgroundImages.value[currentIndex] | ||
| 677 | + }) | ||
| 678 | + | ||
| 629 | Taro.showToast({ title: '海报生成成功', icon: 'success' }) | 679 | Taro.showToast({ title: '海报生成成功', icon: 'success' }) |
| 630 | } | 680 | } |
| 631 | 681 | ... | ... |
-
Please register or login to post a comment