feat(short-drama-agent-front): 补齐后端生产与质量功能

This commit is contained in:
GJ committed 2026-10-08 18:28:35 +08:00
1 parent 967c4ebea1
commit 470b52e26d
52 files changed
+3754 -1075

No files matched your search

@@ -22,6 +22,29 @@ const statusType = computed(() =>
)
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 ''
@@ -32,6 +55,7 @@ const scopeLabel = computed(() => {
: metadata.inputModeFilter === 'omni_reference'
? '全模态参考'
: '全部推荐模式'
if (keyframeQuality.value && typeof metadata.shotId === 'string') return `${episode} · 单镜头`
return videoQuality.value ? `${episode} · ${mode}` : episode
})
const inputPlanCounts = computed(() => {
@@ -78,8 +102,8 @@ function isInputMode(value: unknown, inputMode: string): boolean {
aria-label="隐藏制作任务记录"
title="隐藏制作任务记录"
@click="emit('dismiss')"
><X :size="15" /></NButton
>
><X :size="15"
/></NButton>
</div>
</div>
@@ -101,12 +125,19 @@ function isInputMode(value: unknown, inputMode: string): boolean {
</p>
<NAlert v-if="execution.status === 'running'" type="info" :show-icon="false" class="mt-3">
{{
videoQuality
? '系统会继续生成、检查并按需修复。'
: '系统会继续处理剩余内容并保存已完成结果。'
videoQuality ? '系统会继续生成、检查并按需修复。' : '系统会继续处理剩余内容并保存已完成结果。'
}}可以离开或刷新页面,返回后会继续显示本次任务进度,请勿重复提交。
</NAlert>
<NAlert v-else-if="execution.status === 'completed'" type="success" :show-icon="false" class="mt-3">
<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 }} · 修复耗尽
@@ -117,7 +148,14 @@ function isInputMode(value: unknown, inputMode: string): boolean {
输入规划:首帧模式 {{ inputPlanCounts.firstFrame }} · 全模态参考
{{ inputPlanCounts.omniReference }}
</p>
<p v-else class="mt-2 text-xs">
<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>
@@ -125,7 +163,7 @@ function isInputMode(value: unknown, inputMode: string): boolean {
<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">
+97 -11
View File
@@ -1,9 +1,32 @@
import { computed, ref, watch, type Ref } from 'vue'
import { computed, onScopeDispose, reactive, ref, watch, type Ref } from 'vue'
import { usePolling } from '../../composables/usePolling'
import { workflowExecutionApi } from './execution-api'
const storagePrefix = 'short-drama:workflow-execution'
/** 同项目观察器共享真实后台句柄与活动状态,防止绕过弹窗重复付费启动。 */
interface ExecutionActivity {
/** 任务所属项目。 */
projectId: string
/** 后端实际任务编号。 */
id: string
/** 尚未取得终态时保持活动锁。 */
active: boolean
/** 同一任务取得终态后,任何迟到记录都不能使它重新活动。 */
terminal: boolean
}
/** 活动状态按项目和工作流共同隔离。 */
const executionActivity = reactive<Record<string, ExecutionActivity>>({})
/**
* 检查项目是否仍有已跟踪且未结束的后台任务。
* @param projectId 正式项目 ID
* @returns 是否存在活动后台任务
*/
export function hasActiveWorkflowExecution(projectId: string) {
return Object.values(executionActivity).some(record => record.projectId === projectId && record.active)
}
/** 任务阶段短标签;未知后端阶段保留原值,避免静默隐藏新能力。 */
export function executionStageLabel(stage: string | null) {
if (!stage) return '等待后端开始'
@@ -19,6 +42,11 @@ export function executionStageLabel(stage: string | null) {
resumeGeneration: '恢复分集剧本生成',
resumeRewrite: '恢复剧本改写',
breakdown: '拆解剧本',
storyboardRegenerate: '重生成单集镜头',
storyboardDirection: '生成导演设计',
storyboardVisualState: '生成即时状态',
keyframe_generation: '生成普通首帧',
videoPrompt: '生成视频提示词',
breakdownRetry: '重试失败拆解任务',
breakdownResumeShots: '补齐分镜镜头',
breakdownResumeStoryboard: '修复分镜绑定',
@@ -34,6 +62,7 @@ export function executionStageLabel(stage: string | null) {
finalize: '收尾生产状态',
manualReview: '等待人工处理',
video_prompt: '生成视频提示词',
keyframe_quality: '首帧质量生成',
submitting: '提交视频候选',
generating: '生成视频',
validating: '质量校验',
@@ -64,6 +93,11 @@ function savedExecutionId(projectId: string, workflowName: string) {
/** 跟踪一个项目最近的持久化任务;刷新页面后从本地句柄恢复,状态仍从后端读取。 */
export function useWorkflowExecution(projectId: Ref<string>, workflowName: string) {
/** 卸载后仍保存原项目返回的句柄,但不再更新已销毁的观察器。 */
let disposed = false
onScopeDispose(() => {
disposed = true
})
const executionId = ref('')
const terminal = ref(false)
watch(
@@ -71,13 +105,48 @@ export function useWorkflowExecution(projectId: Ref<string>, workflowName: strin
value => {
executionId.value = savedExecutionId(value, workflowName)
terminal.value = false
if (executionId.value && executionActivity[storageKey(value, workflowName)]?.id !== executionId.value)
executionActivity[storageKey(value, workflowName)] = {
projectId: value,
id: executionId.value,
active: true,
terminal: false
}
},
{ immediate: true }
)
/** 同页面其它入口跟踪了任务时,同步句柄并读取同一后台状态。 */
watch(
() => executionActivity[storageKey(projectId.value, workflowName)]?.id,
id => {
if (id && id !== executionId.value) {
terminal.value = false
executionId.value = id
}
}
)
const key = computed(() => executionId.value)
const query = usePolling(
key,
(id, signal) => (id ? workflowExecutionApi.get(id, signal) : Promise.resolve(null)),
async (id, signal) => {
if (!id) return null
const targetProjectId = projectId.value
const record = await workflowExecutionApi.get(id, signal)
if (record.projectId !== targetProjectId || record.workflowName !== workflowName || record.id !== id)
throw new Error('后台任务与当前项目或工作流不匹配,请刷新核对。')
const activity = executionActivity[storageKey(targetProjectId, workflowName)]
if (
!signal.aborted &&
!disposed &&
projectId.value === targetProjectId &&
activity?.id === id &&
!activity.terminal
) {
activity.terminal = ['completed', 'failed'].includes(record.status)
activity.active = !activity.terminal
}
return record
},
computed(() => (executionId.value && !terminal.value ? 1_500 : false))
)
watch(
@@ -86,16 +155,31 @@ export function useWorkflowExecution(projectId: Ref<string>, workflowName: strin
terminal.value = status === 'completed' || status === 'failed'
}
)
const active = computed(
() =>
!!executionId.value &&
(!query.data.value || ['pending', 'running'].includes(query.data.value.status))
)
const active = computed(() => {
const activity = executionActivity[storageKey(projectId.value, workflowName)]
return activity?.id === executionId.value
? activity.active
: !!executionId.value && (!query.data.value || ['pending', 'running'].includes(query.data.value.status))
})
/** 保存后端返回的真实 executionId,随后立即读取一次权威状态。 */
async function track(id: string) {
if (!id || !projectId.value) return
if (typeof localStorage !== 'undefined') localStorage.setItem(storageKey(projectId.value, workflowName), id)
/**
* 保存任务原项目的真实句柄,只有仍查看该项目时才读取权威状态。
* @param id 后端任务编号
* @param targetProjectId 启动请求时固定的原项目 ID
* @returns 保存句柄与可用观察器刷新完成
*/
async function track(id: string, targetProjectId = projectId.value) {
if (typeof id !== 'string' || !id.trim()) throw new Error('后端未返回有效任务编号,请刷新状态,勿重复提交。')
if (!targetProjectId) return
if (typeof localStorage !== 'undefined') localStorage.setItem(storageKey(targetProjectId, workflowName), id)
if (executionActivity[storageKey(targetProjectId, workflowName)]?.id !== id)
executionActivity[storageKey(targetProjectId, workflowName)] = {
projectId: targetProjectId,
id,
active: true,
terminal: false
}
if (disposed || projectId.value !== targetProjectId) return
terminal.value = false
executionId.value = id
await query.refresh()
@@ -103,6 +187,8 @@ export function useWorkflowExecution(projectId: Ref<string>, workflowName: strin
/** 只隐藏当前观察记录,不取消后端任务。 */
function dismiss() {
if (active.value) return
delete executionActivity[storageKey(projectId.value, workflowName)]
if (projectId.value && typeof localStorage !== 'undefined')
localStorage.removeItem(storageKey(projectId.value, workflowName))
executionId.value = ''
+18 -1
View File
@@ -1,5 +1,6 @@
import { reactive } from 'vue'
import { errorMessage } from '../../lib/http'
import { hasActiveWorkflowExecution } from './execution'
/** 当前浏览器会话中的操作状态;切换路由不会丢失长请求。 */
export interface Operation {
@@ -22,7 +23,23 @@ const operations = reactive<Record<string, Operation>>({})
/** 取得项目操作状态,不向浏览器持久化虚假的后台运行状态。 */
export function getOperation(projectId: string): Operation {
return (operations[projectId] ??= { pending: false, label: '', error: '', notice: '', recovery: null })
if (operations[projectId]) return operations[projectId]
/** 当前 HTTP 操作锁与持久化后台活动锁合并,后台结束前不能重复启动付费操作。 */
let requestPending = false
return (operations[projectId] = {
/** 当前项目是否有短请求或后台任务仍在执行。 */
get pending() {
return requestPending || hasActiveWorkflowExecution(projectId)
},
/** 更新短请求锁;后台锁只由后端真实终态释放。 */
set pending(value: boolean) {
requestPending = value
},
label: '',
error: '',
notice: '',
recovery: null
})
}
/** 只提交一次;断网不自动重试,后台是否已执行由刷新后的 checkpoint 确认。 */