feat(海报检查): 添加海报生成失败状态处理及按钮逻辑
增加海报生成失败状态变量及相应UI反馈 合并保存和重新生成操作为统一处理函数 根据状态显示不同按钮文本和样式
Showing
1 changed file
with
22 additions
and
11 deletions
| ... | @@ -79,11 +79,11 @@ | ... | @@ -79,11 +79,11 @@ |
| 79 | </view> | 79 | </view> |
| 80 | <view | 80 | <view |
| 81 | class="flex-1 text-white py-3 px-6 rounded-lg font-medium shadow-lg active:scale-95 transition-transform duration-150 flex items-center justify-center gap-2" | 81 | class="flex-1 text-white py-3 px-6 rounded-lg font-medium shadow-lg active:scale-95 transition-transform duration-150 flex items-center justify-center gap-2" |
| 82 | - :class="posterPath ? 'bg-gradient-to-r from-green-400 to-green-500' : 'bg-gray-400'" | 82 | + :class="posterPath ? 'bg-gradient-to-r from-green-400 to-green-500' : (posterGenerateFailed ? 'bg-gradient-to-r from-orange-400 to-orange-500' : 'bg-gray-400')" |
| 83 | - @click="savePoster" | 83 | + @click="handlePosterAction" |
| 84 | - :disabled="!posterPath" | 84 | + :disabled="!posterPath && !posterGenerateFailed" |
| 85 | > | 85 | > |
| 86 | - <text>保存海报</text> | 86 | + <text>{{ posterPath ? '保存海报' : (posterGenerateFailed ? '重新生成' : '生成中...') }}</text> |
| 87 | </view> | 87 | </view> |
| 88 | </view> | 88 | </view> |
| 89 | </view> | 89 | </view> |
| ... | @@ -138,6 +138,7 @@ const posterPath = ref('') // 生成的海报路径 | ... | @@ -138,6 +138,7 @@ const posterPath = ref('') // 生成的海报路径 |
| 138 | const backgroundImage = ref('') // 用户上传的背景图 | 138 | const backgroundImage = ref('') // 用户上传的背景图 |
| 139 | const shouldGeneratePoster = ref(false) // 是否应该生成海报 | 139 | const shouldGeneratePoster = ref(false) // 是否应该生成海报 |
| 140 | const currentPosterIndex = ref(0) // 当前显示的海报索引 | 140 | const currentPosterIndex = ref(0) // 当前显示的海报索引 |
| 141 | +const posterGenerateFailed = ref(false) // 海报生成是否失败 | ||
| 141 | 142 | ||
| 142 | // 页面参数 | 143 | // 页面参数 |
| 143 | const pageParams = ref({ | 144 | const pageParams = ref({ |
| ... | @@ -373,17 +374,11 @@ watch(currentPosterIndex, () => { | ... | @@ -373,17 +374,11 @@ watch(currentPosterIndex, () => { |
| 373 | }) | 374 | }) |
| 374 | 375 | ||
| 375 | /** | 376 | /** |
| 376 | - * 返回上一页 | ||
| 377 | - */ | ||
| 378 | -const goBack = () => { | ||
| 379 | - Taro.navigateBack() | ||
| 380 | -} | ||
| 381 | - | ||
| 382 | -/** | ||
| 383 | * 生成当前海报 | 377 | * 生成当前海报 |
| 384 | */ | 378 | */ |
| 385 | const generateCurrentPoster = () => { | 379 | const generateCurrentPoster = () => { |
| 386 | posterPath.value = '' | 380 | posterPath.value = '' |
| 381 | + posterGenerateFailed.value = false | ||
| 387 | shouldGeneratePoster.value = false | 382 | shouldGeneratePoster.value = false |
| 388 | 383 | ||
| 389 | // 延迟触发生成,确保配置更新 | 384 | // 延迟触发生成,确保配置更新 |
| ... | @@ -493,6 +488,7 @@ const uploadBackgroundImage = (filePath) => { | ... | @@ -493,6 +488,7 @@ const uploadBackgroundImage = (filePath) => { |
| 493 | */ | 488 | */ |
| 494 | const onPosterSuccess = (result) => { | 489 | const onPosterSuccess = (result) => { |
| 495 | posterPath.value = result.tempFilePath | 490 | posterPath.value = result.tempFilePath |
| 491 | + posterGenerateFailed.value = false | ||
| 496 | // 更新当前海报的路径 | 492 | // 更新当前海报的路径 |
| 497 | if (posterList.value[currentPosterIndex.value]) { | 493 | if (posterList.value[currentPosterIndex.value]) { |
| 498 | posterList.value[currentPosterIndex.value].path = result.tempFilePath | 494 | posterList.value[currentPosterIndex.value].path = result.tempFilePath |
| ... | @@ -506,6 +502,8 @@ const onPosterSuccess = (result) => { | ... | @@ -506,6 +502,8 @@ const onPosterSuccess = (result) => { |
| 506 | */ | 502 | */ |
| 507 | const onPosterFail = (error) => { | 503 | const onPosterFail = (error) => { |
| 508 | shouldGeneratePoster.value = false | 504 | shouldGeneratePoster.value = false |
| 505 | + posterGenerateFailed.value = true | ||
| 506 | + posterPath.value = '' | ||
| 509 | Taro.showToast({ title: '海报生成失败', icon: 'none' }) | 507 | Taro.showToast({ title: '海报生成失败', icon: 'none' }) |
| 510 | console.error('海报生成失败:', error) | 508 | console.error('海报生成失败:', error) |
| 511 | } | 509 | } |
| ... | @@ -530,6 +528,19 @@ const closePreview = () => { | ... | @@ -530,6 +528,19 @@ const closePreview = () => { |
| 530 | } | 528 | } |
| 531 | 529 | ||
| 532 | /** | 530 | /** |
| 531 | + * 处理海报按钮点击事件 | ||
| 532 | + */ | ||
| 533 | +const handlePosterAction = () => { | ||
| 534 | + if (posterPath.value) { | ||
| 535 | + // 如果海报已生成,执行保存操作 | ||
| 536 | + savePoster() | ||
| 537 | + } else if (posterGenerateFailed.value) { | ||
| 538 | + // 如果生成失败,重新生成海报 | ||
| 539 | + generateCurrentPoster() | ||
| 540 | + } | ||
| 541 | +} | ||
| 542 | + | ||
| 543 | +/** | ||
| 533 | * 保存海报到相册 | 544 | * 保存海报到相册 |
| 534 | */ | 545 | */ |
| 535 | const savePoster = () => { | 546 | const savePoster = () => { | ... | ... |
-
Please register or login to post a comment