feat(aigc): add auto-redirect when generation completes

Add complete event to GeneratingProgressPanel that emits when task status is completed and progress reaches 100%. Add handler in the parent progress page to automatically navigate to task detail page when the complete event is triggered, and stop ongoing task detail polling. Also enhance media download handling in the detail page with proper WeChat mini-program file path handling, error wrapping, temporary file cleanup, and improved error reporting for download failures.
This commit is contained in:
duanshuwen
2026-07-17 23:33:12 +08:00
parent 9b19da2257
commit 5fe3dd54b3
3 changed files with 116 additions and 17 deletions

View File

@@ -70,7 +70,7 @@ const props = defineProps({
},
});
const emit = defineEmits(["continue", "view"]);
const emit = defineEmits(["continue", "view", "complete"]);
const TASK_STATUS_PROGRESS = {
0: 23,
@@ -99,10 +99,19 @@ const clearProgressTimer = () => {
}
};
const emitComplete = () => {
if (Number(props.taskStatus) === 2 && normalizedProgress.value === 100) {
emit("complete");
}
};
const startProgressAnimation = () => {
clearProgressTimer();
const target = targetProgress.value;
if (normalizedProgress.value === target) return;
if (normalizedProgress.value === target) {
emitComplete();
return;
}
progressTimer = setInterval(() => {
const current = normalizedProgress.value;
@@ -114,6 +123,7 @@ const startProgressAnimation = () => {
displayProgress.value = nextProgress;
if (nextProgress === target) {
clearProgressTimer();
emitComplete();
}
}, 60);
};

View File

@@ -7,7 +7,8 @@
<view class="aigc-progress-content">
<GeneratingProgressPanel v-if="taskDetail" :cost="taskDetail.generatorCost"
:generator-type="taskDetail.generatorType" :item-title="taskDetail.itemTitle" :task-id="taskId"
:task-status="taskDetail.taskStatus" @continue="handleContinueTemplates" @view="handleViewTasks" />
:task-status="taskDetail.taskStatus" @continue="handleContinueTemplates" @view="handleViewTasks"
@complete="handleProgressComplete" />
</view>
</scroll-view>
</view>
@@ -28,6 +29,7 @@ const DETAIL_POLL_INTERVAL = 3000;
let detailPollTimer = null;
let isFetchingTaskDetail = false;
let isPageVisible = false;
let isNavigatingToDetail = false;
const showToast = (title) => {
uni.showToast({
@@ -178,6 +180,20 @@ const handleRecharge = () => {
fail: () => showToast("打开积分充值失败"),
});
};
const handleProgressComplete = () => {
if (isNavigatingToDetail || !taskId.value || !isTaskCompleted()) return;
isNavigatingToDetail = true;
stopTaskDetailPolling();
uni.redirectTo({
url: `/pages-aigc/detail/detail?taskId=${encodeURIComponent(taskId.value)}`,
fail: () => {
isNavigatingToDetail = false;
showToast("打开生成详情失败");
},
});
};
</script>
<style scoped lang="scss">