hookehuyr

feat(海报检查): 添加海报生成失败状态处理及按钮逻辑

增加海报生成失败状态变量及相应UI反馈
合并保存和重新生成操作为统一处理函数
根据状态显示不同按钮文本和样式
......@@ -79,11 +79,11 @@
</view>
<view
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"
:class="posterPath ? 'bg-gradient-to-r from-green-400 to-green-500' : 'bg-gray-400'"
@click="savePoster"
:disabled="!posterPath"
: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')"
@click="handlePosterAction"
:disabled="!posterPath && !posterGenerateFailed"
>
<text>保存海报</text>
<text>{{ posterPath ? '保存海报' : (posterGenerateFailed ? '重新生成' : '生成中...') }}</text>
</view>
</view>
</view>
......@@ -138,6 +138,7 @@ const posterPath = ref('') // 生成的海报路径
const backgroundImage = ref('') // 用户上传的背景图
const shouldGeneratePoster = ref(false) // 是否应该生成海报
const currentPosterIndex = ref(0) // 当前显示的海报索引
const posterGenerateFailed = ref(false) // 海报生成是否失败
// 页面参数
const pageParams = ref({
......@@ -373,17 +374,11 @@ watch(currentPosterIndex, () => {
})
/**
* 返回上一页
*/
const goBack = () => {
Taro.navigateBack()
}
/**
* 生成当前海报
*/
const generateCurrentPoster = () => {
posterPath.value = ''
posterGenerateFailed.value = false
shouldGeneratePoster.value = false
// 延迟触发生成,确保配置更新
......@@ -493,6 +488,7 @@ const uploadBackgroundImage = (filePath) => {
*/
const onPosterSuccess = (result) => {
posterPath.value = result.tempFilePath
posterGenerateFailed.value = false
// 更新当前海报的路径
if (posterList.value[currentPosterIndex.value]) {
posterList.value[currentPosterIndex.value].path = result.tempFilePath
......@@ -506,6 +502,8 @@ const onPosterSuccess = (result) => {
*/
const onPosterFail = (error) => {
shouldGeneratePoster.value = false
posterGenerateFailed.value = true
posterPath.value = ''
Taro.showToast({ title: '海报生成失败', icon: 'none' })
console.error('海报生成失败:', error)
}
......@@ -530,6 +528,19 @@ const closePreview = () => {
}
/**
* 处理海报按钮点击事件
*/
const handlePosterAction = () => {
if (posterPath.value) {
// 如果海报已生成,执行保存操作
savePoster()
} else if (posterGenerateFailed.value) {
// 如果生成失败,重新生成海报
generateCurrentPoster()
}
}
/**
* 保存海报到相册
*/
const savePoster = () => {
......