feat(short-drama-agent-front): 新增诊断抽屉并优化项目弹窗

This commit is contained in:
GJ committed 2026-10-16 13:58:01 +08:00
1 parent 97dc784c8b
commit 49ad08a63e
21 files changed
+1479 -363

No files matched your search

+7 -1
View File
@@ -90,10 +90,11 @@ onBeforeUnmount(() => {
:close-on-esc="!busy"
:style="{ width: `${width ?? (wide ? 1040 : 600)}px` }"
class="app-dialog"
:class="{ 'app-dialog-title-only': !description && !$slots.description }"
role="dialog"
:aria-label="title"
>
<!-- 以下是固定标题与说明模块,说明位于标题下并可自定义 -->
<!-- 以下是固定标题与说明模块,无说明时标题与关闭按钮垂直居中对齐 -->
<template #header>
<div class="min-w-0">
<div class="text-lg font-semibold">{{ title }}</div>
@@ -130,6 +131,11 @@ onBeforeUnmount(() => {
.app-dialog .n-card-header {
@apply shrink-0 items-start;
}
/* 无描述的标题栏采用同一条中心线,标题下方保持紧凑的正文间距。 */
.app-dialog.app-dialog-title-only .n-card-header {
align-items: center;
padding-bottom: 16px;
}
/* 正文自然撑开,超过剩余视口高度后由 NScrollbar 内部滚动。 */
.app-dialog .n-card-content {
@apply min-h-0 overflow-hidden;
+49 -227
View File
@@ -13,7 +13,7 @@ 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 type { BreakdownAction, BreakdownInput, BreakdownModule, BreakdownPreview } from './types'
import { breakdownSnapshot, recoveryOptions, workflowCheckpoints } from '../workflows/selectors'
import { getOperation, isOperationRunning, runOperation } from '../workflows/operations'
import ConfirmAction from '../workflows/ConfirmAction.vue'
@@ -21,6 +21,8 @@ import WorkflowExecutionPanel from '../workflows/WorkflowExecutionPanel.vue'
import { useWorkflowExecution } from '../workflows/execution'
import SubjectList from './components/SubjectList.vue'
import StoryboardList from './components/StoryboardList.vue'
import StoryboardDiagnosis from './components/StoryboardDiagnosis.vue'
import type { DiagnosisLocation } from './diagnosis'
import { errorMessage } from '../../lib/http'
import { downloadText, nodeLabel } from '../../lib/format'
@@ -32,42 +34,6 @@ const preview = ref<BreakdownPreview | null>(null)
const previewBusy = ref(false)
const tab = ref('character')
const toolsOpen = ref(false)
/** 分镜诊断与拆解设置解耦,默认不占用列表空间。 */
const qualityPanelOpen = 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 && qualityPanelOpen.value && projectId.value === id) handRepairPreview.value = data
} catch (cause) {
if (version === handDiagnosticsVersion && qualityPanelOpen.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 && qualityPanelOpen.value && projectId.value === id) handDiagnostics.value = data
} catch (cause) {
if (version === handDiagnosticsVersion && qualityPanelOpen.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: '故事空间与环境特征' },
@@ -84,101 +50,37 @@ 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([qualityPanelOpen, projectId], () => {
++handDiagnosticsVersion
handDiagnostics.value = null
handDiagnosticsBusy.value = false
handRepairPreview.value = null
handRepairBusy.value = false
++legacyResultsRequest
legacyResultsBusy.value = false
legacyResults.value = null
/** 分镜阅读和诊断入口共用当前剧集,不维护独立的诊断集号输入。 */
const selectedEpisodeNo = ref<number>()
/** 按正式规划回退到首集,与分镜列表的默认选中保持一致。 */
const currentEpisodeNo = computed(() => {
const available = plans.value.length ? plans.value : shots.value.map(item => item.episodePlan)
return (available.find(item => item.episodeNo === selectedEpisodeNo.value) ?? available[0])?.episodeNo
})
/** 历史镜头 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' | 'beat' | 'shot'>('episode')
const legacyBeatNo = ref<number>()
const legacyShotNo = ref<number>()
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 === 'project' ? undefined : legacyEpisodeNo.value
legacyResultsBusy.value = true
try {
const data = await breakdownApi.legacyActionDiagnosisResults(id, episode)
if (requestVersion === legacyResultsRequest && version === handDiagnosticsVersion && projectId.value === id && qualityPanelOpen.value) legacyResults.value = data
} catch (cause) {
if (requestVersion === legacyResultsRequest && version === handDiagnosticsVersion && projectId.value === id && qualityPanelOpen.value) actionMessage?.error(errorMessage(cause))
} finally {
if (requestVersion === legacyResultsRequest) legacyResultsBusy.value = false
}
/** 项目预览涵盖正式剧集与已有分镜剧集,不遗漏已有分镜。 */
const diagnosisEpisodeNos = computed(() => [
...new Set([
...(project.value?.episodes.map(item => item.episode) ?? []),
...shots.value.map(item => item.episodeNo)
])
])
/** 分镜列表仅暴露定位方法。 */
const storyboardList = ref<InstanceType<typeof StoryboardList> | null>(null)
/** 诊断组件仅暴露按范围打开方法。 */
const diagnosisPanel = ref<InstanceType<typeof StoryboardDiagnosis> | null>(null)
/**
* 从分镜卡片直接打开对应的节拍或镜头诊断。
* @param location 当前分镜坐标
*/
function openShotDiagnosis(location: DiagnosisLocation) {
diagnosisPanel.value?.open(location)
}
watch(() => legacyDiagnosisExecution.query.data.value?.status, (status, previous) => {
if (status && status !== previous && (status === 'completed' || status === 'failed') && qualityPanelOpen.value) {
void loadLegacyResults()
}
})
watch([legacyEpisodeNo, legacyBeatNo, legacyShotNo, 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,
legacyDiagnosisScope.value === 'beat' || legacyDiagnosisScope.value === 'shot' ? legacyBeatNo.value : undefined,
legacyDiagnosisScope.value === 'shot' ? legacyShotNo.value : undefined)
if (version === handDiagnosticsVersion && projectId.value === id && qualityPanelOpen.value) legacyPreview.value = data
} catch (cause) {
if (version === handDiagnosticsVersion && projectId.value === id && qualityPanelOpen.value) actionMessage?.error(errorMessage(cause))
} finally {
if (version === handDiagnosticsVersion) legacyPreviewBusy.value = false
}
}
/** 从 Beat / Shot 悬停入口定位诊断范围,并复用统一费用确认。 */
async function openLegacyShotDiagnosis(scope: { episodeNo: number; beatNo: number; shotNo?: number }) {
legacyEpisodeNo.value = scope.episodeNo
legacyBeatNo.value = scope.beatNo
legacyShotNo.value = scope.shotNo
legacyDiagnosisScope.value = scope.shotNo === undefined ? 'beat' : 'shot'
tab.value = 'storyboard'
qualityPanelOpen.value = true
await loadLegacyPreview()
}
async function startLegacyDiagnosis() {
const id = projectId.value
legacyStarting.value = true
try {
const diagnosisTask = await breakdownApi.startLegacyActionDiagnosis(id, {
confirmed: true,
...(legacyDiagnosisScope.value !== 'project' ? { episodeNo: legacyEpisodeNo.value } : {}),
...(legacyDiagnosisScope.value === 'beat' || legacyDiagnosisScope.value === 'shot' ? { beatNo: legacyBeatNo.value } : {}),
...(legacyDiagnosisScope.value === 'shot' ? { shotNo: legacyShotNo.value } : {}),
concurrency: legacyConcurrency.value
})
await legacyDiagnosisExecution.track(diagnosisTask.executionId, id)
} catch (cause) {
actionMessage?.error(errorMessage(cause))
} finally {
legacyStarting.value = false
}
/**
* 诊断问题定位到分镜正文,必要时切换到对应剧集。
* @param location 待定位的分镜坐标
*/
function locateDiagnosisShot(location: DiagnosisLocation) {
void storyboardList.value?.locate(location)
}
const backgroundExecution = useWorkflowExecution(projectId, 'breakdown')
const recovery = computed(() => recoveryOptions(checkpoints.value))
@@ -684,103 +586,23 @@ const rules = {
/></div
></template>
<div v-if="tab === 'storyboard'" class="breakdown-result-pad">
<div class="mb-3 flex justify-end">
<NButton text @click="qualityPanelOpen = !qualityPanelOpen">{{ qualityPanelOpen ? '收起质量诊断' : '分镜质量诊断' }}</NButton>
</div>
<div v-if="qualityPanelOpen" class="mb-5 space-y-3">
<div class="text-sm font-medium">分镜质量诊断</div>
<!-- 手部动作诊断按需读取,历史镜头缺少证据时不误报为安全。 -->
<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>
<span v-if="legacyDiagnosisScope === 'beat' || legacyDiagnosisScope === 'shot'" class="text-xs text-muted">Beat {{ legacyBeatNo }}{{ legacyDiagnosisScope === 'shot' ? ` / Shot ${legacyShotNo}` : '' }}</span>
<NInputNumber v-if="legacyDiagnosisScope !== 'project'" 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 !== 'project' && !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>
</div>
<StoryboardList :plans="plans" :episodes="shots" @diagnose="openLegacyShotDiagnosis">
<StoryboardList
ref="storyboardList"
v-model:episode-no="selectedEpisodeNo"
:plans="plans"
:episodes="shots"
@diagnose="openShotDiagnosis"
>
<!-- 以下是跟随当前剧集的一行诊断摘要,抽屉独立于列表滚动 -->
<template #diagnosis>
<StoryboardDiagnosis
ref="diagnosisPanel"
:project-id="projectId"
:episode-no="currentEpisodeNo"
:episode-nos="diagnosisEpisodeNos"
@locate="locateDiagnosisShot"
/>
</template>
<template #actions>
<RouterLink :to="`/projects/${project?.id}/storyboard`" class="text-button"
>进入分镜设计<ArrowRight :size="14"
+44 -16
View File
@@ -1,5 +1,16 @@
import { optionalResource, request } from '../../lib/http'
import type { BreakdownAction, BreakdownInput, BreakdownPreview, BreakdownState, StoryboardHandOccupancyDiagnostics, StoryboardHandRepairPreview, StoryboardHandRepairHistory, LegacyActionDiagnosisPreview, LegacyActionDiagnosisBatchStart, LegacyActionDiagnosisResults } from './types'
import type {
BreakdownAction,
BreakdownInput,
BreakdownPreview,
BreakdownState,
StoryboardHandOccupancyDiagnostics,
StoryboardHandRepairPreview,
StoryboardHandRepairHistory,
LegacyActionDiagnosisPreview,
LegacyActionDiagnosisBatchStart,
LegacyActionDiagnosisResults
} from './types'
import type { WorkflowExecutionStart } from '../workflows/execution.types'
/** Breakdown API;预览为 GET,启动和恢复为等待完成的长 POST。 */
@@ -9,30 +20,47 @@ export const breakdownApi = {
return request<BreakdownPreview>(`/projects/${encodeURIComponent(id)}/breakdown-preview?${query}`, { signal })
},
handOccupancyDiagnostics: (id: string, signal?: AbortSignal) =>
request<StoryboardHandOccupancyDiagnostics>(`/projects/${encodeURIComponent(id)}/breakdown/storyboard-hand-occupancy-diagnostics`, { signal }),
request<StoryboardHandOccupancyDiagnostics>(
`/projects/${encodeURIComponent(id)}/breakdown/storyboard-hand-occupancy-diagnostics`,
{ signal }
),
handRepairPreview: (id: string, signal?: AbortSignal) =>
request<StoryboardHandRepairPreview>(`/projects/${encodeURIComponent(id)}/breakdown/storyboard-hand-occupancy-repair-preview`, { signal }),
request<StoryboardHandRepairPreview>(
`/projects/${encodeURIComponent(id)}/breakdown/storyboard-hand-occupancy-repair-preview`,
{ signal }
),
handRepairHistory: (id: string, shotId: string, signal?: AbortSignal) =>
request<StoryboardHandRepairHistory>(`/projects/${encodeURIComponent(id)}/breakdown/storyboard-hand-occupancy-repair-history/${encodeURIComponent(shotId)}`, { signal }),
request<StoryboardHandRepairHistory>(
`/projects/${encodeURIComponent(id)}/breakdown/storyboard-hand-occupancy-repair-history/${encodeURIComponent(shotId)}`,
{ signal }
),
legacyActionDiagnosisPreview: (id: string, episodeNo: number, beatNo?: number, shotNo?: number) => {
const query = new URLSearchParams({ episodeNo: String(episodeNo) })
if (beatNo !== undefined) query.set('beatNo', String(beatNo))
if (shotNo !== undefined) query.set('shotNo', String(shotNo))
return request<LegacyActionDiagnosisPreview>(`/projects/${encodeURIComponent(id)}/breakdown/storyboard-legacy-action-diagnosis-preview?${query}`)
return request<LegacyActionDiagnosisPreview>(
`/projects/${encodeURIComponent(id)}/breakdown/storyboard-legacy-action-diagnosis-preview?${query}`
)
},
startLegacyActionDiagnosis: (id: string, input: {
episodeNo?: number
beatNo?: number
shotNo?: number
concurrency: number
confirmed: true
}) => request<LegacyActionDiagnosisBatchStart>(
`/projects/${encodeURIComponent(id)}/breakdown/storyboard-legacy-action-diagnose-batch`,
{ method: 'POST', body: input }
),
startLegacyActionDiagnosis: (
id: string,
input: {
episodeNo?: number
beatNo?: number
shotNo?: number
concurrency: number
confirmed: true
}
) =>
request<LegacyActionDiagnosisBatchStart>(
`/projects/${encodeURIComponent(id)}/breakdown/storyboard-legacy-action-diagnose-batch`,
{ method: 'POST', body: input }
),
legacyActionDiagnosisResults: (id: string, episodeNo?: number) => {
const query = episodeNo === undefined ? '' : `?episodeNo=${episodeNo}`
return request<LegacyActionDiagnosisResults>(`/projects/${encodeURIComponent(id)}/breakdown/storyboard-legacy-action-diagnosis-results${query}`)
return request<LegacyActionDiagnosisResults>(
`/projects/${encodeURIComponent(id)}/breakdown/storyboard-legacy-action-diagnosis-results${query}`
)
},
latest: (id: string, signal?: AbortSignal) =>
optionalResource(request<BreakdownState>(`/projects/${encodeURIComponent(id)}/breakdown/latest`, { signal })),
@@ -0,0 +1,766 @@
<script setup lang="ts">
import { computed, onScopeDispose, ref, watch } from 'vue'
import {
NButton,
NCollapse,
NCollapseItem,
NDrawer,
NDrawerContent,
NInputNumber,
NScrollbar,
NSelect,
NTag
} from 'naive-ui'
import { ScanLine } from '@lucide/vue'
import { breakdownApi } from '../api'
import { diagnosisInput, diagnosisStatusLabels, scopeDiagnosisShots, summarizeDiagnosis } from '../diagnosis'
import type { DiagnosisLocation, DiagnosisScope } from '../diagnosis'
import type {
LegacyActionDiagnosisPreview,
LegacyActionDiagnosisResults,
StoryboardHandOccupancyDiagnostics,
StoryboardHandRepairPreview
} from '../types'
import ConfirmAction from '../../workflows/ConfirmAction.vue'
import WorkflowExecutionPanel from '../../workflows/WorkflowExecutionPanel.vue'
import { useWorkflowExecution } from '../../workflows/execution'
import { useActionMessage } from '../../../components/ui/useActionMessage'
import { errorMessage } from '../../../lib/http'
/** 当前分镜上下文;诊断入口与列表共用同一个正式剧集。 */
const props = defineProps<{
/** 正式项目编号。 */
projectId: string
/** 当前阅读的剧集编号。 */
episodeNo?: number
/** 全项目预览所需的正式剧集编号。 */
episodeNos: number[]
}>()
/** 关闭抽屉后定位对应镜头或节拍。 */
const emit = defineEmits<{ locate: [location: DiagnosisLocation] }>()
/** 统一操作消息层。 */
const message = useActionMessage()
/** 任务观察独立于抽屉显隐,关闭抽屉后继续跟踪真实进度。 */
const execution = useWorkflowExecution(
computed(() => props.projectId),
'storyboard-legacy-action-diagnosis'
)
/** 右侧诊断抽屉是否展开。 */
const drawerOpen = ref(false)
/** 等待抽屉离场后再转移焦点,避免焦点陷阱把定位焦点拉回。 */
const pendingLocation = ref<DiagnosisLocation | null>(null)
/** 本次查看及提交的诊断范围。 */
const scope = ref<DiagnosisScope>({ kind: 'project' })
/** 当前集摘要与抽屉结果分开保存,切换抽屉范围不会改变摘要含义。 */
const episodeResults = ref<LegacyActionDiagnosisResults | null>(null)
/** 当前集摘要的读取状态。 */
const summaryBusy = ref(false)
/** 当前集摘要的读取错误。 */
const summaryError = ref('')
/** 抽屉范围对应的后端结果,节拍及镜头会再次筛选。 */
const results = ref<LegacyActionDiagnosisResults | null>(null)
/** 抽屉结果读取状态。 */
const resultsBusy = ref(false)
/** 抽屉结果读取错误。 */
const resultsError = ref('')
/** 只读范围预览;全项目按正式剧集汇总,任何一集失败都不能启动。 */
const previews = ref<LegacyActionDiagnosisPreview[] | null>(null)
/** 只读范围预览的读取状态。 */
const previewBusy = ref(false)
/** 范围预览的读取错误。 */
const previewError = ref('')
/** 模型任务并发数,默认值沿用原有能力。 */
const concurrency = ref(3)
/** 批量任务的启动状态。 */
const starting = ref(false)
/** 结果列表默认聚焦冲突、异常和过期,未诊断记录按需查看。 */
const resultFilter = ref<'attention' | 'pending' | 'all'>('attention')
/** 项目级结构化动作证据校验,明确区别于当前集 AI 诊断。 */
const handDiagnostics = ref<StoryboardHandOccupancyDiagnostics | null>(null)
/** 项目级校验的读取状态。 */
const handBusy = ref(false)
/** 项目级校验的读取错误。 */
const handError = ref('')
/** 当前主动展开修复建议的问题序号。 */
const repairIssue = ref<number | null>(null)
/** 只读修复建议,不提供自动写入操作。 */
const repairPreview = ref<StoryboardHandRepairPreview | null>(null)
/** 修复建议读取状态。 */
const repairBusy = ref(false)
/** 请求版本用于忽略范围变化、关闭抽屉及组件卸载后的迟到响应。 */
let summaryVersion = 0
/** 当前范围结果请求版本。 */
let resultsVersion = 0
/** 当前范围预览请求版本。 */
let previewVersion = 0
/** 项目级校验和修复建议的请求版本。 */
let handVersion = 0
/** 当前查看范围的中文名称,同时用于费用确认。 */
const scopeLabel = computed(() => {
const target = scope.value
if (target.kind === 'project') return '全项目'
const episode = `第 ${target.episodeNo} 集`
if (target.kind === 'episode') return episode
return `${episode} / 节拍 ${target.beatNo}${target.kind === 'shot' ? ` / 镜头 ${target.shotNo}` : ''}`
})
/** 当前范围的稳定标识,范围切换立即使旧预览失效。 */
const scopeKey = computed(() => JSON.stringify(scope.value))
/** 当前集摘要根据真实诊断记录统计。 */
const summaryCounts = computed(() => (episodeResults.value ? summarizeDiagnosis(episodeResults.value.shots) : null))
/** 抽屉统计严格对应当前集、节拍或镜头范围。 */
const scopedShots = computed(() => scopeDiagnosisShots(results.value?.shots ?? [], scope.value))
/** 当前范围的状态计数。 */
const counts = computed(() => summarizeDiagnosis(scopedShots.value))
/** 按状态筛选的结果记录。 */
const visibleShots = computed(() =>
scopedShots.value.filter(
shot =>
resultFilter.value === 'all' ||
(resultFilter.value === 'pending'
? shot.status === 'not_diagnosed'
: !['not_diagnosed', 'no_conflict_found'].includes(shot.status))
)
)
/** 预览展示范围内的实际镜头总数,不把待补证据数量冒充付费数量。 */
const previewCount = computed(() => previews.value?.reduce((sum, item) => sum + item.candidateCount, 0) ?? 0)
/** 并发参数限制与后端请求契约一致。 */
const concurrencyValid = computed(
() => Number.isSafeInteger(concurrency.value) && concurrency.value >= 1 && concurrency.value <= 5
)
/** 启动前必须取得当前范围预览,并保证没有同项目同工作流活动任务。 */
const canStart = computed(
() =>
!!previews.value &&
previewCount.value > 0 &&
concurrencyValid.value &&
!previewBusy.value &&
!execution.active.value &&
!starting.value
)
/** 费用确认使用当前预览范围及并发,不虚构模型价格。 */
const confirmation = computed(
() =>
`${scopeLabel.value},范围内共 ${previewCount.value} 个镜头,并发 ${concurrency.value}。会产生模型费用,已有当前版本有效诊断的镜头将跳过;仅保存诊断记录,不修改镜头。`
)
/** 顶部只显示当前集覆盖情况,未取得结果时不推断为安全或未诊断。 */
const summaryText = computed(() => {
const value = summaryCounts.value
if (!props.episodeNo) return '尚无可诊断的剧集'
if (summaryBusy.value) return '正在读取诊断记录…'
if (summaryError.value) return '诊断记录读取失败'
if (!value) return '尚未读取诊断记录'
if (!value.total) return '本集尚无可诊断镜头'
if (value.pending === value.total) return `${value.total} 个镜头尚未诊断`
return `共 ${value.total} 镜 · 已发现冲突 ${value.conflict} · 待诊断 ${value.pending} · 证据不足/无效 ${value.insufficient + value.invalid} · 已过期 ${value.stale} · 未发现冲突 ${value.clear}`
})
/** 读取当前集摘要,切换剧集后丢弃旧结果,不增加后台轮询。 */
async function loadSummary() {
const id = props.projectId
const episodeNo = props.episodeNo
const version = ++summaryVersion
episodeResults.value = null
summaryError.value = ''
summaryBusy.value = !!id && episodeNo !== undefined
if (!id || episodeNo === undefined) return
try {
const data = await breakdownApi.legacyActionDiagnosisResults(id, episodeNo)
if (version === summaryVersion) episodeResults.value = data
} catch (cause) {
if (version === summaryVersion) summaryError.value = errorMessage(cause)
} finally {
if (version === summaryVersion) summaryBusy.value = false
}
}
/**
* 读取当前抽屉范围结果;同集结果同时更新顶部摘要。
* @returns 当前结果读取结束
*/
async function loadResults() {
const id = props.projectId
const target = scope.value
const version = ++resultsVersion
resultsBusy.value = true
resultsError.value = ''
try {
const data = await breakdownApi.legacyActionDiagnosisResults(
id,
target.kind === 'project' ? undefined : target.episodeNo
)
if (version !== resultsVersion) return
results.value = data
if (target.kind !== 'project' && target.episodeNo === props.episodeNo) {
++summaryVersion
summaryBusy.value = false
summaryError.value = ''
episodeResults.value = data
}
} catch (cause) {
if (version === resultsVersion) resultsError.value = errorMessage(cause)
} finally {
if (version === resultsVersion) resultsBusy.value = false
}
}
/** 只读预览当前范围,全项目依照后端单集预览接口逐集汇总。 */
async function loadPreview() {
const id = props.projectId
const target = scope.value
const version = ++previewVersion
previews.value = null
previewBusy.value = true
previewError.value = ''
try {
const episodes = target.kind === 'project' ? [...new Set(props.episodeNos)] : [target.episodeNo]
if (!episodes.length) throw new Error('尚无可预览的剧集')
const data = await Promise.all(
episodes.map(episode =>
breakdownApi.legacyActionDiagnosisPreview(
id,
episode,
target.kind === 'beat' || target.kind === 'shot' ? target.beatNo : undefined,
target.kind === 'shot' ? target.shotNo : undefined
)
)
)
if (version === previewVersion) previews.value = data
} catch (cause) {
if (version === previewVersion) previewError.value = errorMessage(cause)
} finally {
if (version === previewVersion) previewBusy.value = false
}
}
/** 读取全项目结构化证据;证据不足时不以零冲突暗示安全。 */
async function loadHandDiagnostics() {
const version = ++handVersion
handBusy.value = true
handError.value = ''
handDiagnostics.value = null
repairPreview.value = null
repairIssue.value = null
repairBusy.value = false
try {
const data = await breakdownApi.handOccupancyDiagnostics(props.projectId)
if (version === handVersion) handDiagnostics.value = data
} catch (cause) {
if (version === handVersion) handError.value = errorMessage(cause)
} finally {
if (version === handVersion) handBusy.value = false
}
}
/**
* 将只读修复候选放在对应问题下方,避免脱离问题单独罗列。
* @param index 用户展开的问题序号
* @returns 修复建议读取结束
*/
async function showRepair(index: number) {
repairIssue.value = repairIssue.value === index ? null : index
if (repairIssue.value === null || repairPreview.value || repairBusy.value) return
const version = handVersion
repairBusy.value = true
try {
const data = await breakdownApi.handRepairPreview(props.projectId)
if (version === handVersion) repairPreview.value = data
} catch (cause) {
if (version === handVersion) message?.error(errorMessage(cause))
} finally {
if (version === handVersion) repairBusy.value = false
}
}
/**
* 筛选与当前结构化冲突相同镜头、阶段和角色的修复建议。
* @param issue 当前结构化冲突
* @returns 对应的人工修复候选
*/
function repairsFor(issue: StoryboardHandOccupancyDiagnostics['diagnostics'][number]) {
return (
repairPreview.value?.candidates.filter(
item =>
item.episodeNo === issue.episodeNo &&
item.beatNo === issue.beatNo &&
item.shotNo === issue.shotNo &&
item.phaseNo === issue.phaseNo &&
item.characterRef === issue.characterRef
) ?? []
)
}
/**
* 仅展示后端问题中明确提供的建议文本,不推断未知结构。
* @param issues 后端诊断问题记录
* @returns 可读的问题建议
*/
function issueDescriptions(issues: unknown[]) {
return issues.flatMap(issue =>
issue && typeof issue === 'object' && 'suggestion' in issue && typeof issue.suggestion === 'string'
? [issue.suggestion]
: []
)
}
/**
* 从顶部或镜头入口打开抽屉;指定镜头时自动取得只读范围预览。
* @param location 可选的节拍或镜头坐标
*/
function open(location?: DiagnosisLocation) {
pendingLocation.value = null
scope.value = location
? location.shotNo === undefined
? { kind: 'beat', episodeNo: location.episodeNo, beatNo: location.beatNo }
: { kind: 'shot', ...location, shotNo: location.shotNo }
: props.episodeNo === undefined
? { kind: 'project' }
: { kind: 'episode', episodeNo: props.episodeNo }
drawerOpen.value = true
if (location) void loadPreview()
}
/**
* 关闭抽屉后通知列表定位,保留当前任务观察。
* @param location 待定位的镜头或节拍
*/
function locate(location: DiagnosisLocation) {
pendingLocation.value = location
drawerOpen.value = false
}
/** 抽屉关闭动画结束后定位镜头,键盘焦点与正文高亮保持一致。 */
function finishLocate() {
if (!pendingLocation.value) return
const location = pendingLocation.value
pendingLocation.value = null
emit('locate', location)
}
/** 费用确认后提交固定范围,并保存后台任务句柄。 */
async function startDiagnosis() {
if (!canStart.value) return
const id = props.projectId
const input = diagnosisInput(scope.value, concurrency.value)
starting.value = true
try {
const task = await breakdownApi.startLegacyActionDiagnosis(id, input)
await execution.track(task.executionId, id)
} catch (cause) {
message?.error(errorMessage(cause))
} finally {
starting.value = false
}
}
/** 切换项目或当前剧集时清除旧范围,摘要读取只随上下文变化执行。 */
watch(
[() => props.projectId, () => props.episodeNo],
() => {
pendingLocation.value = null
drawerOpen.value = false
++handVersion
handDiagnostics.value = null
handBusy.value = false
handError.value = ''
void loadSummary()
},
{ immediate: true, flush: 'sync' }
)
/** 关闭或切换范围立即废弃预览及结果请求,禁止确认旧预览。 */
watch(
[drawerOpen, scopeKey],
([shown]) => {
++previewVersion
++resultsVersion
previews.value = null
previewBusy.value = false
previewError.value = ''
results.value = null
resultsBusy.value = false
resultsError.value = ''
resultFilter.value = 'attention'
if (shown) {
void loadResults()
if (!handDiagnostics.value && !handBusy.value) void loadHandDiagnostics()
} else {
++handVersion
handBusy.value = false
repairBusy.value = false
}
},
{ flush: 'sync' }
)
/** 后台任务结束后更新摘要和已打开的结果,不因关闭抽屉停止跟踪。 */
watch(
() => execution.query.data.value?.status,
(status, previous) => {
if (status !== previous && (status === 'completed' || status === 'failed')) {
void loadSummary()
if (drawerOpen.value) void loadResults()
}
}
)
/** 离开分镜页面后所有在途只读响应失效。 */
onScopeDispose(() => {
++summaryVersion
++resultsVersion
++previewVersion
++handVersion
})
/** 镜头入口只需要打开指定范围,不暴露组件内部状态。 */
defineExpose({ open })
</script>
<template>
<!-- 以下是紧凑的当前集诊断摘要模块,完整结果不挤占分镜正文 -->
<div class="storyboard-diagnosis-summary" aria-live="polite">
<div class="diagnosis-summary-text">
<ScanLine :size="16" aria-hidden="true" />
<span class="font-medium">动作诊断</span>
<span class="text-muted"
>{{ episodeNo === undefined ? '当前集' : `第 ${episodeNo} 集` }} · {{ summaryText }}</span
>
<NTag v-if="execution.active.value" type="info" size="small" :bordered="false">诊断中</NTag>
</div>
<NButton text :disabled="!projectId" aria-haspopup="dialog" :aria-expanded="drawerOpen" @click="open()"
>查看诊断</NButton
>
</div>
<!-- 以下是独立滚动的右侧诊断抽屉模块,手机自动使用全屏宽度 -->
<NDrawer
v-model:show="drawerOpen"
placement="right"
width="min(560px, 100vw)"
class="storyboard-diagnosis-drawer"
@after-leave="finishLocate"
>
<NDrawerContent title="动作诊断" closable :native-scrollbar="false">
<p class="diagnosis-intro">检查手部动作占用与冲突,帮助定位需要处理的镜头。</p>
<!-- 以下是当前范围模块,剧集编号始终与阅读列表一致 -->
<section class="diagnosis-section">
<h3>诊断范围</h3>
<div class="diagnosis-scope-controls">
<NButton
size="small"
:disabled="episodeNo === undefined"
:type="scope.kind !== 'project' ? 'primary' : 'default'"
@click="scope = { kind: 'episode', episodeNo: episodeNo! }"
>当前集</NButton
>
<NButton
size="small"
:type="scope.kind === 'project' ? 'primary' : 'default'"
@click="scope = { kind: 'project' }"
>全项目</NButton
>
</div>
<p class="diagnosis-scope-label">{{ scopeLabel }}</p>
<p class="text-xs text-muted">当前支持手部动作冲突检查。</p>
</section>
<!-- 以下是诊断结果模块,默认隐藏未诊断长列表 -->
<section class="diagnosis-section">
<div class="diagnosis-section-heading">
<h3>诊断结果</h3>
<NButton text size="small" :loading="resultsBusy" @click="loadResults">刷新结果</NButton>
</div>
<p v-if="resultsError" class="text-danger" role="alert">{{ resultsError }}</p>
<template v-else-if="results">
<div class="diagnosis-counts">
<span>范围内 {{ counts.total }} 镜</span
><span :class="{ 'text-danger': counts.conflict }">冲突 {{ counts.conflict }}</span>
<span>证据不足 {{ counts.insufficient }}</span
><span>证据无效 {{ counts.invalid }}</span
><span>已过期 {{ counts.stale }}</span> <span>未诊断 {{ counts.pending }}</span
><span>未发现冲突 {{ counts.clear }}</span>
</div>
<NSelect
v-model:value="resultFilter"
aria-label="筛选诊断结果"
size="small"
class="diagnosis-result-filter"
:options="[
{ label: '需处理:冲突、证据异常与过期', value: 'attention' },
{ label: `未诊断(${counts.pending})`, value: 'pending' },
{ label: `全部镜头(${counts.total})`, value: 'all' }
]"
/>
<div v-if="!visibleShots.length" class="diagnosis-empty">
<p>
{{
counts.total === 0
? '当前范围尚无镜头。'
: counts.pending === counts.total
? `${counts.pending} 个镜头尚未诊断,暂无法判断冲突情况。`
: resultFilter === 'attention'
? '当前没有需处理的诊断记录。'
: '当前筛选下没有镜头。'
}}
</p>
<NButton
v-if="counts.pending && resultFilter !== 'pending'"
text
size="small"
@click="resultFilter = 'pending'"
>查看未诊断镜头</NButton
>
</div>
<NScrollbar
v-if="visibleShots.length"
class="diagnosis-result-list"
tabindex="0"
aria-label="镜头诊断列表"
>
<article v-for="item in visibleShots" :key="item.shotId" class="diagnosis-result-item">
<div class="diagnosis-section-heading">
<span class="text-xs text-muted"
>第 {{ item.episodeNo }} 集 / 节拍 {{ item.beatNo }} / 镜头 {{ item.shotNo }}</span
>
<NTag
:type="
item.status === 'conflict_found'
? 'error'
: item.status === 'no_conflict_found'
? 'success'
: 'default'
"
size="small"
:bordered="false"
>{{ diagnosisStatusLabels[item.status] }}</NTag
>
</div>
<p class="font-medium">{{ item.title }}</p>
<p
v-for="(description, index) in issueDescriptions(item.issues)"
:key="index"
class="text-muted"
>
{{ description }}
</p>
<NButton text size="small" @click="locate(item)">定位镜头</NButton>
</article>
</NScrollbar>
</template>
<p v-else class="text-muted">{{ resultsBusy ? '正在读取当前范围结果…' : '尚未读取结果' }}</p>
</section>
<!-- 以下是使用 Naive UI 折叠组件的全项目结构化校验模块,默认收起 -->
<section class="diagnosis-section">
<NCollapse>
<NCollapseItem name="hand-diagnostics">
<template #header>
<span class="diagnosis-evidence-title">结构化动作校验</span>
<span class="ml-2 text-xs text-muted">全项目</span>
</template>
<div class="diagnosis-section-heading">
<span class="text-xs text-muted">直接读取已有动作证据,不调用模型</span>
<NButton text size="small" :loading="handBusy" @click="loadHandDiagnostics"
>刷新校验</NButton
>
</div>
<p v-if="handError" class="text-danger" role="alert">{{ handError }}</p>
<template v-else-if="handDiagnostics">
<p class="mt-2">
有效动作证据 {{ handDiagnostics.evidenceShotCount }} /
{{ handDiagnostics.shotCount }} 镜
</p>
<p class="text-muted">
{{
handDiagnostics.assessment === 'no_shots'
? '全项目尚无镜头。'
: handDiagnostics.assessment === 'insufficient_evidence'
? '证据不足,暂无法判断冲突情况。'
: handDiagnostics.assessment === 'partial_evidence'
? `部分镜头缺少有效证据;现有证据发现 ${handDiagnostics.warningCount} 项冲突。`
: `现有证据发现 ${handDiagnostics.warningCount} 项冲突。`
}}
</p>
<article
v-for="(issue, index) in handDiagnostics.diagnostics"
:key="index"
class="diagnosis-result-item"
>
<p class="text-xs text-muted">
第 {{ issue.episodeNo }} 集 / 节拍 {{ issue.beatNo }} / 镜头 {{ issue.shotNo }} /
阶段
{{ issue.phaseNo }}
</p>
<p>{{ issue.suggestion }}</p>
<div class="diagnosis-scope-controls">
<NButton text size="small" @click="locate(issue)">定位镜头</NButton>
<NButton
text
size="small"
:loading="repairBusy && repairIssue === index"
@click="showRepair(index)"
>{{ repairIssue === index ? '收起修复建议' : '查看修复建议' }}</NButton
>
</div>
<div v-if="repairIssue === index && repairPreview" class="diagnosis-repair">
<div v-for="(repair, repairIndex) in repairsFor(issue)" :key="repairIndex">
<p>{{ repair.suggestion }}</p>
<p v-if="repair.blockingReasons.length" class="text-xs text-muted">
{{ repair.blockingReasons.join(';') }}
</p>
</div>
<p v-if="!repairsFor(issue).length" class="text-muted">当前没有可用修复建议。</p>
</div>
</article>
</template>
<p v-else class="text-muted">{{ handBusy ? '正在读取全项目校验…' : '尚未读取校验' }}</p>
</NCollapseItem>
</NCollapse>
</section>
<!-- 以下是统一的 AI 诊断启动模块,预览和费用确认集中展示 -->
<section class="diagnosis-section">
<h3>启动 AI 诊断</h3>
<p class="text-muted mt-2">{{ scopeLabel }} · 已有当前版本有效结果的镜头将跳过。</p>
<!-- 以下是使用 Naive UI 折叠组件的高级设置模块,默认收起 -->
<NCollapse class="diagnosis-advanced">
<NCollapseItem name="advanced-settings">
<template #header><span class="text-xs text-muted">高级设置</span></template>
<label class="diagnosis-concurrency"
><span>任务并发</span
><NInputNumber
v-model:value="concurrency"
aria-label="诊断任务并发"
:min="1"
:max="5"
:precision="0"
size="small"
/></label>
</NCollapseItem>
</NCollapse>
<div v-if="previews" class="diagnosis-preview" aria-live="polite">
<p>{{ scopeLabel }} · 范围内 {{ previewCount }} 个镜头</p>
<p class="text-xs text-muted">
缺少结构化动作证据 {{ previews.reduce((sum, item) => sum + item.needsEvidenceCount, 0) }} 镜 ·
快照无效 {{ previews.reduce((sum, item) => sum + item.invalidSnapshotCount, 0) }} 镜
</p>
</div>
<p v-if="previewError" class="text-danger" role="alert">{{ previewError }}</p>
<p class="text-xs text-muted mt-3">AI 诊断会产生模型费用,仅保存诊断记录,不修改镜头。</p>
<div class="diagnosis-start-actions">
<NButton
:loading="previewBusy"
:disabled="previewBusy || starting || execution.active.value"
@click="loadPreview"
>{{ previews ? '重新预览范围' : '预览诊断范围' }}</NButton
>
<ConfirmAction
label="启动 AI 诊断"
:description="confirmation"
primary
:disabled="!canStart"
:loading="starting"
@confirm="startDiagnosis"
/>
</div>
<p v-if="execution.active.value" class="text-xs text-muted mt-3">
诊断任务进行中,可关闭抽屉继续查看分镜。
</p>
</section>
<!-- 以下是持久化诊断任务进度模块,刷新页面后仍可恢复 -->
<WorkflowExecutionPanel
v-if="execution.executionId.value"
title="动作诊断任务"
:execution="execution.query.data.value ?? null"
:loading="execution.query.loading.value"
:error="execution.query.error.value ?? ''"
@refresh="execution.query.refresh()"
@dismiss="execution.dismiss()"
/>
</NDrawerContent>
</NDrawer>
</template>
<style>
@reference "../../../styles/styles.css";
/* 摘要保持一行信息密度,窄屏允许自然换行,入口始终可见。 */
.storyboard-diagnosis-summary {
@apply flex items-center justify-between gap-3 py-2.5 px-3 mb-5 bg-(--app-subtle) text-xs;
}
.diagnosis-summary-text {
@apply flex min-w-0 items-center flex-wrap gap-x-2 gap-y-1;
}
.storyboard-diagnosis-summary > .n-button {
flex-shrink: 0;
}
/* 抽屉分区依靠留白和细线区分,避免再堆叠大面积面板。 */
.storyboard-diagnosis-drawer .n-drawer-body-content-wrapper {
padding: 20px 24px 32px;
}
.storyboard-diagnosis-drawer .n-drawer-header {
padding: 20px 24px;
}
.diagnosis-intro {
@apply text-sm text-muted leading-6;
}
.diagnosis-section {
@apply py-5 border-b border-(--app-border) text-sm leading-6;
}
.diagnosis-section h3,
.diagnosis-evidence-title {
@apply font-semibold text-sm;
}
.diagnosis-section-heading {
@apply flex items-center justify-between gap-3;
}
.diagnosis-scope-controls {
@apply flex flex-wrap items-center gap-2 mt-3;
}
.diagnosis-scope-label {
@apply mt-3 font-medium;
}
.diagnosis-counts {
@apply flex flex-wrap gap-x-4 gap-y-1 mt-3 mb-4 text-xs text-muted;
}
/* 长结果列表独立滚动,避免把范围预览和启动操作推到列表末尾。 */
.diagnosis-result-list {
max-height: min(40dvh, 360px);
}
.diagnosis-result-filter {
@apply mb-3;
}
.diagnosis-empty {
@apply py-4 text-muted;
}
.diagnosis-result-item {
@apply py-4 border-t border-(--app-border) space-y-2;
}
.diagnosis-result-item .n-tag {
flex-shrink: 0;
}
.diagnosis-advanced {
@apply mt-3 text-xs text-muted;
}
.diagnosis-concurrency {
@apply flex items-center gap-3;
}
.diagnosis-concurrency .n-input-number {
@apply w-28;
}
.diagnosis-preview,
.diagnosis-repair {
@apply bg-(--app-subtle) p-3 mt-3;
}
.diagnosis-start-actions {
@apply flex flex-wrap justify-end gap-3 mt-4;
}
@media (max-width: 760px) {
.n-drawer.storyboard-diagnosis-drawer {
width: 100vw !important;
}
.storyboard-diagnosis-drawer .n-drawer-body-content-wrapper {
padding: 16px 16px 28px;
}
.storyboard-diagnosis-drawer .n-drawer-header {
padding: 16px;
}
.storyboard-diagnosis-summary {
@apply items-start;
}
.diagnosis-summary-text > .text-muted {
@apply basis-full;
}
}
</style>
@@ -2,19 +2,32 @@
import ContextNotice from '../../../components/ui/ContextNotice.vue'
import { NButton, NSelect, NTag } from 'naive-ui'
import { computed, ref } from 'vue'
import { computed, nextTick, ref } from 'vue'
import { Clock3 } from '@lucide/vue'
import { EmptyState } from '../../../components/ui'
import type { EpisodePlan, EpisodeShots } from '../types'
import type { DiagnosisLocation } from '../diagnosis'
/** Episode → Beat → Shot 的分层查看,不提前加入下一条 graph 的导演字段。 */
const props = defineProps<{ plans: EpisodePlan[]; episodes: EpisodeShots[] }>()
const props = defineProps<{
/** 正式分集节拍规划。 */
plans: EpisodePlan[]
/** 正式分集镜头。 */
episodes: EpisodeShots[]
}>()
/** 分镜卡片只负责发出诊断定位,确认及模型任务交由页面处理。 */
const emit = defineEmits<{ diagnose: [scope: { episodeNo: number; beatNo: number; shotNo?: number }] }>()
const selected = ref<number>()
const emit = defineEmits<{ diagnose: [scope: DiagnosisLocation] }>()
/** 阅读与诊断共用的当前剧集编号。 */
const selected = defineModel<number>('episodeNo')
/** 分镜正文根节点,用于定位问题镜头。 */
const root = ref<HTMLElement | null>(null)
/** 最近定位的镜头或节拍标识,用于保留可见高亮。 */
const locatedPosition = ref('')
/** 兼容只有正式镜头而没有单独规划的历史结果。 */
const plans = computed(() => (props.plans.length ? props.plans : props.episodes.map(item => item.episodePlan)))
/** 选择器与正文统一使用最终规划编号;初次读取或当前剧集被移除时回退到第一集。 */
const plan = computed(() => plans.value.find(item => item.episodeNo === selected.value) ?? plans.value[0])
/** 当前剧集对应的正式镜头。 */
const episode = computed(() => props.episodes.find(item => item.episodeNo === plan.value?.episodeNo))
const purposeLabels: Record<string, string> = {
establish: '建立场景',
@@ -28,10 +41,31 @@ const purposeLabels: Record<string, string> = {
resolution: '收束',
hook: '钩子'
}
/**
* 切换剧集并定位问题镜头,尊重系统减少动画设置。
* @param location 问题所在的正式剧集、节拍与镜头坐标
* @returns 列表更新并完成定位
*/
async function locate(location: DiagnosisLocation) {
selected.value = location.episodeNo
await nextTick()
const position = `${location.episodeNo}-${location.beatNo}${location.shotNo === undefined ? '' : `-${location.shotNo}`}`
const element = root.value?.querySelector<HTMLElement>(`[data-shot-position="${position}"]`)
if (!element) return
locatedPosition.value = position
element.focus({ preventScroll: true })
element.scrollIntoView({
block: 'center',
behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'
})
}
/** 仅暴露诊断问题定位能力。 */
defineExpose({ locate })
</script>
<template>
<div class="breakdown-storyboard">
<div ref="root" class="breakdown-storyboard">
<!-- 以下是分镜剧集选择与工作区入口模块 -->
<div v-if="plan || $slots.actions" class="breakdown-storyboard-toolbar">
<label v-if="plan" class="breakdown-episode-picker"
><span>选择剧集</span
@@ -55,6 +89,9 @@ const purposeLabels: Record<string, string> = {
<slot name="actions" />
</div>
</div>
<!-- 以下是当前集诊断摘要插槽,完整结果在右侧抽屉展示 -->
<slot name="diagnosis" />
<!-- 以下是当前集节拍与分镜正文模块 -->
<template v-if="plan">
<div v-if="plan.storyGoal || plan.emotionalArc" class="mb-7 surface-inset p-4">
<p v-if="plan.storyGoal" class="font-medium">{{ plan.storyGoal }}</p>
@@ -65,12 +102,27 @@ const purposeLabels: Record<string, string> = {
<ContextNotice v-if="!episode" type="info" :show-icon="false" class="mb-5">
本集已完成节拍规划,镜头尚未生成。请等待进度更新,或在确认中断后使用“补齐缺失镜头”。
</ContextNotice>
<section v-for="beat in plan.beats" :key="beat.beatNo" class="beat-section">
<section
v-for="beat in plan.beats"
:key="beat.beatNo"
class="beat-section"
tabindex="-1"
:data-shot-position="`${plan.episodeNo}-${beat.beatNo}`"
:class="{ 'diagnosis-located': locatedPosition === `${plan.episodeNo}-${beat.beatNo}` }"
>
<div class="beat-heading">
<span class="beat-number">{{ String(beat.beatNo).padStart(2, '0') }}</span>
<h3 class="text-sm font-semibold">{{ beat.title }}</h3>
<NTag size="small" :bordered="false">{{ purposeLabels[beat.purpose] || beat.purpose }}</NTag>
<NButton v-if="plan" size="tiny" text class="diagnose-hover-action ml-auto" aria-label="诊断当前节拍" @click="emit('diagnose', { episodeNo: plan.episodeNo, beatNo: beat.beatNo })">AI 诊断</NButton>
<NButton
v-if="plan"
size="tiny"
text
class="diagnose-hover-action ml-auto"
aria-label="诊断当前节拍"
@click="emit('diagnose', { episodeNo: plan.episodeNo, beatNo: beat.beatNo })"
>AI 诊断</NButton
>
</div>
<p class="mb-4 mt-3 text-sm leading-6 text-muted">{{ beat.description }}</p>
<div class="space-y-3">
@@ -78,6 +130,11 @@ const purposeLabels: Record<string, string> = {
v-for="shot in episode?.beatShots.find(item => item.beatNo === beat.beatNo)?.shots ?? []"
:key="shot.shotNo"
class="shot-row group"
tabindex="-1"
:data-shot-position="`${plan.episodeNo}-${beat.beatNo}-${shot.shotNo}`"
:class="{
'diagnosis-located': locatedPosition === `${plan.episodeNo}-${beat.beatNo}-${shot.shotNo}`
}"
>
<div class="shot-label">
镜头 {{ String(shot.shotNo).padStart(2, '0')
@@ -86,8 +143,23 @@ const purposeLabels: Record<string, string> = {
>
</div>
<div class="min-w-0 flex-1">
<div class="flex items-center justify-between gap-3"><h4 class="text-sm font-medium">{{ shot.title }}</h4>
<NButton v-if="plan" size="tiny" text class="diagnose-hover-action" aria-label="诊断当前镜头" @click="emit('diagnose', { episodeNo: plan.episodeNo, beatNo: beat.beatNo, shotNo: shot.shotNo })">AI 诊断</NButton>
<div class="flex items-center justify-between gap-3">
<h4 class="text-sm font-medium">{{ shot.title }}</h4>
<NButton
v-if="plan"
size="tiny"
text
class="diagnose-hover-action"
aria-label="诊断当前镜头"
@click="
emit('diagnose', {
episodeNo: plan.episodeNo,
beatNo: beat.beatNo,
shotNo: shot.shotNo
})
"
>AI 诊断</NButton
>
</div>
<p class="mt-2 text-sm leading-7">{{ shot.description }}</p>
<p class="mt-2 text-xs leading-6 text-muted">视觉重点 · {{ shot.visualFocus }}</p>
@@ -117,6 +189,11 @@ const purposeLabels: Record<string, string> = {
<style>
/* 本组件专属布局与 Naive 内部结构覆盖。 */
@reference "../../../styles/styles.css";
/* 问题定位保留轮廓提示,便于关闭抽屉后识别目标。 */
.diagnosis-located {
outline: 1px solid var(--app-accent);
outline-offset: 3px;
}
.beat-section {
@apply mt-[25px] pt-[23px];
}
@@ -136,7 +213,10 @@ const purposeLabels: Record<string, string> = {
pointer-events: auto;
}
@media (hover: none) {
.diagnose-hover-action { opacity: 1; pointer-events: auto; }
.diagnose-hover-action {
opacity: 1;
pointer-events: auto;
}
}
.beat-number {
@apply text-muted font-mono text-[11px];
+81
View File
@@ -0,0 +1,81 @@
import type { LegacyActionDiagnosisResults } from './types'
/** 诊断及定位共用的镜头坐标。 */
export interface DiagnosisLocation {
/** 正式剧集编号。 */
episodeNo: number
/** 集内节拍编号。 */
beatNo: number
/** 节拍内镜头编号;省略时表示整个节拍。 */
shotNo?: number
}
/** 诊断范围按层级约束,避免全项目请求遗留镜头条件。 */
export type DiagnosisScope =
| { /** 全项目范围。 */ kind: 'project' }
| { /** 单集范围。 */ kind: 'episode'; /** 正式集号。 */ episodeNo: number }
| ({ /** 单节拍范围。 */ kind: 'beat' } & Omit<DiagnosisLocation, 'shotNo'>)
| ({ /** 单镜头范围,必须包含镜头编号。 */ kind: 'shot' } & Required<DiagnosisLocation>)
/**
* 从后端整集或全项目结果中取得当前诊断范围。
* @param shots 后端镜头诊断记录
* @param scope 当前诊断范围
* @returns 当前范围内的镜头记录
*/
export function scopeDiagnosisShots(shots: LegacyActionDiagnosisResults['shots'], scope: DiagnosisScope) {
return shots.filter(
shot =>
scope.kind === 'project' ||
(shot.episodeNo === scope.episodeNo &&
(scope.kind === 'episode' ||
(shot.beatNo === scope.beatNo && (scope.kind === 'beat' || shot.shotNo === scope.shotNo))))
)
}
/**
* 按镜头真实诊断状态重新统计,缺少证据不能算作检查通过。
* @param shots 当前范围镜头记录
* @returns 各状态镜头数量
*/
export function summarizeDiagnosis(shots: LegacyActionDiagnosisResults['shots']) {
const counts = { total: shots.length, conflict: 0, clear: 0, insufficient: 0, invalid: 0, stale: 0, pending: 0 }
for (const shot of shots) counts[diagnosisCountKeys[shot.status]]++
return counts
}
/**
* 生成与已确认范围一致的批量诊断请求。
* @param scope 已预览的诊断范围
* @param concurrency 模型任务并发数
* @returns 后端批量诊断请求参数
*/
export function diagnosisInput(scope: DiagnosisScope, concurrency: number) {
return {
confirmed: true as const,
concurrency,
...(scope.kind !== 'project' ? { episodeNo: scope.episodeNo } : {}),
...(scope.kind === 'beat' || scope.kind === 'shot' ? { beatNo: scope.beatNo } : {}),
...(scope.kind === 'shot' ? { shotNo: scope.shotNo } : {})
}
}
/** 后端诊断状态对应的统计字段。 */
const diagnosisCountKeys = {
conflict_found: 'conflict',
no_conflict_found: 'clear',
insufficient_evidence: 'insufficient',
invalid_evidence: 'invalid',
stale: 'stale',
not_diagnosed: 'pending'
} as const
/** 状态始终保留文字,避免仅通过颜色区分问题。 */
export const diagnosisStatusLabels = {
conflict_found: '手部冲突',
no_conflict_found: '未发现冲突',
insufficient_evidence: '证据不足',
invalid_evidence: '证据无效',
stale: '诊断过期',
not_diagnosed: '尚未诊断'
} as const
+7 -1
View File
@@ -269,7 +269,13 @@ export interface LegacyActionDiagnosisResults {
shotNo: number
title: string
diagnosisId: string | null
status: 'not_diagnosed' | 'stale' | 'conflict_found' | 'no_conflict_found' | 'insufficient_evidence' | 'invalid_evidence'
status:
| 'not_diagnosed'
| 'stale'
| 'conflict_found'
| 'no_conflict_found'
| 'insufficient_evidence'
| 'invalid_evidence'
issues: unknown[]
createdAt: string | null
}>
+14 -2
View File
@@ -23,7 +23,11 @@ const state = computed(() => dramaRecords.value.at(-1)?.state)
const episodes = computed(() => project.value?.episodes ?? [])
const total = computed(() => project.value?.episodeCount ?? state.value?.episodeCount)
/** 整剧目标时长仅作展示,不影响生成状态。 */
const targetMinutes = computed(() => project.value?.targetDurationSeconds === null || project.value?.targetDurationSeconds === undefined ? null : Math.round(project.value.targetDurationSeconds / 60))
const targetMinutes = computed(() =>
project.value?.targetDurationSeconds === null || project.value?.targetDurationSeconds === undefined
? null
: Math.round(project.value.targetDurationSeconds / 60)
)
const projectId = computed(() => project.value?.id ?? '')
const operation = computed(() => getOperation(projectId.value))
const backgroundExecution = useWorkflowExecution(projectId, 'create-drama')
@@ -100,7 +104,15 @@ function exportScript() {
</div>
<div v-if="project" class="mt-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted">
<span>计划 {{ total ?? '—' }} 集</span>
<span>时长规划:{{ project.durationMode === 'auto' ? '自动' : project.durationMode === 'fixed_episode_count' ? '固定集数' : '弹性集数' }}</span>
<span
>时长规划:{{
project.durationMode === 'auto'
? '自动'
: project.durationMode === 'fixed_episode_count'
? '固定集数'
: '弹性集数'
}}</span
>
<span v-if="targetMinutes !== null">整剧目标约 {{ targetMinutes }} 分钟</span>
</div>
<!-- 以下是唯一的创作任务进度与恢复操作模块,随标题区滚动 -->
+10 -2
View File
@@ -164,7 +164,9 @@ onBeforeUnmount(() => observer?.disconnect())
>
<span class="reader-episode-label">第 {{ item.episode }} 集</span>
<span class="reader-episode-title">{{ item.title || '未命名剧集' }}</span>
<span v-if="item.targetDurationSeconds !== null" class="text-xs text-muted">{{ item.targetDurationSeconds }}秒</span>
<span v-if="item.targetDurationSeconds !== null" class="text-xs text-muted"
>{{ item.targetDurationSeconds }}秒</span
>
</NButton>
</div>
</NScrollbar>
@@ -181,7 +183,13 @@ onBeforeUnmount(() => observer?.disconnect())
class="reader-chapter"
>
<header class="reader-chapter-heading">
<p>第 {{ item.episode }} 集<span v-if="item.targetDurationSeconds !== null" class="ml-3 text-xs text-muted">目标 {{ item.targetDurationSeconds }} 秒</span></p>
<p>
第 {{ item.episode }} 集<span
v-if="item.targetDurationSeconds !== null"
class="ml-3 text-xs text-muted"
>目标 {{ item.targetDurationSeconds }} 秒</span
>
</p>
<h2 :id="`${readerId}-heading-${item.episode}`">{{ item.title || '未命名剧集' }}</h2>
</header>
<p v-if="item.summary" class="script-summary">{{ item.summary }}</p>
@@ -1,5 +1,4 @@
<script setup lang="ts">
import FeedbackMessage from '../../../components/ui/FeedbackMessage.vue'
import AppForm from '../../../components/ui/AppForm.vue'
import { NFormItem } from 'naive-ui'
@@ -25,9 +24,14 @@ const feedback = ref('')
const formRef = ref<InstanceType<typeof AppForm> | null>(null)
/** 与后端 POST /projects 入参一致的创建表单。 */
const form = reactive({
title: '', topic: '', style: '', episodeCount: 1,
title: '',
topic: '',
style: '',
episodeCount: 1,
durationMode: 'auto' as DramaDurationBudget['mode'],
totalMinutes: 90, minSeconds: 120, maxSeconds: 180
totalMinutes: 90,
minSeconds: 120,
maxSeconds: 180
})
/** 时长模式只影响可见字段,默认 Auto 不施加时长约束。 */
const durationOptions = [
@@ -36,7 +40,8 @@ const durationOptions = [
{ label: '根据单集时长推导集数', value: 'flexible_episode_count' }
]
const estimatedCount = computed(() => {
if (form.durationMode !== 'flexible_episode_count' || form.minSeconds <= 0 || form.maxSeconds < form.minSeconds) return null
if (form.durationMode !== 'flexible_episode_count' || form.minSeconds <= 0 || form.maxSeconds < form.minSeconds)
return null
const total = Math.round(form.totalMinutes * 60)
const minimum = Math.ceil(total / form.maxSeconds)
const maximum = Math.floor(total / form.minSeconds)
@@ -52,8 +57,10 @@ function durationBudget(): DramaDurationBudget {
return { mode: 'fixed_episode_count', totalDurationSeconds, episodeCount: form.episodeCount }
}
return {
mode: 'flexible_episode_count', totalDurationSeconds,
episodeDurationMinSeconds: form.minSeconds, episodeDurationMaxSeconds: form.maxSeconds
mode: 'flexible_episode_count',
totalDurationSeconds,
episodeDurationMinSeconds: form.minSeconds,
episodeDurationMaxSeconds: form.maxSeconds
}
}
@@ -65,11 +72,20 @@ async function submit() {
feedback.value = '总时长必须是大于 0 的整数分钟'
return
}
if (form.durationMode !== 'flexible_episode_count' && (!Number.isInteger(form.episodeCount) || form.episodeCount <= 0)) {
if (
form.durationMode !== 'flexible_episode_count' &&
(!Number.isInteger(form.episodeCount) || form.episodeCount <= 0)
) {
feedback.value = '计划集数必须是大于 0 的整数'
return
}
if (form.durationMode === 'flexible_episode_count' && (!Number.isInteger(form.minSeconds) || !Number.isInteger(form.maxSeconds) || form.minSeconds <= 0 || form.maxSeconds < form.minSeconds)) {
if (
form.durationMode === 'flexible_episode_count' &&
(!Number.isInteger(form.minSeconds) ||
!Number.isInteger(form.maxSeconds) ||
form.minSeconds <= 0 ||
form.maxSeconds < form.minSeconds)
) {
feedback.value = '单集时长范围必须为正整数,且最大时长不能小于最小时长'
return
}
@@ -136,7 +152,7 @@ const rules = computed(() => ({
placeholder="描述主角、故事背景,以及你希望展开的核心冲突……"
:disabled="busy"
:input-props="{ id: 'topic' }"
class="min-h-32 resize-y"
class="project-story-input min-h-32 resize-y"
v-model:value="form.topic"
type="textarea"
:autosize="{ minRows: 3, maxRows: 12 }"
@@ -149,7 +165,7 @@ const rules = computed(() => ({
placeholder="如:都市悬疑、爽文反转"
:disabled="busy"
:input-props="{ id: 'style' }"
class="min-h-32 resize-y"
class="project-story-input min-h-32 resize-y"
v-model:value="form.style"
type="textarea"
:autosize="{ minRows: 3, maxRows: 12 }"
@@ -157,14 +173,44 @@ const rules = computed(() => ({
></NFormItem>
</div>
<!-- 时长与集数:按规划模式动态显示。 -->
<NFormItem label="时长规划模式"><NSelect v-model:value="form.durationMode" :options="durationOptions" :disabled="busy" /></NFormItem>
<NFormItem v-if="form.durationMode !== 'auto'" label="整剧目标时长(分钟)"><NInputNumber :value="form.totalMinutes" @update:value="form.totalMinutes = $event ?? 0" :min="1" :precision="0" :disabled="busy" class="w-full" /></NFormItem>
<NFormItem label="时长规划模式"
><NSelect v-model:value="form.durationMode" :options="durationOptions" :disabled="busy"
/></NFormItem>
<NFormItem v-if="form.durationMode !== 'auto'" label="整剧目标时长(分钟)"
><NInputNumber
:value="form.totalMinutes"
@update:value="form.totalMinutes = $event ?? 0"
:min="1"
:precision="0"
:disabled="busy"
class="w-full"
/></NFormItem>
<div v-if="form.durationMode === 'flexible_episode_count'" class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<NFormItem label="单集最短时长(秒)"><NInputNumber :value="form.minSeconds" @update:value="form.minSeconds = $event ?? 0" :min="1" :precision="0" :disabled="busy" class="w-full" /></NFormItem>
<NFormItem label="单集最长时长(秒)"><NInputNumber :value="form.maxSeconds" @update:value="form.maxSeconds = $event ?? 0" :min="1" :precision="0" :disabled="busy" class="w-full" /></NFormItem>
<NFormItem label="单集最短时长(秒)"
><NInputNumber
:value="form.minSeconds"
@update:value="form.minSeconds = $event ?? 0"
:min="1"
:precision="0"
:disabled="busy"
class="w-full"
/></NFormItem>
<NFormItem label="单集最长时长(秒)"
><NInputNumber
:value="form.maxSeconds"
@update:value="form.maxSeconds = $event ?? 0"
:min="1"
:precision="0"
:disabled="busy"
class="w-full"
/></NFormItem>
</div>
<div class="grid grid-cols-1 gap-4">
<NFormItem v-if="form.durationMode !== 'flexible_episode_count'" path="episodeCount" label="计划集数" :label-props="{ for: 'episode-count' }"
<NFormItem
v-if="form.durationMode !== 'flexible_episode_count'"
path="episodeCount"
label="计划集数"
:label-props="{ for: 'episode-count' }"
><NInputNumber
:disabled="busy"
:input-props="{ id: 'episode-count' }"
@@ -176,7 +222,6 @@ const rules = computed(() => ({
></NFormItem>
</div>
<FeedbackMessage v-if="feedback" :message="feedback" />
</AppForm>
<template #footer>
<NButton :disabled="busy" @click="open = false">取消</NButton>
@@ -4,7 +4,7 @@ import FeedbackMessage from '../../../components/ui/FeedbackMessage.vue'
import ContextNotice from '../../../components/ui/ContextNotice.vue'
import { computed, reactive, ref, watch } from 'vue'
import { NButton, NInput } from 'naive-ui'
import { NAlert, NButton, NInput } from 'naive-ui'
import { AppDialog } from '../../../components/ui'
import { errorMessage } from '../../../lib/http'
import { projectsApi } from '../api'
@@ -19,6 +19,8 @@ const readiness = ref<Awaited<ReturnType<typeof projectsApi.deleteReadiness>> |
const readinessPending = ref(false)
const expected = computed(() => props.project?.title || props.project?.topic || '')
const confirmed = computed(() => !!props.project && state.confirm.trim() === expected.value)
/** 名称匹配且后台检查允许删除时才启用危险按钮,其余状态统一使用灰色禁用样式。 */
const canRemove = computed(() => confirmed.value && !readinessPending.value && readiness.value?.canDelete === true)
watch(
() => [open.value, props.project?.id],
async () => {
@@ -55,30 +57,49 @@ async function remove() {
}
</script>
<template>
<AppDialog v-model:open="open" :title="`永久删除 · ${expected}`" description="删除后无法恢复。">
<ContextNotice type="error" :show-icon="false" class="mt-4">
会永久删除剧本、主体、身份、形态、分镜、首帧、视频、工作流记录,以及本地 Storage
中属于该项目的图片、视频和上传素材。
</ContextNotice>
<ContextNotice v-if="readinessPending" type="info" :show-icon="false" class="mt-3"
>正在检查项目后台任务…</ContextNotice
>
<ContextNotice v-else-if="readiness && !readiness.canDelete" type="warning" :show-icon="false" class="mt-3">
当前有
{{ readiness.totalActiveTasks }}
个后台任务正在执行,暂不能删除。请等待图片、首帧、视频或工作流任务结束后再试。
</ContextNotice>
<AppDialog v-model:open="open" :title="`永久删除 · ${expected}`">
<FeedbackMessage v-if="state.error" :message="state.error" />
<p class="mt-5 text-xs">
请输入 <strong>{{ expected }}</strong> 确认删除:
</p>
<NInput v-model:value="state.confirm" class="mt-2" placeholder="输入项目名称" />
<!-- 以下是分组间距统一为 16px 的删除说明与名称确认模块 -->
<section class="space-y-4">
<!-- 删除范围与后台任务状态属于同组,保持 8px 间距 -->
<div class="space-y-2">
<ContextNotice type="error" :show-icon="false">
会永久删除剧本、主体、身份、形态、分镜、首帧、视频、工作流记录,以及本地 Storage
中属于该项目的图片、视频和上传素材。
</ContextNotice>
<ContextNotice v-if="readinessPending" type="info" :show-icon="false"
>正在检查项目后台任务…</ContextNotice
>
<!-- 以下是阻止删除的独立警告模块,通过图标、底色和标题突出原因与下一步 -->
<NAlert
v-else-if="readiness && !readiness.canDelete"
type="warning"
title="暂时无法删除"
:bordered="false"
role="alert"
>
<div class="text-xs leading-6">
<p>
当前有 <strong>{{ readiness.totalActiveTasks }} 个后台任务</strong>正在执行。
</p>
<p>请等待图片、首帧、视频或工作流任务结束后再试。</p>
</div>
</NAlert>
</div>
<!-- 确认提示与输入框保持 8px 间距,标签点击可聚焦输入框 -->
<label class="block text-xs">
<span class="block"
>请输入 <strong>{{ expected }}</strong> 确认删除:</span
>
<NInput v-model:value="state.confirm" class="mt-2" placeholder="输入项目名称" />
</label>
</section>
<template #footer>
<NButton @click="open = false">取消</NButton>
<NButton
type="error"
:type="canRemove ? 'error' : 'default'"
:loading="state.pending"
:disabled="!confirmed || readinessPending || !readiness?.canDelete"
:disabled="!canRemove"
@click="remove"
>永久删除项目</NButton
>
@@ -68,14 +68,22 @@ async function save() {
<FeedbackMessage v-if="state.error" :message="state.error" />
<section class="dialog-form-stack">
<label class="block text-xs">项目名称<NInput v-model:value="form.title" class="mt-2" /></label>
<!-- 以下是与新增弹窗共用内边距的故事主题编辑模块 -->
<label class="block text-xs"
>故事主题<NInput
v-model:value="form.topic"
type="textarea"
:autosize="{ minRows: 3, maxRows: 8 }"
class="mt-2"
class="project-story-input mt-2"
/></label>
<!-- 以下是与新增弹窗共用内边距的多行风格编辑模块,随内容自动增高 -->
<label class="block text-xs"
>风格<NInput
v-model:value="form.style"
type="textarea"
:autosize="{ minRows: 3, maxRows: 8 }"
class="project-story-input mt-2"
/></label>
<label class="block text-xs">风格<NInput v-model:value="form.style" class="mt-2" /></label>
</section>
<template #footer>
<NButton @click="open = false">取消</NButton>
+13 -2
View File
@@ -4,8 +4,19 @@ export type ProjectStatus = 'draft' | 'generating' | 'completed' | 'need_review'
/** 创建短剧时长预算:Auto 仅约束集数,固定与弹性模式可约束总时长。 */
export type DramaDurationBudget =
| { mode: 'auto'; episodeCount: number }
| { mode: 'fixed_episode_count'; totalDurationSeconds: number; episodeCount: number; episodeDurationMinSeconds?: number; episodeDurationMaxSeconds?: number }
| { mode: 'flexible_episode_count'; totalDurationSeconds: number; episodeDurationMinSeconds: number; episodeDurationMaxSeconds: number }
| {
mode: 'fixed_episode_count'
totalDurationSeconds: number
episodeCount: number
episodeDurationMinSeconds?: number
episodeDurationMaxSeconds?: number
}
| {
mode: 'flexible_episode_count'
totalDurationSeconds: number
episodeDurationMinSeconds: number
episodeDurationMaxSeconds: number
}
/** 创建请求参数,与后端 POST /projects 入参保持一致。 */
export interface CreateProjectInput {
+30 -11
View File
@@ -84,7 +84,9 @@ const productionReady = computed(() => directionComplete.value && visualStateCom
const durationAudit = ref<StoryboardDurationAudit | null>(null)
/** 项目预算汇总为只读数据,失败不影响现有分镜操作。 */
const durationBudget = ref<ProjectDurationBudgetSummary | null>(null)
const currentDurationBudget = computed(() => durationBudget.value?.episodes?.find(item => item.episodeNo === episodeNo.value) ?? null)
const currentDurationBudget = computed(
() => durationBudget.value?.episodes?.find(item => item.episodeNo === episodeNo.value) ?? null
)
const durationAuditError = ref('')
/** 仅在只读预算请求进行中展示局部加载状态。 */
const durationLoading = ref(false)
@@ -108,9 +110,8 @@ async function refreshDuration(projectId: string) {
durationLoading.value = false
if (audit.status === 'fulfilled') durationAudit.value = audit.value
if (budget.status === 'fulfilled' && Array.isArray(budget.value?.episodes)) durationBudget.value = budget.value
durationAuditError.value = audit.status === 'rejected' || budget.status === 'rejected'
? '部分时长信息暂不可用,不影响分镜操作。'
: ''
durationAuditError.value =
audit.status === 'rejected' || budget.status === 'rejected' ? '部分时长信息暂不可用,不影响分镜操作。' : ''
}
watch(
id,
@@ -255,21 +256,39 @@ const rules = { concurrency: integerRule('批量并发'), maxRepairAttempts: int
></NSelect>
</div>
<!-- 当前剧集时长汇总仅占一行;窄屏自动换行,不挤压操作按钮。 -->
<div v-if="currentDurationBudget || durationLoading" class="storyboard-duration-summary" aria-label="本集时长预算">
<div
v-if="currentDurationBudget || durationLoading"
class="storyboard-duration-summary"
aria-label="本集时长预算"
>
<span v-if="durationLoading" class="text-muted" role="status">时长数据更新中…</span>
<template v-if="currentDurationBudget">
<span v-if="currentDurationBudget.targetDurationSeconds !== null">目标 {{ currentDurationBudget.targetDurationSeconds }} 秒</span>
<span v-if="currentDurationBudget.targetDurationSeconds !== null"
>目标 {{ currentDurationBudget.targetDurationSeconds }} 秒</span
>
<span v-else>自动规划时长</span>
<span v-if="currentDurationBudget.plannedSeconds !== null">Beat {{ currentDurationBudget.plannedSeconds }} 秒</span>
<span v-if="currentDurationBudget.shotCount > 0 && currentDurationBudget.shotSeconds !== null">Shot {{ currentDurationBudget.shotSeconds }} 秒</span>
<span v-if="currentDurationBudget.plannedSeconds !== null"
>Beat {{ currentDurationBudget.plannedSeconds }} 秒</span
>
<span v-if="currentDurationBudget.shotCount > 0 && currentDurationBudget.shotSeconds !== null"
>Shot {{ currentDurationBudget.shotSeconds }} 秒</span
>
<span
v-if="durationStatusLabel"
:class="currentDurationBudget.audit?.needsReview ? 'text-warning' : 'text-muted'"
>
{{ durationStatusLabel }}
<template v-if="currentDurationBudget.audit?.deviationSeconds !== null && currentDurationBudget.audit?.deviationSeconds !== undefined">
{{ currentDurationBudget.audit.deviationSeconds > 0 ? '+' : '' }}{{ currentDurationBudget.audit.deviationSeconds }} 秒
(±{{ currentDurationBudget.audit.toleranceSeconds ?? 0 }} 秒)
<template
v-if="
currentDurationBudget.audit?.deviationSeconds !== null &&
currentDurationBudget.audit?.deviationSeconds !== undefined
"
>
{{ currentDurationBudget.audit.deviationSeconds > 0 ? '+' : ''
}}{{ currentDurationBudget.audit.deviationSeconds }} 秒 (±{{
currentDurationBudget.audit.toleranceSeconds ?? 0
}}
秒)
</template>
</span>
</template>
+7
View File
@@ -210,6 +210,13 @@ body {
padding-inline: 0;
background: transparent;
}
/* 新增与编辑项目的主题、风格输入框统一留白;同步作用于文本、占位和自动高度镜像。 */
.project-story-input.n-input--textarea {
--n-padding-vertical: 12px;
}
.project-story-input.n-input--textarea .n-input-wrapper {
padding-inline: 16px;
}
.dialog-form-stack {
display: flex;
flex-direction: column;
+5 -2
View File
@@ -422,8 +422,11 @@ describe('管理后台组件边界', () => {
it('服务端制作阶段就绪后解锁全部左侧链接,标题只保留项目配置入口', async () => {
const detail = vi.spyOn(projectsApi, 'detail').mockResolvedValue({
id: 'navigation-test',
durationMode: 'auto', episodeCount: 1, targetDurationSeconds: null,
episodeMinSeconds: null, episodeMaxSeconds: null,
durationMode: 'auto',
episodeCount: 1,
targetDurationSeconds: null,
episodeMinSeconds: null,
episodeMaxSeconds: null,
title: '导航测试项目',
topic: '测试主题',
style: null,
+113 -47
View File
@@ -1,5 +1,5 @@
import { computed, ref } from 'vue'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { NSelect } from 'naive-ui'
import { readFileSync } from 'node:fs'
@@ -159,6 +159,62 @@ async function selectTab(label: string) {
await flushPromises()
}
/**
* 提供完整的空诊断记录,用于只验证分镜列表的用例隔离只读摘要请求。
* @returns 后端诊断结果响应
*/
function diagnosisResultsResponse() {
return new Response(
JSON.stringify({
data: {
projectId: 'breakdown-scroll-test',
episodeNo: 1,
counts: { total: 0, conflict: 0, clear: 0, insufficient: 0, invalid: 0, stale: 0, pending: 0 },
shots: []
}
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } }
)
}
/**
* 提供完整结构化校验响应,通过证据数量区分当前与迟到结果。
* @param evidenceShotCount 具有有效动作证据的镜头数量
* @returns 后端结构化校验响应
*/
function handDiagnosticsResponse(evidenceShotCount: number) {
return new Response(
JSON.stringify({
data: {
projectId: 'breakdown-scroll-test',
episodeCount: 1,
shotCount: 25,
validSnapshotCount: 25,
evidenceShotCount,
invalidEvidenceShotCount: 0,
missingEvidenceShotCount: 25 - evidenceShotCount,
evidenceCoverage: evidenceShotCount / 25,
assessment: evidenceShotCount ? 'complete_evidence' : 'insufficient_evidence',
warningCount: 0,
diagnostics: [],
willCallModel: false,
willModifyAssets: false
}
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } }
)
}
/**
* 从真实挂载的抽屉读取内容,不把诊断抽屉误当成拆解设置弹窗。
* @returns 当前动作诊断抽屉
*/
function qualityDrawer() {
const panel = document.querySelector<HTMLElement>('.storyboard-diagnosis-drawer')
if (!panel) throw new Error('动作诊断抽屉未打开')
return new DOMWrapper(panel)
}
describe('拆解页内容滚动', () => {
it('拆解设置保留输入标签、单行单位与模块说明,改版后仍校验模块和剧本状态', async () => {
const fetcher = vi.fn<typeof fetch>()
@@ -332,6 +388,10 @@ describe('拆解页内容滚动', () => {
})
it('分镜选择与计数、入口同排,默认显示实际剧集,切换后内容和统计同步', async () => {
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async () => diagnosisResultsResponse())
)
const record = checkpoint()
const result = record.state.breakdownResult!
const first = result.storyboardPlans![0]!
@@ -395,6 +455,11 @@ describe('拆解页内容滚动', () => {
['分镜', '镜头 25'],
['任务明细', '任务错误 50']
])('%s 的末项始终放在独立结果滚动容器内', async (label, lastItem) => {
if (label === '分镜')
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async () => diagnosisResultsResponse())
)
mountPage()
await selectTab(label)
expect(wrapper!.find('.workspace-scroll').exists()).toBe(false)
@@ -451,64 +516,65 @@ describe('拆解页内容滚动', () => {
expect(drawerPanel().text()).toContain('重试失败抽取')
})
it('手部质量诊断仅在点击后请求,并展示证据不足状态', async () => {
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({
data: {
projectId: 'breakdown-scroll-test', episodeCount: 1,
shotCount: 25, validSnapshotCount: 25,
evidenceShotCount: 0, invalidEvidenceShotCount: 0,
missingEvidenceShotCount: 25, evidenceCoverage: 0,
assessment: 'insufficient_evidence', warningCount: 0,
diagnostics: [], willCallModel: false, willModifyAssets: false
}
}), { status: 200, headers: { 'Content-Type': 'application/json' } }))
it('诊断摘要与抽屉按需读取,展开结构化校验后展示证据不足', async () => {
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
const url = String(input)
if (url.includes('storyboard-legacy-action-diagnosis-results')) return diagnosisResultsResponse()
if (url.endsWith('storyboard-hand-occupancy-diagnostics')) return handDiagnosticsResponse(0)
throw new Error(`未预期的诊断请求:${url}`)
})
vi.stubGlobal('fetch', fetcher)
mountPage()
await wrapper!.get('[data-workspace-tools]').trigger('click')
await flushPromises()
expect(fetcher).not.toHaveBeenCalled()
const panel = drawerPanel()
const action = panel.findAll('button').find(button => button.text() === '查看诊断')
expect(action).toBeDefined()
await action!.trigger('click')
await flushPromises()
await selectTab('分镜')
expect(fetcher).toHaveBeenCalledTimes(1)
expect(String(fetcher.mock.calls[0]?.[0])).toContain('/breakdown/storyboard-hand-occupancy-diagnostics')
expect(panel.text()).toContain('有效证据 0 / 25')
expect(panel.text()).toContain('证据不足')
expect(String(fetcher.mock.calls[0]?.[0])).toContain('diagnosis-results?episodeNo=1')
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
await flushPromises()
const panel = qualityDrawer()
await panel.get('.n-collapse-item__header-main').trigger('click')
await flushPromises()
expect(panel.text()).toContain('有效动作证据 0 / 25 镜')
expect(panel.text()).toContain('证据不足,暂无法判断冲突情况')
expect(
fetcher.mock.calls.filter(([input]) => String(input).endsWith('storyboard-hand-occupancy-diagnostics'))
).toHaveLength(1)
})
it('关闭弹窗后迟到的诊断响应不会污染再次打开的状态', async () => {
let resolveRequest: ((value: Response) => void) | undefined
const fetcher = vi.fn<typeof fetch>().mockImplementation(() => new Promise<Response>(resolve => {
resolveRequest = resolve
}))
it('关闭抽屉后的迟到校验响应不会污染再次打开的状态', async () => {
let resolveFirst: ((value: Response) => void) | undefined
let handRequests = 0
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
const url = String(input)
if (url.includes('storyboard-legacy-action-diagnosis-results')) return diagnosisResultsResponse()
if (url.endsWith('storyboard-hand-occupancy-diagnostics')) {
handRequests++
if (handRequests === 1)
return new Promise<Response>(resolve => {
resolveFirst = resolve
})
return handDiagnosticsResponse(0)
}
throw new Error(`未预期的诊断请求:${url}`)
})
vi.stubGlobal('fetch', fetcher)
mountPage()
await wrapper!.get('[data-workspace-tools]').trigger('click')
await selectTab('分镜')
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
await flushPromises()
const action = drawerPanel().findAll('button').find(button => button.text() === '查看诊断')
expect(action).toBeDefined()
await action!.trigger('click')
expect(fetcher).toHaveBeenCalledTimes(1)
await drawerPanel().get('.n-card-header__close').trigger('click')
expect(handRequests).toBe(1)
await qualityDrawer().get('.n-drawer-header__close').trigger('click')
await flushPromises()
resolveRequest!(new Response(JSON.stringify({
data: {
projectId: 'breakdown-scroll-test', episodeCount: 1,
shotCount: 25, validSnapshotCount: 25,
evidenceShotCount: 25, invalidEvidenceShotCount: 0,
missingEvidenceShotCount: 0, evidenceCoverage: 1,
assessment: 'complete_evidence', warningCount: 0,
diagnostics: [], willCallModel: false, willModifyAssets: false
}
}), { status: 200, headers: { 'Content-Type': 'application/json' } }))
resolveFirst!(handDiagnosticsResponse(25))
await flushPromises()
await wrapper!.get('[data-workspace-tools]').trigger('click')
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
await flushPromises()
expect(drawerPanel().text()).not.toContain('有效证据 25 / 25')
expect(drawerPanel().findAll('button').some(button => button.text() === '查看诊断')).toBe(true)
expect(fetcher).toHaveBeenCalledTimes(1)
const panel = qualityDrawer()
await panel.get('.n-collapse-item__header-main').trigger('click')
await flushPromises()
expect(panel.text()).not.toContain('有效动作证据 25 / 25')
expect(panel.text()).toContain('有效动作证据 0 / 25 镜')
expect(handRequests).toBe(2)
})
it('没有正式剧集时保留可滚动的空状态,不显示拆解设置与结果', () => {
+104
View File
@@ -0,0 +1,104 @@
import { describe, expect, it } from 'vitest'
import { diagnosisInput, scopeDiagnosisShots, summarizeDiagnosis } from '@/features/breakdown/diagnosis'
import type { LegacyActionDiagnosisResults } from '@/features/breakdown/types'
/** 同集不同节拍及跨集镜头,用于验证范围不会混入其它位置的结果。 */
const shots: LegacyActionDiagnosisResults['shots'] = [
{
shotId: 'a',
episodeNo: 1,
beatNo: 1,
shotNo: 1,
title: '镜头一',
diagnosisId: null,
status: 'not_diagnosed',
issues: [],
createdAt: null
},
{
shotId: 'b',
episodeNo: 1,
beatNo: 1,
shotNo: 2,
title: '镜头二',
diagnosisId: 'b',
status: 'conflict_found',
issues: [],
createdAt: null
},
{
shotId: 'c',
episodeNo: 1,
beatNo: 2,
shotNo: 1,
title: '镜头三',
diagnosisId: 'c',
status: 'stale',
issues: [],
createdAt: null
},
{
shotId: 'd',
episodeNo: 2,
beatNo: 1,
shotNo: 1,
title: '镜头四',
diagnosisId: 'd',
status: 'no_conflict_found',
issues: [],
createdAt: null
}
]
describe('动作诊断范围与统计', () => {
it('单镜头和节拍只保留准确位置,不能直接使用整集结果统计', () => {
expect(
scopeDiagnosisShots(shots, { kind: 'shot', episodeNo: 1, beatNo: 1, shotNo: 2 }).map(item => item.shotId)
).toEqual(['b'])
const beat = scopeDiagnosisShots(shots, { kind: 'beat', episodeNo: 1, beatNo: 1 })
expect(beat.map(item => item.shotId)).toEqual(['a', 'b'])
expect(summarizeDiagnosis(beat)).toEqual({
total: 2,
conflict: 1,
clear: 0,
insufficient: 0,
invalid: 0,
stale: 0,
pending: 1
})
})
it('单集不混入其它剧集,全项目保留全部结果', () => {
expect(scopeDiagnosisShots(shots, { kind: 'episode', episodeNo: 2 }).map(item => item.shotId)).toEqual(['d'])
expect(scopeDiagnosisShots(shots, { kind: 'project' })).toHaveLength(4)
})
it('未诊断、证据不足、证据无效和过期都不能计入未发现冲突', () => {
const results = [
shots[0]!,
shots[2]!,
{ ...shots[1]!, status: 'insufficient_evidence' as const },
{ ...shots[1]!, status: 'invalid_evidence' as const }
]
expect(summarizeDiagnosis(results)).toEqual({
total: 4,
conflict: 0,
clear: 0,
insufficient: 1,
invalid: 1,
stale: 1,
pending: 1
})
})
it('全项目启动不遗留集、节拍或镜头条件,单镜头保留全部条件', () => {
expect(diagnosisInput({ kind: 'project' }, 3)).toEqual({ confirmed: true, concurrency: 3 })
expect(diagnosisInput({ kind: 'shot', episodeNo: 2, beatNo: 4, shotNo: 1 }, 2)).toEqual({
confirmed: true,
concurrency: 2,
episodeNo: 2,
beatNo: 4,
shotNo: 1
})
})
})
@@ -6,8 +6,21 @@ import { readAllStyles } from '@/testing/styles'
import type { Episode } from '@/features/projects/types'
const episodes: Episode[] = [
{ episode: 1, targetDurationSeconds: null, title: '来信', summary: '第一集摘要', content: '第一场:旧书店。', conflict: '信件失踪' },
{ episode: 2, targetDurationSeconds: null, title: '雨夜', content: '<script>不要执行模型内容</script>', hook: '门外有人' },
{
episode: 1,
targetDurationSeconds: null,
title: '来信',
summary: '第一集摘要',
content: '第一场:旧书店。',
conflict: '信件失踪'
},
{
episode: 2,
targetDurationSeconds: null,
title: '雨夜',
content: '<script>不要执行模型内容</script>',
hook: '门外有人'
},
{ episode: 3, targetDurationSeconds: null, title: '重逢', content: '' }
]
let wrapper: VueWrapper | undefined
+2 -1
View File
@@ -61,7 +61,8 @@ function project(id: string, status: ProjectStatus): ProjectDetail {
episodeCount: 1,
targetDurationSeconds: null,
episodeMinSeconds: null,
episodeMaxSeconds: null, title: '访问限制测试',
episodeMaxSeconds: null,
title: '访问限制测试',
topic: '',
style: null,
createdAt: '',
+10 -1
View File
@@ -108,7 +108,16 @@ function stubFetch(fetcher: Mock<typeof fetch>) {
targetDurationSeconds: null,
episodeMinSeconds: null,
episodeMaxSeconds: null,
episodes: [{ episodeNo: 1, targetDurationSeconds: null, plannedSeconds: null, shotSeconds: null, shotCount: 0, audit: null }],
episodes: [
{
episodeNo: 1,
targetDurationSeconds: null,
plannedSeconds: null,
shotSeconds: null,
shotCount: 0,
audit: null
}
],
targetWarningCount: 0,
willCallModel: false,
willModifyAssets: false