feat: 接入持久化工作流执行状态

This commit is contained in:
GouJ committed 2026-09-23 19:53:55 +08:00
1 parent 7d2900c705
commit 3caea26924
14 files changed
+532 -44

No files matched your search

@@ -0,0 +1,107 @@
<script setup lang="ts">
import { computed } from 'vue'
import { NAlert, NButton, NProgress, NTag } from 'naive-ui'
import { RefreshCw, X } from '@lucide/vue'
import { formatDate } from '../../lib/format'
import { executionPercentage, executionStageLabel } from './execution'
import type { WorkflowExecution } from './execution.types'
const props = withDefaults(
defineProps<{ title?: string; execution: WorkflowExecution | null; loading: boolean; error: string }>(),
{ title: '后台任务' }
)
const emit = defineEmits<{ refresh: []; dismiss: [] }>()
const percentage = computed(() => executionPercentage(props.execution?.current ?? 0, props.execution?.total ?? 0))
const result = computed(() => props.execution?.result ?? {})
const statusLabel = computed(() => {
const labels = { pending: '等待开始', running: '执行中', completed: '已完成', failed: '失败' }
return props.execution ? labels[props.execution.status] : ''
})
const statusType = computed(() =>
props.execution?.status === 'completed' ? 'success' : props.execution?.status === 'failed' ? 'error' : 'warning'
)
const finished = computed(() => ['completed', 'failed'].includes(props.execution?.status ?? ''))
const videoQuality = computed(() => props.execution?.workflowName === 'video-quality')
</script>
<template>
<section v-if="execution || error" class="panel mt-4 p-5" :aria-label="title">
<div class="flex flex-wrap items-start justify-between gap-3">
<div>
<div class="flex flex-wrap items-center gap-2">
<h3 class="text-sm font-semibold">{{ title }}</h3>
<NTag v-if="execution" size="small" :type="statusType" :bordered="false">{{ statusLabel }}</NTag>
</div>
<p v-if="execution" class="mt-2 text-xs text-muted">
{{ executionStageLabel(execution.stage) }} · 更新于 {{ formatDate(execution.updatedAt) }}
</p>
</div>
<div class="flex items-center gap-2">
<NButton
class="icon-button"
quaternary
:loading="loading"
aria-label="刷新后台任务状态"
title="刷新后台任务状态"
@click="emit('refresh')"
><RefreshCw :size="15" /></NButton
><NButton
v-if="finished || error"
class="icon-button"
quaternary
aria-label="隐藏后台任务记录"
title="隐藏后台任务记录"
@click="emit('dismiss')"
><X :size="15" /></NButton
>
</div>
</div>
<template v-if="execution">
<NProgress
v-if="execution.total > 0"
type="line"
:percentage="percentage"
:height="5"
:show-indicator="false"
class="mt-4"
/>
<p class="mt-3 text-xs">
<template v-if="execution.total > 0">已处理 {{ execution.current }} / {{ execution.total }}</template>
<template v-else>后端正在确定本次任务范围</template>
<template v-if="execution.currentResourceId">
· 当前镜头 <code>{{ execution.currentResourceId }}</code></template
>
</p>
<NAlert v-if="execution.status === 'running'" type="info" :show-icon="false" class="mt-3">
{{
videoQuality
? '后端会继续生成、校验并按需修复。'
: '后端会继续处理剩余镜头并保存已完成的提示词。'
}}可以离开或刷新页面,返回后会继续显示本次任务进度,请勿重复提交。
</NAlert>
<NAlert v-else-if="execution.status === 'completed'" type="success" :show-icon="false" class="mt-3">
<p>本轮任务已结束,页面正在重新读取镜头资产状态。</p>
<p v-if="videoQuality" class="mt-2 text-xs">
目标 {{ result.targetCount ?? execution.total }} · 通过 {{ result.passed ?? 0 }} · 修复耗尽
{{ result.exhausted ?? 0 }} · 模型失败 {{ result.providerFailed ?? 0 }} · 提交失败
{{ result.submissionFailed ?? 0 }}
</p>
<p v-else class="mt-2 text-xs">
共 {{ result.total ?? execution.total }} · 生成 {{ result.generated ?? execution.current }} · 跳过
{{ result.skipped ?? 0 }} · 阻塞 {{ result.blocked ?? 0 }} · 失败 {{ result.failed ?? 0 }}
</p>
</NAlert>
<NAlert v-else-if="execution.status === 'failed'" type="error" :show-icon="false" class="mt-3">
<p>{{ execution.error || '后台任务执行失败。' }}</p>
<p class="mt-2 text-xs">
请先刷新下方视频状态,确认已成功的镜头;处理报错原因后,只对仍处于“可执行”的镜头重新提交。
</p>
</NAlert>
<p class="mt-3 break-all font-mono text-[10px] text-muted">执行 ID · {{ execution.id }}</p>
</template>
<NAlert v-if="error" type="error" :show-icon="false" class="mt-3">
{{ error }}。任务可能仍在后端运行,请先点击刷新;不要直接重复提交。
</NAlert>
</section>
</template>