Files
short-drama-agent-front/src/features/breakdown/BreakdownPage.vue
T

1034 lines
56 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import ContextNotice from '../../components/ui/ContextNotice.vue'
import AppForm from '../../components/ui/AppForm.vue'
import { NFormItem } from 'naive-ui'
import { integerRule, fieldRule } from '../../lib/form-rules'
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
import WorkspaceExportButton from '../../components/ui/WorkspaceExportButton.vue'
import { NScrollbar, NButton, NCheckbox, NInputNumber, NProgress, NTab, NTable, NTabs } from 'naive-ui'
import { computed, h, onScopeDispose, ref, watch } from 'vue'
import { useActionMessage } from '../../components/ui/useActionMessage'
import { Layers, LoaderCircle, ArrowRight, Settings2 } from '@lucide/vue'
import { EmptyState, StatusBadge, WorkspaceTools } from '../../components/ui'
import { useProjectContext } from '../projects/context'
import { breakdownApi } from './api'
import type { BreakdownAction, BreakdownInput, BreakdownModule, BreakdownPreview, StoryboardHandOccupancyDiagnostics, StoryboardHandRepairPreview, LegacyActionDiagnosisPreview, LegacyActionDiagnosisResults } from './types'
import { breakdownSnapshot, recoveryOptions, workflowCheckpoints } from '../workflows/selectors'
import { getOperation, isOperationRunning, runOperation } from '../workflows/operations'
import ConfirmAction from '../workflows/ConfirmAction.vue'
import WorkflowExecutionPanel from '../workflows/WorkflowExecutionPanel.vue'
import { useWorkflowExecution } from '../workflows/execution'
import SubjectList from './components/SubjectList.vue'
import StoryboardList from './components/StoryboardList.vue'
import { errorMessage } from '../../lib/http'
import { downloadText, nodeLabel } from '../../lib/format'
/** 拆解工作区:先预览真实分组,再启动;恢复操作根据 checkpoint 分阶段展示。 */
const { project, checkpoints, refresh, refreshStageReadiness, stageReadiness, error } = useProjectContext()
const groupSize = ref(3)
const modules = ref<BreakdownModule[]>(['character', 'scene', 'prop'])
const preview = ref<BreakdownPreview | null>(null)
const previewBusy = ref(false)
const tab = ref('character')
const toolsOpen = ref(false)
/** 仅打开设置面板时按需查询,不增加页面常驻提示或后台轮询。 */
const handDiagnostics = ref<StoryboardHandOccupancyDiagnostics | null>(null)
const handDiagnosticsBusy = ref(false)
const handRepairPreview = ref<StoryboardHandRepairPreview | null>(null)
const handRepairBusy = ref(false)
/** 只在用户主动查看时加载修复候选,避免打开设置就请求额外接口。 */
async function loadHandRepairPreview(id: string) {
const version = handDiagnosticsVersion
handRepairBusy.value = true
try {
const data = await breakdownApi.handRepairPreview(id)
if (version === handDiagnosticsVersion && toolsOpen.value && projectId.value === id) handRepairPreview.value = data
} catch (cause) {
if (version === handDiagnosticsVersion && toolsOpen.value && projectId.value === id) actionMessage?.error(errorMessage(cause))
} finally {
if (version === handDiagnosticsVersion) handRepairBusy.value = false
}
}
let handDiagnosticsVersion = 0
async function loadHandDiagnostics(id: string) {
const version = ++handDiagnosticsVersion
handDiagnosticsBusy.value = true
handDiagnostics.value = null
try {
const data = await breakdownApi.handOccupancyDiagnostics(id)
if (version === handDiagnosticsVersion && toolsOpen.value && projectId.value === id) handDiagnostics.value = data
} catch (cause) {
if (version === handDiagnosticsVersion && toolsOpen.value && projectId.value === id) actionMessage?.error(errorMessage(cause))
} finally {
if (version === handDiagnosticsVersion) handDiagnosticsBusy.value = false
}
}
const moduleOptions: { value: BreakdownModule; label: string; description: string }[] = [
{ value: 'character', label: '人物', description: '人物身份、外观与形态' },
{ value: 'scene', label: '场景', description: '故事空间与环境特征' },
{ value: 'prop', label: '道具', description: '关键物件与视觉描述' }
]
const records = computed(() => workflowCheckpoints(checkpoints.value, 'breakdown'))
const snapshot = computed(() => breakdownSnapshot(checkpoints.value))
const result = computed(() => snapshot.value?.breakdownResult ?? snapshot.value)
const subjects = computed(() => result.value?.subjectCandidates ?? [])
const forms = computed(() => result.value?.subjectForms ?? [])
const plans = computed(() => result.value?.storyboardPlans ?? [])
const shots = computed(() => result.value?.storyboardEpisodeShots ?? [])
const summary = computed(() => snapshot.value?.taskSummary)
const validation = computed(() => result.value?.storyboardShotValidation ?? snapshot.value?.storyboardShotValidation)
const projectId = computed(() => project.value?.id ?? '')
const operation = computed(() => getOperation(projectId.value))
watch([toolsOpen, projectId], () => {
++handDiagnosticsVersion
handDiagnostics.value = null
handDiagnosticsBusy.value = false
handRepairPreview.value = null
handRepairBusy.value = false
++legacyResultsRequest
legacyResultsBusy.value = false
legacyResults.value = null
})
/** 历史镜头 AI 诊断使用独立的持久化任务观察器,刷新后可恢复进度。 */
const legacyDiagnosisExecution = useWorkflowExecution(projectId, 'storyboard-legacy-action-diagnosis')
const legacyEpisodeNo = ref(3)
const legacyConcurrency = ref(3)
const legacyPreview = ref<LegacyActionDiagnosisPreview | null>(null)
const legacyPreviewBusy = ref(false)
const legacyStarting = ref(false)
const legacyDiagnosisScope = ref<'episode' | 'project'>('episode')
const legacyResults = ref<LegacyActionDiagnosisResults | null>(null)
const legacyResultsBusy = ref(false)
let legacyResultsRequest = 0
async function loadLegacyResults() {
const id = projectId.value
const version = handDiagnosticsVersion
const requestVersion = ++legacyResultsRequest
const episode = legacyDiagnosisScope.value === 'episode' ? legacyEpisodeNo.value : undefined
legacyResultsBusy.value = true
try {
const data = await breakdownApi.legacyActionDiagnosisResults(id, episode)
if (requestVersion === legacyResultsRequest && version === handDiagnosticsVersion && projectId.value === id && toolsOpen.value) legacyResults.value = data
} catch (cause) {
if (requestVersion === legacyResultsRequest && version === handDiagnosticsVersion && projectId.value === id && toolsOpen.value) actionMessage?.error(errorMessage(cause))
} finally {
if (requestVersion === legacyResultsRequest) legacyResultsBusy.value = false
}
}
watch(() => legacyDiagnosisExecution.query.data.value?.status, (status, previous) => {
if (status && status !== previous && (status === 'completed' || status === 'failed') && toolsOpen.value) {
void loadLegacyResults()
}
})
watch([legacyEpisodeNo, legacyDiagnosisScope, projectId], () => {
++legacyResultsRequest
legacyResultsBusy.value = false
legacyPreview.value = null
legacyResults.value = null
})
const legacyDiagnosisDescription = computed(() => legacyDiagnosisScope.value === 'project' ? '全项目历史镜头 AI 诊断,已有有效结果将跳过。会产生模型费用,不会修改镜头。' : `第 ${legacyEpisodeNo.value} 集,共 ${legacyPreview.value?.candidateCount ?? '未知'} 个镜头,并发 ${legacyConcurrency.value}。会产生模型费用,已有有效结果将跳过。`)
async function loadLegacyPreview() {
const id = projectId.value
const version = handDiagnosticsVersion
legacyPreviewBusy.value = true
try {
const data = await breakdownApi.legacyActionDiagnosisPreview(id, legacyEpisodeNo.value)
if (version === handDiagnosticsVersion && projectId.value === id && toolsOpen.value) legacyPreview.value = data
} catch (cause) {
if (version === handDiagnosticsVersion && projectId.value === id && toolsOpen.value) actionMessage?.error(errorMessage(cause))
} finally {
if (version === handDiagnosticsVersion) legacyPreviewBusy.value = false
}
}
async function startLegacyDiagnosis() {
const id = projectId.value
legacyStarting.value = true
try {
const diagnosisTask = await breakdownApi.startLegacyActionDiagnosis(id, {
confirmed: true,
...(legacyDiagnosisScope.value === 'episode' ? { episodeNo: legacyEpisodeNo.value } : {}),
concurrency: legacyConcurrency.value
})
await legacyDiagnosisExecution.track(diagnosisTask.executionId, id)
} catch (cause) {
actionMessage?.error(errorMessage(cause))
} finally {
legacyStarting.value = false
}
}
const backgroundExecution = useWorkflowExecution(projectId, 'breakdown')
const recovery = computed(() => recoveryOptions(checkpoints.value))
const execution = computed(() => snapshot.value?.workflowExecution)
const taskStopped = computed(() => execution.value?.status === 'failed' || execution.value?.status === 'completed')
/** 后台拆解结束后自动刷新项目、Checkpoint 与正式主体/分镜数据。 */
watch(
() => backgroundExecution.query.data.value?.status,
(status, previous) => {
if ((status === 'completed' || status === 'failed') && status !== previous)
void Promise.all([refresh(), refreshStageReadiness()])
}
)
const showRecovery = computed(
() => records.value.length > 0 && (execution.value?.status !== 'completed' || validation.value?.valid === false)
)
const configValid = computed(
() => Number.isSafeInteger(groupSize.value) && groupSize.value > 0 && modules.value.length > 0
)
const input = computed<BreakdownInput>(() => ({ groupSize: groupSize.value, modules: [...modules.value] }))
/** 后端就绪状态决定是否显示后续制作入口。 */
const stageComplete = computed(() => stageReadiness.value?.breakdown.ready === true)
/** 拆解提示复用全局 NMessage,详细问题留在设置弹窗。 */
const actionMessage = useActionMessage()
/** 问题内容变化才通知,轮询取得相同快照时不会重复弹出。 */
const issueSignature = computed(() =>
JSON.stringify({
error: execution.value?.errorMessage || '',
issues: validation.value?.valid === false ? validation.value.issues : []
})
)
/** 首次读取或问题变化时只显示一条汇总,保留可操作的详情入口。 */
watch(
issueSignature,
() => {
const executionError = execution.value?.errorMessage
const invalid = validation.value?.valid === false
if (!executionError && !invalid) return
actionMessage?.warning(
() =>
h('div', { class: 'flex flex-wrap items-center gap-3' }, [
h(
'span',
invalid
? `分镜校验未通过,共 ${validation.value?.issues.length ?? 0} 项问题。`
: '拆解任务未完成,请查看错误详情。'
),
h(
NButton,
{
text: true,
onClick: () => {
toolsOpen.value = true
}
},
() => '查看详情与恢复操作'
)
]),
{ duration: 6000, closable: true }
)
},
{ immediate: true }
)
/** 已加载的就绪状态由未完成变为完成时通知,不重放首次读取的历史结果。 */
watch([() => stageReadiness.value, stageComplete], ([, ready], [previousReadiness, previous]) => {
if (previousReadiness && ready && !previous)
actionMessage?.success('剧本拆解已准备完成,可以继续视觉风格。', { duration: 4000, closable: true })
})
const canStart = computed(
() =>
!!project.value?.episodes.length &&
project.value.status === 'completed' &&
!!preview.value &&
configValid.value &&
!operation.value.pending &&
!backgroundExecution.active.value &&
!error.value &&
(!records.value.length || taskStopped.value)
)
let previewController: AbortController | undefined
let previewVersion = 0
/** 输入变化立即废弃旧预览,防止按新配置启动旧的任务清单。 */
function invalidatePreview() {
previewVersion++
previewController?.abort()
preview.value = null
previewBusy.value = false
}
watch(
[
groupSize,
() => modules.value.join(','),
() => project.value?.episodes.map(item => item.episode + ':' + item.content).join('|')
],
invalidatePreview
)
onScopeDispose(invalidatePreview)
/** 只接受明确勾选状态,不把不确定值作为模块选择。 */
function toggleModule(module: BreakdownModule, checked: boolean | 'indeterminate') {
if (checked === true && !modules.value.includes(module)) modules.value.push(module)
else modules.value = modules.value.filter(item => item !== module)
}
/** 获取服务器生成的任务分组,不在浏览器伪造任务 ID。 */
async function loadPreview() {
if (!configValid.value || project.value?.status !== 'completed' || previewBusy.value) return
invalidatePreview()
const version = previewVersion
previewController = new AbortController()
previewBusy.value = true
try {
const data = await breakdownApi.preview(project.value.id, input.value, previewController.signal)
if (version === previewVersion) preview.value = data
} catch (cause) {
if (version === previewVersion) actionMessage?.error(errorMessage(cause), { duration: 6000, closable: true })
} finally {
if (version === previewVersion) previewBusy.value = false
}
}
/** 长请求不随路由切换取消,返回后刷新 checkpoint 与正式项目数据。 */
async function run(action: BreakdownAction) {
if (project.value?.status !== 'completed' || operation.value.pending || error.value) return
if (action === 'start' && !canStart.value) return
const labels: Record<BreakdownAction, string> = {
start: '正在拆解剧本',
retry: '正在重试失败抽取',
'resume-shots': '正在补齐镜头',
'resume-storyboard': '正在修复分镜绑定'
}
const id = project.value.id
await runOperation(
id,
labels[action],
async () => {
const started = await breakdownApi.run(id, action, action === 'start' ? input.value : undefined)
await backgroundExecution.track(started.executionId)
return started
},
{ type: 'info', content: '拆解任务已提交,可在“拆解设置与恢复”中查看进度。' }
)
await refresh()
}
/** 导出当前拆解结果;阶段性数据也明确标记为 snapshot。 */
function exportResult() {
if (!snapshot.value) return
downloadText(
`breakdown-${project.value?.id}-snapshot.json`,
JSON.stringify(snapshot.value, null, 2),
'application/json'
)
}
const formModel = computed(() => ({ groupSize: groupSize.value, modules: modules.value }))
const rules = {
groupSize: integerRule('每组集数'),
modules: fieldRule(value => Array.isArray(value) && value.length > 0, '请至少选择一个抽取模块', true)
}
</script>
<template>
<!-- 以下是手机完成提示自然滚走、分类导航与设置入口吸顶的拆解工作区 -->
<WorkspacePage split compact mobile-scroll class="breakdown-workspace-page">
<template #header>
<!-- 以下是拆解状态与设置 -->
<div class="workspace-toolbar">
<h2 class="font-semibold">剧本拆解</h2>
<div v-if="snapshot" class="toolbar-summary">
<span v-if="summary"
>抽取 {{ summary.completed }} / {{ summary.total }} · 失败 {{ summary.failed }}</span
>
<span>主体 {{ subjects.length }} · 分镜剧集 {{ shots.length }} / {{ plans.length }}</span>
<StatusBadge
:status="execution?.status || 'unknown'"
:label="
execution?.status === 'completed'
? '工作流已完成'
: execution?.status === 'failed'
? '工作流失败'
: '执行状态待确认'
"
/>
</div>
<!-- 以下是轻量状态入口,详细问题与恢复操作统一放入弹窗 -->
<div v-if="project?.episodes.length" class="toolbar-actions">
<NButton
v-if="execution?.errorMessage || validation?.valid === false"
text
type="error"
@click="toolsOpen = true"
>查看拆解问题</NButton
>
<RouterLink v-if="stageComplete" :to="`/projects/${projectId}/visual-style`" class="text-button"
>继续视觉风格 →</RouterLink
>
<WorkspaceTools
:pending="operation.pending"
:pending-label="operation.label"
v-model:open="toolsOpen"
title="拆解设置与恢复"
label="拆解设置与恢复"
>
<section class="panel workspace-panel breakdown-settings-panel">
<div class="flex flex-wrap items-start justify-between gap-3">
<div>
<h2 class="flex items-center gap-2 font-semibold"><Layers :size="17" />拆解设置</h2>
<p class="mt-2 text-xs leading-5 text-muted">
读取已保存的
{{ project.episodes.length }}
集剧本。每个分组分别抽取所选模块,再生成主体与分镜。
</p>
</div>
</div>
<AppForm
class="breakdown-settings-form"
:model="formModel"
:rules="rules"
:disabled="operation.pending"
validate-on-change
@submit="loadPreview"
>
<div class="breakdown-config">
<NFormItem
class="breakdown-group-field"
path="groupSize"
label="每组集数"
:label-props="{ for: 'group-size' }"
>
<div class="breakdown-group-input">
<NInputNumber
:disabled="operation.pending"
:input-props="{ id: 'group-size' }"
class="breakdown-group-number"
:value="typeof groupSize === 'number' ? groupSize : null"
@update:value="groupSize = $event ?? 0"
:min="1"
:step="1"
></NInputNumber
><span class="breakdown-group-unit">集 / 组</span>
</div>
</NFormItem>
<NFormItem path="modules" label="抽取模块" class="breakdown-modules-field">
<div class="breakdown-module-options">
<div
v-for="option in moduleOptions"
:key="option.value"
class="breakdown-module-option"
>
<NCheckbox
:checked="modules.includes(option.value)"
:disabled="operation.pending"
:aria-label="option.label"
:aria-describedby="`breakdown-module-${option.value}-help`"
@update:checked="toggleModule(option.value, $event)"
class="control-row-checkbox"
><span class="text-sm font-medium">{{
option.label
}}</span></NCheckbox
>
<p
:id="`breakdown-module-${option.value}-help`"
class="breakdown-module-description"
>
{{ option.description }}
</p>
</div>
</div>
</NFormItem>
<NButton
:disabled="
project?.status !== 'completed' ||
previewBusy ||
operation.pending ||
!!error
"
attr-type="submit"
class="breakdown-preview-button"
><LoaderCircle v-if="previewBusy" :size="14" class="animate-spin" />预览分组
</NButton>
</div>
</AppForm>
<div v-if="preview" class="group-preview">
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
<p class="text-sm">
<strong>{{ preview.groupCount }}</strong> 个分组
<span class="mx-2 text-faint">/</span>
<strong>{{ preview.estimatedTaskCount }}</strong> 个抽取任务
</p>
<ConfirmAction
:loading="
isOperationRunning(operation, '正在拆解剧本') ||
backgroundExecution.active.value
"
:label="records.length ? '重新拆解' : '开始拆解'"
:description="
records.length
? '这会重新运行完整剧本拆解,可能替换已保存的主体与分镜。只想恢复失败阶段时,请使用下方对应恢复操作。'
: '将按当前预览配置启动完整的 剧本拆解流程。抽取结束后仍需完成主体整理、分镜生成与入库。'
"
:acknowledgement="records.length > 0"
primary
:disabled="!canStart"
@confirm="run('start')"
/>
</div>
<div class="flex flex-wrap gap-2">
<div v-for="group in preview.groups" :key="group.groupId" class="group-chip">
<span class="text-muted">{{ String(group.groupNo).padStart(2, '0') }}</span
><span>第 {{ group.startEpisodeNo }}–{{ group.endEpisodeNo }} 集</span>
</div>
</div>
</div>
<p v-if="project.status === 'generating'" class="mt-4 text-xs text-danger">
剧本仍在生成,暂不允许启动拆解,避免读取到不完整的剧集。
</p>
<p v-if="records.length && !taskStopped" class="mt-4 text-xs leading-5 text-muted">
当前任务还没有明确的完成或失败记录。为避免重复执行,已暂停重新拆解;如任务已中断,请先刷新状态,再选择对应恢复操作。
</p>
</section>
<WorkflowExecutionPanel
v-if="backgroundExecution.executionId.value"
title="剧本拆解任务"
class="breakdown-execution-panel"
:show-status-hint="false"
:execution="backgroundExecution.query.data.value"
:loading="backgroundExecution.query.loading.value"
:error="backgroundExecution.query.error.value"
@refresh="backgroundExecution.query.refresh"
@dismiss="backgroundExecution.dismiss"
/>
<!-- 手部动作诊断按需读取,历史镜头缺少证据时不误报为安全。 -->
<section class="workspace-panel">
<div class="flex flex-wrap items-center justify-between gap-3">
<h3 class="text-sm font-medium">手部动作质量</h3>
<NButton text :loading="handDiagnosticsBusy" :disabled="!projectId || handDiagnosticsBusy" @click="loadHandDiagnostics(projectId)">{{ handDiagnostics ? '刷新' : '查看诊断' }}</NButton>
</div>
<div v-if="handDiagnostics" class="mt-3 flex flex-wrap gap-x-4 gap-y-2 text-xs text-muted">
<span>镜头 {{ handDiagnostics.shotCount }}</span>
<span>有效证据 {{ handDiagnostics.evidenceShotCount }} / {{ handDiagnostics.shotCount }}</span>
<span>冲突 {{ handDiagnostics.warningCount }}</span>
<span v-if="handDiagnostics.assessment === 'insufficient_evidence'">证据不足</span>
<span v-else-if="handDiagnostics.assessment === 'partial_evidence'">部分镜头缺少证据</span>
</div>
<div v-if="handDiagnostics?.diagnostics.length" class="mt-3 space-y-2 text-xs">
<div v-for="(issue, index) in handDiagnostics.diagnostics" :key="index">
第 {{ issue.episodeNo }} 集 / Beat {{ issue.beatNo }} / Shot {{ issue.shotNo }} / 阶段 {{ issue.phaseNo }}:{{ issue.suggestion }}
</div>
</div>
</section>
<section class="workspace-panel">
<div class="flex flex-wrap items-center justify-between gap-3">
<h3 class="text-sm font-medium">历史镜头 AI 动作诊断</h3>
<NButton text :loading="legacyPreviewBusy" @click="loadLegacyPreview">预览范围</NButton>
</div>
<div class="mt-3 flex flex-wrap items-center gap-3">
<NButton size="small" :type="legacyDiagnosisScope === 'episode' ? 'primary' : 'default'" @click="legacyDiagnosisScope = 'episode'">单集</NButton>
<NButton size="small" :type="legacyDiagnosisScope === 'project' ? 'primary' : 'default'" @click="legacyDiagnosisScope = 'project'">全项目</NButton>
<NInputNumber v-if="legacyDiagnosisScope === 'episode'" v-model:value="legacyEpisodeNo" :min="1" :precision="0" size="small" class="w-24" />
<span class="text-xs text-muted">并发</span>
<NInputNumber v-model:value="legacyConcurrency" :min="1" :max="5" :precision="0" size="small" class="w-20" />
</div>
<div v-if="legacyPreview" class="mt-3 text-xs text-muted">
第 {{ legacyPreview.episodeNo }} 集:{{ legacyPreview.candidateCount }} 个镜头,{{ legacyPreview.needsEvidenceCount }} 个待补证据
</div>
<div class="mt-3 flex justify-end">
<ConfirmAction label="启动 AI 诊断" :description="legacyDiagnosisDescription"
:loading="legacyStarting" :disabled="legacyDiagnosisExecution.active.value || legacyStarting || (legacyDiagnosisScope === 'episode' && !legacyPreview)"
primary @confirm="startLegacyDiagnosis" />
</div>
<div class="mt-3 flex flex-wrap items-center justify-between gap-3">
<span class="text-xs text-muted">诊断结果</span>
<NButton text :loading="legacyResultsBusy" @click="loadLegacyResults">查看结果</NButton>
</div>
<div v-if="legacyResults" class="mt-2 space-y-3 text-xs">
<div class="flex flex-wrap gap-x-4 gap-y-2 text-muted">
<span>总计 {{ legacyResults.counts.total }}</span>
<span>冲突 {{ legacyResults.counts.conflict }}</span>
<span>未发现冲突 {{ legacyResults.counts.clear }}</span>
<span>证据不足 {{ legacyResults.counts.insufficient }}</span>
<span>证据无效 {{ legacyResults.counts.invalid }}</span>
<span>已过期 {{ legacyResults.counts.stale }}</span>
<span>未诊断 {{ legacyResults.counts.pending }}</span>
</div>
<div v-for="item in legacyResults.shots.filter(shot => shot.status !== 'no_conflict_found')" :key="item.shotId" class="py-1">
第 {{ item.episodeNo }} 集 / Beat {{ item.beatNo }} / Shot {{ item.shotNo }} · {{ item.title }}
<span class="ml-2 text-muted">{{ ({
conflict_found: '手部冲突',
insufficient_evidence: '证据不足',
invalid_evidence: '证据无效',
stale: '诊断过期',
not_diagnosed: '尚未诊断',
no_conflict_found: '未发现冲突'
} as const)[item.status] }}</span>
</div>
</div>
<WorkflowExecutionPanel v-if="legacyDiagnosisExecution.executionId.value"
title="历史动作诊断任务"
:execution="legacyDiagnosisExecution.query.data.value ?? null"
:loading="legacyDiagnosisExecution.query.loading.value"
:error="legacyDiagnosisExecution.query.error.value ?? ''"
@refresh="legacyDiagnosisExecution.query.refresh()"
@dismiss="legacyDiagnosisExecution.dismiss()" />
</section>
<section v-if="handDiagnostics?.warningCount" class="workspace-panel">
<div class="flex items-center justify-between gap-3">
<h3 class="text-sm font-medium">局部修复候选</h3>
<NButton text :loading="handRepairBusy" :disabled="handRepairBusy" @click="loadHandRepairPreview(projectId)">
{{ handRepairPreview ? '刷新候选' : '查看候选' }}
</NButton>
</div>
<div v-if="handRepairPreview" class="mt-3 space-y-2 text-xs">
<div v-for="(item, index) in handRepairPreview.candidates" :key="index" class="space-y-1">
<p>第 {{ item.episodeNo }} 集 / Beat {{ item.beatNo }} / Shot {{ item.shotNo }} / 阶段 {{ item.phaseNo }}</p>
<p class="text-muted">{{ item.suggestion }}</p>
<p v-if="item.blockingReasons.length" class="text-muted">{{ item.blockingReasons.join(';') }}</p>
</div>
</div>
</section>
<section v-if="snapshot">
<div class="mb-3 flex flex-wrap items-center justify-between gap-3">
<h2 class="text-sm font-medium">
最近可用拆解快照
<span class="ml-2 text-xs font-normal text-muted">{{
nodeLabel(records.at(-1)?.metadata?.nodeName)
}}</span>
</h2>
<StatusBadge
:status="execution?.status || 'unknown'"
:label="
execution?.status === 'completed'
? '工作流已完成'
: execution?.status === 'failed'
? '工作流失败'
: '阶段快照 · 执行状态待确认'
"
/>
</div>
<div v-if="summary" class="flex flex-wrap items-center gap-x-6 gap-y-2 text-xs text-muted">
<span
>抽取完成
<strong class="text-ink"
>{{ summary.completed }} / {{ summary.total }}</strong
></span
><span>失败 {{ summary.failed }}</span
><span>主体 {{ subjects.length }}</span
><span>分镜剧集 {{ shots.length }} / {{ plans.length }}</span>
</div>
<NProgress
v-if="summary?.total"
aria-label="已完成抽取任务"
type="line"
:show-indicator="false"
:height="4"
:percentage="
Math.min(100, Math.max(0, (summary.completed / Math.max(1, summary.total)) * 100))
"
class="mt-3"
></NProgress>
<ContextNotice
v-if="execution?.errorMessage"
role="alert"
type="error"
:show-icon="false"
class="mt-4"
>{{ execution.errorMessage }}</ContextNotice
>
<ContextNotice
v-if="validation && !validation.valid"
type="error"
:show-icon="false"
class="mt-4"
><p class="font-medium">分镜校验未通过</p>
<ul class="mt-2 list-inside list-disc space-y-1">
<li v-for="(issue, index) in validation.issues" :key="index">
第 {{ issue.episodeNo }} 集<span v-if="issue.beatNo">
/ Beat {{ issue.beatNo }}</span
><span v-if="issue.shotNo"> / Shot {{ issue.shotNo }}</span
>:{{ issue.message }}
</li>
</ul></ContextNotice
>
<div v-if="showRecovery" class="recovery-strip mt-4">
<div>
<p class="text-sm font-medium">从中断处继续</p>
<p class="mt-1 text-xs leading-5 text-muted">
抽取失败、镜头缺失、主体绑定异常分别处理。禁用表示近期 checkpoint
不具备所需数据。
</p>
</div>
<div class="flex flex-wrap gap-2">
<ConfirmAction
:loading="isOperationRunning(operation, '正在重试失败抽取')"
label="重试失败抽取"
description="只重试 character / scene / prop 抽取任务中的失败项。不能用于镜头阶段失败。"
acknowledgement
:disabled="
project?.status !== 'completed' ||
!recovery.retry ||
operation.pending ||
!!error
"
@confirm="run('retry')"
/><ConfirmAction
:loading="isOperationRunning(operation, '正在补齐镜头')"
label="补齐缺失镜头"
description="复用已完成剧集的镜头,仅生成尚未完成的 Episode Shot,再进行校验与入库。"
acknowledgement
:disabled="
project?.status !== 'completed' ||
!recovery.shots ||
operation.pending ||
!!error
"
@confirm="run('resume-shots')"
/><ConfirmAction
:loading="isOperationRunning(operation, '正在修复分镜绑定')"
label="修复分镜绑定"
description="复用已有镜头,修复 SubjectRef 与视觉 Form 绑定,再校验并保存。"
acknowledgement
:disabled="
project?.status !== 'completed' ||
!recovery.storyboard ||
operation.pending ||
!!error
"
@confirm="run('resume-storyboard')"
/>
</div>
</div>
</section>
</WorkspaceTools>
</div>
</div>
</template>
<NScrollbar v-if="!project?.episodes.length" class="panel-scroll panel">
<EmptyState
title="还没有可拆解的剧集"
description="先完成剧本创作。拆解会读取数据库中的正式剧集,不需要上传 checkpoint。"
><RouterLink class="button button-primary" :to="`/projects/${project?.id}/create-drama`"
>前往剧本创作<ArrowRight :size="14" /></RouterLink
></EmptyState>
</NScrollbar>
<template v-else>
<section class="breakdown-results-section">
<div class="result-toolbar tabs-toolbar">
<NTabs v-model:value="tab" class="workspace-tabs" type="line" size="small" aria-label="拆解结果"
><!-- 以下是仅显示分类名称的拆解标签模块,主体数量保留在搜索统计中 -->
<NTab v-for="option in moduleOptions" :key="option.value" :name="option.value">{{
option.label
}}</NTab
><NTab name="storyboard">分镜</NTab
><NTab name="tasks"
><span class="breakdown-task-label-desktop">任务明细</span
><span class="breakdown-task-label-mobile">任务</span></NTab
>
<template #suffix
><div class="tabs-toolbar-actions breakdown-toolbar-actions">
<!-- 以下是手机分类导航中的拆解设置入口,共用原有设置弹窗 -->
<NButton
quaternary
class="icon-button breakdown-mobile-tools"
aria-label="拆解设置与恢复"
title="拆解设置与恢复"
aria-haspopup="dialog"
:aria-expanded="toolsOpen"
@click="toolsOpen = true"
>
<template #icon><Settings2 :size="15" /></template>
</NButton>
<!-- 以下是拆解快照直接导出模块,与剧本创作共用图标和悬浮说明 -->
<WorkspaceExportButton
label="导出拆解结果"
:disabled="!snapshot"
@export="exportResult"
/></div
></template>
</NTabs>
</div>
<div class="breakdown-content panel">
<main class="min-w-0 min-h-0 overflow-hidden">
<!-- 所有结果标签共用有界的内容滚动;切换标签回到顶部,不继承上一列表的位置。 -->
<NScrollbar :key="tab" class="panel-scroll breakdown-results-scroll">
<template v-for="option in moduleOptions" :key="option.value"
><div v-if="tab === option.value" class="breakdown-result-pad">
<SubjectList
:project-id="project?.id"
:subjects="subjects.filter(item => item.module === option.value)"
:forms="forms"
/></div
></template>
<div v-if="tab === 'storyboard'" class="breakdown-result-pad">
<StoryboardList :plans="plans" :episodes="shots">
<template #actions>
<RouterLink :to="`/projects/${project?.id}/storyboard`" class="text-button"
>进入分镜设计<ArrowRight :size="14"
/></RouterLink>
</template>
</StoryboardList>
</div>
<div v-if="tab === 'tasks'" class="breakdown-result-pad">
<NScrollbar x-scrollable v-if="snapshot?.tasks?.length" class="table-scroll">
<NTable :bordered="false" :single-line="true" striped class="project-table"
><thead>
<tr>
<th>分组</th>
<th>模块</th>
<th>状态</th>
<th>尝试</th>
</tr>
</thead>
<tbody>
<template v-for="task in snapshot.tasks" :key="task.taskId"
><tr>
<td>
第 {{ task.group.startEpisodeNo }}–{{ task.group.endEpisodeNo }}
集
</td>
<td>
{{
moduleOptions.find(item => item.value === task.module)
?.label
}}
</td>
<td>
<StatusBadge
:status="task.status"
:label="
{
pending: '等待中',
running: '执行中',
completed: '完成',
failed: '失败'
}[task.status]
"
/>
</td>
<td>{{ task.attempt }}</td>
</tr>
<tr v-if="task.errorMessage">
<td colspan="4" class="text-danger">{{ task.errorMessage }}</td>
</tr></template
>
</tbody></NTable
>
</NScrollbar>
<EmptyState
v-else
title="尚无抽取任务记录"
description="启动拆解后会持续保存进度;预览只展示本次处理范围,不会直接开始执行。"
/>
</div>
</NScrollbar>
</main>
</div>
</section>
</template>
</WorkspacePage>
</template>
<style>
/* 本组件专属布局与 Naive 内部结构覆盖。 */
@reference "../../styles/styles.css";
/* 任务卡片取消二次内缩,与快照、校验详情及设置卡片边缘对齐。 */
.workspace-tools-body .breakdown-execution-panel {
padding: 0;
}
.group-preview {
@apply mt-6 pt-5;
}
.group-chip {
@apply flex items-center gap-2.5 bg-(--app-subtle) rounded-none py-2 px-[11px] text-[11px];
}
.recovery-strip {
@apply bg-(--app-subtle) flex justify-between flex-wrap items-center gap-[15px] p-[17px] rounded-none;
}
.breakdown-settings-panel {
container: breakdown-settings / inline-size;
}
/* 说明与表单留出 16px,避免移除来源标签后紧贴首个字段。 */
.breakdown-settings-form {
margin-top: 16px;
}
.breakdown-config {
@apply grid grid-cols-[180px_minmax(0,_1fr)_auto] items-start gap-y-4 gap-x-6;
--breakdown-label-offset: 29px;
}
.breakdown-group-field,
.breakdown-modules-field,
.breakdown-module-option {
@apply min-w-0;
}
.breakdown-group-input {
@apply w-full flex items-center gap-3;
}
.breakdown-group-number.n-input-number {
@apply flex-[0_0_120px] w-[120px];
}
.breakdown-group-unit {
@apply shrink-0 whitespace-nowrap text-muted text-sm;
}
.breakdown-modules-field {
@apply m-0 p-0 border-0;
}
.breakdown-module-options {
/* 模块内部收紧为 8px,说明到字段和字段之间仍保持 16px 的层级间距。 */
@apply w-full grid grid-cols-[repeat(3,_minmax(0,_1fr))] gap-y-2 gap-x-4;
}
.breakdown-module-description {
@apply mt-1 mx-0 mb-0 pl-6 text-muted text-[11px] leading-[18px] wrap-anywhere;
}
.breakdown-preview-button.n-button {
@apply self-start mt-[var(--breakdown-label-offset)] whitespace-nowrap;
}
@container breakdown-settings (max-width: 780px) {
.breakdown-config {
@apply grid-cols-[180px_minmax(0,_1fr)];
}
.breakdown-preview-button.n-button {
@apply col-[2] justify-self-end mt-0;
}
}
@container breakdown-settings (max-width: 560px) {
.breakdown-config {
@apply grid-cols-[minmax(0,_1fr)];
}
.breakdown-module-options {
@apply grid-cols-[repeat(auto-fit,_minmax(min(100%,_160px),_1fr))];
}
.breakdown-preview-button.n-button {
@apply col-[1];
}
}
.result-toolbar .n-tabs-tab__label {
@apply inline-flex gap-1.5;
}
.breakdown-results-section {
@apply flex flex-col flex-1 min-h-0 min-w-0;
/* 提示到导航、导航到搜索、搜索到列表共用同一个模块间距。 */
gap: var(--app-content-gap);
}
.breakdown-results-section > .result-toolbar {
@apply shrink-0;
}
.breakdown-results-section > .breakdown-content {
/* 移除执行记录分栏,结果独占剩余宽高。 */
@apply grid flex-1 h-auto min-h-0 grid-cols-[minmax(0,_1fr)] grid-rows-[minmax(0,_1fr)];
/* 外层透明,搜索框和各条目使用自身背景,模块间距不再铺底色。 */
background: transparent;
}
.breakdown-results-scroll .n-scrollbar-content {
@apply wrap-anywhere;
}
.breakdown-result-pad {
/* 条目保留自身背景和内边距,外层不再重复缩进搜索和结果。 */
@apply p-0;
}
.breakdown-result-pad .subject-list-toolbar {
margin-bottom: var(--app-content-gap);
}
.breakdown-workspace-page .workspace-tabs .n-tabs-nav__suffix,
.breakdown-workspace-page .breakdown-toolbar-actions {
/* 设置与导出入口共用标签栏高度,导出按钮保持正方形。 */
align-items: stretch;
}
.breakdown-workspace-page .breakdown-toolbar-actions {
gap: 0;
}
.breakdown-workspace-page .breakdown-mobile-tools.n-button {
display: none;
}
.breakdown-task-label-mobile {
display: none;
}
@media (max-width: 760px) {
/* 手机隐藏整行统计和旧设置入口,设置功能移到分类导航右侧。 */
.breakdown-workspace-page .workspace-heading-scroll.n-scrollbar {
display: none;
}
.breakdown-task-label-desktop {
display: none;
}
.breakdown-task-label-mobile {
display: inline;
}
/* 缩短标签文字并收紧间距,让手机分类与设置图标完整显示在同一行。 */
.breakdown-workspace-page .workspace-tabs.n-tabs .n-tabs-nav .n-tabs-tab {
padding-inline: 8px;
}
.breakdown-workspace-page .breakdown-mobile-tools.n-button {
display: inline-flex;
width: 44px;
min-width: 44px;
height: 44px;
padding: 0;
}
/* 分类导航与设置共用完整吸顶背景,正文不会从导航区域透出。 */
.breakdown-workspace-page .breakdown-results-section > .result-toolbar {
position: sticky;
top: 0;
z-index: 19;
background: var(--app-body);
}
/* 正文交给项目内容区滚动,绿色提示随页面位置自然移出,不做透明度收起。 */
.breakdown-workspace-page .breakdown-results-section {
flex: none;
overflow: visible;
}
.breakdown-workspace-page .breakdown-content,
.breakdown-workspace-page .breakdown-content > main,
.breakdown-workspace-page .breakdown-results-scroll,
.breakdown-workspace-page .breakdown-results-scroll > .n-scrollbar-container {
height: auto;
max-height: none;
overflow: visible;
}
}
@media (max-width: 800px) {
.breakdown-workspace-page .workspace-toolbar {
@apply min-h-0 flex-nowrap gap-2;
}
.breakdown-workspace-page .workspace-toolbar h2 {
@apply hidden;
}
.breakdown-workspace-page .toolbar-summary {
@apply min-w-0 flex-1 flex-nowrap overflow-x-auto overflow-y-hidden overscroll-x-contain;
scrollbar-width: none;
mask-image: linear-gradient(to right, #000 calc(100% - 12px), transparent);
}
.breakdown-workspace-page .toolbar-summary::-webkit-scrollbar {
display: none;
}
.breakdown-workspace-page .toolbar-summary > * {
@apply shrink-0;
}
.breakdown-workspace-page .toolbar-actions {
@apply ml-0 shrink-0;
}
.breakdown-workspace-page .toolbar-actions > * {
@apply shrink-0;
}
.breakdown-workspace-page .workspace-tools-label {
@apply hidden;
}
.breakdown-workspace-page .workspace-tools-trigger {
@apply h-8 w-8 p-0;
min-width: 32px;
}
.breakdown-workspace-page .workspace-tools-trigger .n-button__icon {
@apply m-0;
}
.breakdown-results-section .tabs-toolbar {
container-type: normal;
}
.breakdown-results-section .workspace-tabs > .n-tabs-nav {
@apply flex-nowrap;
}
.breakdown-results-section .workspace-tabs .n-tabs-nav-scroll-wrapper {
@apply min-w-0 flex-1;
flex-basis: auto;
}
.breakdown-results-section .workspace-tabs .n-tabs-nav__suffix {
@apply w-auto pl-2;
}
.breakdown-results-section .tabs-toolbar-actions {
@apply min-h-0 flex-nowrap;
}
}
</style>