fix(frontend): 保持重新生成退出前详情

This commit is contained in:
caoxiaozhu
2026-07-27 10:43:48 +08:00
parent 53014bb381
commit 53844a3a09
4 changed files with 95 additions and 40 deletions

View File

@@ -15,7 +15,7 @@ import type { GenerationState, ResultItem } from './types'
interface GenerationBindings {
taskId: Ref<string | null>
dirty: Ref<boolean>
beforeGenerate?: () => Promise<void>
beforeGenerate?: () => Promise<boolean | void>
}
const RESULT_PAGE_SIZE = 500
@@ -51,6 +51,7 @@ export function useDataProcessGeneration(bindings: GenerationBindings) {
let generationTimer: ReturnType<typeof setTimeout> | null = null
let generationRun = 0
let pollFailureCount = 0
let generationStarting = false
function stopGenerationTimer() {
generationRun += 1
@@ -140,33 +141,39 @@ export function useDataProcessGeneration(bindings: GenerationBindings) {
}
async function startGeneration() {
if (generationStarting || generation.status === 'running') return
const taskId = bindings.taskId.value
if (!taskId) {
ElMessage.error('任务尚未创建,请返回上一步重试')
return
}
stopGenerationTimer()
const runId = generationRun
generation.status = 'running'
pollFailureCount = 0
generation.progress = 0
generation.message = '正在同步预览修改并启动后端处理,请稍候。'
generationStarting = true
let runId: number | null = null
try {
await bindings.beforeGenerate?.()
const canStart = await bindings.beforeGenerate?.()
if (canStart === false) return
stopGenerationTimer()
const activeRunId = generationRun
runId = activeRunId
generation.status = 'running'
pollFailureCount = 0
generation.progress = 0
generation.message = '正在同步预览修改并启动后端处理,请稍候。'
const progress = await generateDataProcess(taskId)
if (runId !== generationRun) return
if (activeRunId !== generationRun) return
if (progress.status === 'completed' || progress.status === 'failed' || progress.status === 'stopped') {
await finishFromProgress(progress)
return
}
applyProgress(progress)
generationTimer = setTimeout(() => void pollGeneration(runId), POLL_INTERVAL_MS)
generationTimer = setTimeout(() => void pollGeneration(activeRunId), POLL_INTERVAL_MS)
} catch (error) {
if (runId !== generationRun) return
if (runId !== null && runId !== generationRun) return
generation.status = 'failed'
generation.message = error instanceof Error ? error.message : '启动数据处理失败,请重试。'
} finally {
generationStarting = false
}
}