diff --git a/frontend/app/web-gold/src/views/dh/Video.vue b/frontend/app/web-gold/src/views/dh/Video.vue index fdb0969f5f..11c1f011ff 100644 --- a/frontend/app/web-gold/src/views/dh/Video.vue +++ b/frontend/app/web-gold/src/views/dh/Video.vue @@ -382,8 +382,10 @@ const generateVideo = async () => { if (createRes.code === 0) { currentTaskId.value = createRes.data + // 保存到本地存储,方便刷新页面后恢复 + localStorage.setItem('digital_human_last_task_id', createRes.data) message.success('任务创建成功,开始处理') - + // 3. 开始轮询任务状态 startPollingTask() } else { @@ -414,6 +416,37 @@ const uploadVideoFile = async (file) => { } } +// 加载最近一次任务结果 +const loadLastTask = async () => { + try { + const lastTaskId = localStorage.getItem('digital_human_last_task_id') + if (!lastTaskId) return + + const res = await getDigitalHumanTask(lastTaskId) + if (res.code === 0 && res.data) { + const task = res.data + currentTaskId.value = lastTaskId + + // 如果任务是成功状态,显示结果 + if (task.status === 'SUCCESS' && task.resultVideoUrl) { + previewVideoUrl.value = task.resultVideoUrl + currentTaskStatus.value = 'SUCCESS' + message.success('已自动加载最近一次任务结果') + } else if (task.status === 'PROCESSING') { + // 如果任务还在处理中,继续轮询 + currentTaskStatus.value = 'PROCESSING' + currentTaskStep.value = task.currentStep + generationProgress.value = task.progress || 0 + startPollingTask() + } + } + } catch (error) { + console.error('loadLastTask error:', error) + // 清理无效的缓存 + localStorage.removeItem('digital_human_last_task_id') + } +} + // 开始轮询任务状态 const startPollingTask = () => { if (pollingInterval.value) { @@ -441,18 +474,24 @@ const startPollingTask = () => { previewVideoUrl.value = task.resultVideoUrl isGenerating.value = false currentTaskStatus.value = 'SUCCESS' + // 保存成功的任务ID + localStorage.setItem('digital_human_last_task_id', currentTaskId.value) message.success('视频生成成功!') } else if (task.status === 'FAILED') { clearInterval(pollingInterval.value) pollingInterval.value = null isGenerating.value = false currentTaskStatus.value = 'FAILED' + // 失败时清除缓存 + localStorage.removeItem('digital_human_last_task_id') message.error(`任务失败:${task.errorMessage || '未知错误'}`) } else if (task.status === 'CANCELED') { clearInterval(pollingInterval.value) pollingInterval.value = null isGenerating.value = false currentTaskStatus.value = 'CANCELED' + // 取消时也清除缓存 + localStorage.removeItem('digital_human_last_task_id') message.info('任务已取消') } } @@ -639,6 +678,9 @@ onMounted(async () => { } else if (voiceSource.value === 'system' && SYSTEM_VOICES.length > 0) { selectVoiceProfile({ ...SYSTEM_VOICES[0], source: 'system' }) } + + // 加载最近一次任务结果 + await loadLastTask() }) onUnmounted(() => {