172 lines
8.7 KiB
Vue
172 lines
8.7 KiB
Vue
<script setup lang="ts">
|
||
import { computed } from 'vue'
|
||
import { NAlert, NButton, NProgress, NTag } from 'naive-ui'
|
||
import { 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')
|
||
/** 首帧质量后台任务使用独立的通过与修复失败统计,不套用普通生图字段。 */
|
||
const keyframeQuality = computed(() => props.execution?.workflowName === 'keyframe-quality')
|
||
/** 只接受后端完整的质量计数,畸形或缺失结果不显示全成功。 */
|
||
const keyframeCounts = computed(() => {
|
||
const fields = ['targetCount', 'passed', 'repairFailed', 'failed'] as const
|
||
if (
|
||
!fields.every(
|
||
field =>
|
||
typeof result.value[field] === 'number' &&
|
||
Number.isSafeInteger(result.value[field]) &&
|
||
Number(result.value[field]) >= 0
|
||
)
|
||
)
|
||
return null
|
||
const counts = {
|
||
targetCount: Number(result.value.targetCount),
|
||
passed: Number(result.value.passed),
|
||
repairFailed: Number(result.value.repairFailed),
|
||
failed: Number(result.value.failed)
|
||
}
|
||
return counts.passed + counts.repairFailed + counts.failed === counts.targetCount ? counts : null
|
||
})
|
||
/** 范围描述保留指定镜头或剧集,不把小批量误显示为全项目。 */
|
||
const scopeLabel = computed(() => {
|
||
const metadata = props.execution?.metadata
|
||
if (!metadata) return ''
|
||
const episode = typeof metadata.episodeNo === 'number' ? `第 ${metadata.episodeNo} 集` : '全项目'
|
||
const mode =
|
||
metadata.inputModeFilter === 'first_frame'
|
||
? '首帧模式'
|
||
: metadata.inputModeFilter === 'omni_reference'
|
||
? '全模态参考'
|
||
: '全部推荐模式'
|
||
if (keyframeQuality.value && typeof metadata.shotId === 'string') return `${episode} · 单镜头`
|
||
return videoQuality.value ? `${episode} · ${mode}` : episode
|
||
})
|
||
const inputPlanCounts = computed(() => {
|
||
const plans = result.value.inputPlans
|
||
if (!Array.isArray(plans)) return null
|
||
return {
|
||
firstFrame: plans.filter(plan => isInputMode(plan, 'first_frame')).length,
|
||
omniReference: plans.filter(plan => isInputMode(plan, 'omni_reference')).length
|
||
}
|
||
})
|
||
|
||
/** 对持久化 JSON 做最小结构校验,避免模板依赖不可信结果字段。 */
|
||
function isInputMode(value: unknown, inputMode: string): boolean {
|
||
return !!value && typeof value === 'object' && 'inputMode' in value && value.inputMode === inputMode
|
||
}
|
||
</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>
|
||
<p v-if="scopeLabel" class="mt-1 text-xs text-muted">范围:{{ scopeLabel }}</p>
|
||
</div>
|
||
<div class="flex items-center gap-2">
|
||
<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="
|
||
keyframeQuality && (!keyframeCounts || keyframeCounts.repairFailed + keyframeCounts.failed > 0)
|
||
? 'warning'
|
||
: '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-if="videoQuality && inputPlanCounts" class="mt-2 text-xs">
|
||
输入规划:首帧模式 {{ inputPlanCounts.firstFrame }} · 全模态参考
|
||
{{ inputPlanCounts.omniReference }}
|
||
</p>
|
||
<p v-else-if="keyframeQuality" class="mt-2 text-xs">
|
||
<template v-if="keyframeCounts"
|
||
>目标 {{ keyframeCounts.targetCount }} · 通过 {{ keyframeCounts.passed }} · 修复未通过
|
||
{{ keyframeCounts.repairFailed }} · 调用失败 {{ keyframeCounts.failed }}</template
|
||
>
|
||
<template v-else>后端首帧质量统计不完整,请查看任务详情并刷新核对。</template>
|
||
</p>
|
||
<p v-else-if="!videoQuality" 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>
|
||
<details class="mt-3 text-[10px] text-muted">
|
||
<summary class="cursor-pointer">任务详情</summary>
|
||
<p class="mt-2 break-all font-mono">任务编号 · {{ execution.id }}</p>
|
||
</details>
|
||
</template>
|
||
<NAlert v-if="error" type="error" :show-icon="false" class="mt-3">
|
||
{{ error }}。任务可能仍在运行,请先重新读取状态;不要直接重复提交。
|
||
<NButton text class="ml-3" :loading="loading" @click="emit('refresh')">重试读取</NButton>
|
||
</NAlert>
|
||
</section>
|
||
</template>
|