feat(short-drama-agent-front): 适配故事规划并优化任务弹窗

This commit is contained in:
GJ committed 2026-10-28 11:47:05 +08:00
1 parent 48fce3975f
commit 5836b90934
12 files changed
+960 -133

No files matched your search

+41 -4
View File
@@ -10,21 +10,31 @@ withDefaults(
showIcon?: boolean
/** 需要始终可见的业务状态名称。 */
title?: string
/** 重要注意事项复用项目主题底面、图标与醒目标题,普通说明保持原有紧凑样式。 */
emphasized?: boolean
}>(),
{ type: 'info', showIcon: true }
{ type: 'info', showIcon: true, emphasized: false }
)
</script>
<template>
<div class="context-notice" :class="`context-notice-${type}`">
<div
class="context-notice"
:class="[`context-notice-${type}`, { 'context-notice-emphasized': emphasized }]"
:role="emphasized && (type === 'error' || type === 'warning') ? 'alert' : undefined"
>
<component
v-if="showIcon"
:is="type === 'success' ? CheckCircle2 : type === 'warning' || type === 'error' ? CircleAlert : Info"
:size="14"
:size="emphasized ? 18 : 14"
aria-hidden="true"
/>
<div class="min-w-0 flex-1">
<strong v-if="title" class="mb-1 block text-xs font-medium">{{ title }}</strong
<strong
v-if="title"
class="mb-1 block"
:class="emphasized ? 'text-sm font-semibold' : 'text-xs font-medium'"
>{{ title }}</strong
><slot />
</div>
</div>
@@ -44,4 +54,31 @@ withDefaults(
.context-notice > div > p:first-child {
@apply mt-0;
}
/* 重要提示沿用项目的中性底面和文字层级,深浅主题自动保持协调。 */
.context-notice-emphasized {
@apply gap-3 text-sm leading-7;
padding: var(--app-content-gap);
color: var(--app-muted);
background: var(--app-subtle);
}
.context-notice-emphasized strong {
color: var(--app-ink);
}
.context-notice-emphasized > svg {
@apply mt-1;
color: var(--app-ink);
}
/* 明确的失败和成功保留现有项目状态色,只在图标与柔和底面上提示。 */
.context-notice-emphasized.context-notice-error {
background: color-mix(in srgb, var(--app-danger-soft) 45%, var(--app-surface));
}
.context-notice-emphasized.context-notice-error > svg {
color: var(--app-danger);
}
.context-notice-emphasized.context-notice-success {
background: color-mix(in srgb, var(--app-success-soft) 45%, var(--app-surface));
}
.context-notice-emphasized.context-notice-success > svg {
color: var(--app-success);
}
</style>
+273 -97
View File
@@ -1,10 +1,12 @@
<script setup lang="ts">
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
import { NScrollbar, NCollapse, NCollapseItem, NProgress, NTab, NTabs, NTag } from 'naive-ui'
import { NScrollbar, NCollapse, NCollapseItem, NTab, NTabs, NTag, NButton } from 'naive-ui'
import { computed, ref, watch } from 'vue'
import { ArrowRight, Check, Circle } from '@lucide/vue'
import { ArrowRight, Check, Circle, CircleAlert, ClipboardList, LoaderCircle } from '@lucide/vue'
import WorkspaceExportButton from '../../components/ui/WorkspaceExportButton.vue'
import { EmptyState } from '../../components/ui'
import { AppDialog, EmptyState, WorkspaceRefreshButton, WorkspaceSectionHeading } from '../../components/ui'
import WorkspaceActionTooltip from '../../components/ui/WorkspaceActionTooltip.vue'
import ContextNotice from '../../components/ui/ContextNotice.vue'
import { useProjectContext } from '../projects/context'
import { projectsApi } from '../projects/api'
import { workflowCheckpoints } from '../workflows/selectors'
@@ -12,15 +14,23 @@ import { getOperation, isOperationRunning, runOperation } from '../workflows/ope
import ConfirmAction from '../workflows/ConfirmAction.vue'
import { downloadText } from '../../lib/format'
import EpisodeReader from './EpisodeReader.vue'
import { useWorkflowExecution } from '../workflows/execution'
import { executionStageLabel, useWorkflowExecution } from '../workflows/execution'
import WorkflowExecutionPanel from '../workflows/WorkflowExecutionPanel.vue'
import { dramaStages } from './progress'
/** 剧本创作工作区,正式数据库内容为准,checkpoint 只补充计划与恢复信息。 */
const { project, checkpoints, refresh, refreshStageReadiness, error } = useProjectContext()
/** 当前阅读的正式内容标签。 */
const tab = ref('episodes')
/** 任务详情按需查看;关闭弹窗不会停止任务观察。 */
const taskOpen = ref(false)
/** 仅使用创作工作流记录,避免混入拆解或改写候选。 */
const dramaRecords = computed(() => workflowCheckpoints(checkpoints.value, 'create-drama'))
/** 最新保存状态,不回退历史规划或审核。 */
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(() =>
@@ -28,44 +38,99 @@ const targetMinutes = computed(() =>
? 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')
/** 任务读取异常统一交给弹窗展示,页面只保留摘要。 */
const taskError = computed(() => backgroundExecution.discoveryError.value || backgroundExecution.query.error.value)
/** 页面摘要采用明确的任务阶段与项目结果,不从进度比例推断成功。 */
const taskSummary = computed(() => {
const record = backgroundExecution.query.data.value
if (taskError.value) return '任务状态读取异常'
if (record?.status === 'failed') return '创作任务失败'
if (record?.status === 'pending') return '等待开始创作'
if (record?.status === 'running') return executionStageLabel(record.stage)
if (project.value?.status === 'completed') return '剧本创作完成'
if (project.value?.status === 'need_review') return '审核待处理'
return record?.status === 'completed' ? '任务已结束,结果待确认' : '等待状态更新'
})
/** 切换项目时关闭旧项目弹层,不将上个项目的任务界面带入新项目。 */
watch(projectId, () => {
taskOpen.value = false
})
/** 节点事件只触发权威数据重读,不按节点先后次序补造完成状态。 */
watch(
() => backgroundExecution.query.data.value?.status,
(status, previous) => {
if ((status === 'completed' || status === 'failed') && status !== previous)
void Promise.all([refresh(), refreshStageReadiness()])
() => {
const record = backgroundExecution.query.data.value
return record ? ([record.id, record.stage, record.status] as const) : null
},
(record, previous) => {
if (!record || (previous && record.every((value, index) => value === previous[index]))) return
void refresh()
if (record[2] === 'completed' || record[2] === 'failed') void refreshStageReadiness()
}
)
/** 正式项目完成状态独立于任务结束与审核执行状态。 */
const complete = computed(() => project.value?.status === 'completed')
const hasCheckpoint = computed(() => dramaRecords.value.length > 0)
const canGenerate = computed(
/** 当前记录是否包含服务端保存的规划,不在页面验证或重建规划。 */
const hasStoryPlan = computed(() => !!state.value?.storyPlan)
/** 恢复生成只接受连续的正式剧集前缀,允许进入尚未完成的派生设定阶段。 */
const hasEpisodePrefix = computed(
() =>
!complete.value &&
hasCheckpoint.value &&
!!project.value?.characters.length &&
!!project.value?.world &&
(!total.value || episodes.value.length < total.value)
!!total.value &&
episodes.value.length <= total.value &&
episodes.value
.toSorted((a, b) => a.episode - b.episode)
.every((episode, index) => episode.episode === index + 1)
)
/** 有明确审核结论后,应走审核或改写恢复,避免重复生成。 */
const hasReview = computed(() => typeof state.value?.reviewPassed === 'boolean')
/** 生成恢复不再以 Character 或 World 为前置条件,最终仍由服务端复核。 */
const canGenerate = computed(() => !complete.value && hasStoryPlan.value && hasEpisodePrefix.value && !hasReview.value)
/** 只有当前保存记录明确审核未通过,才能恢复改写。 */
const canRewrite = computed(
() =>
!complete.value &&
hasCheckpoint.value &&
!!episodes.value.length &&
(!total.value || episodes.value.length >= total.value)
!!state.value?.review &&
state.value.reviewPassed === false &&
hasEpisodePrefix.value &&
episodes.value.length === total.value
)
/** 任务发现或状态读取异常时,先核对真实状态,禁止重复恢复。 */
const recoveryBlocked = computed(
() =>
operation.value.pending ||
backgroundExecution.active.value ||
backgroundExecution.discovering.value ||
!!backgroundExecution.discoveryError.value ||
!!backgroundExecution.query.error.value ||
!!error.value
)
/** 用后端最新保存输出及当前节点呈现六个阶段。 */
const stages = computed(() =>
dramaStages(project.value, dramaRecords.value.at(-1), backgroundExecution.query.data.value)
)
/** 恢复中不展示旧审核结论,等当前保存记录确认结果。 */
const reviewPassed = computed(() =>
stages.value.find(stage => stage.node === 'reviewDrama')?.status === 'completed'
? state.value?.reviewPassed
: undefined
)
const stages = computed(() => [
{ label: '角色设定', done: !!project.value?.characters.length },
{ label: '世界观', done: !!project.value?.world },
{ label: '编写剧集', done: !!total.value && episodes.value.length >= total.value },
{ label: '审核与改写', done: state.value?.reviewPassed === true },
{ label: '完成', done: complete.value }
])
/** 恢复操作不能以“查看状态”的名义发送,始终在确认后调用。 */
/**
* 确认后提交恢复请求,并继续观察真实任务。
* @param action 后端支持的生成或改写恢复动作
*/
async function resume(action: 'resume-generation' | 'resume-rewrite') {
if (!project.value || operation.value.pending || error.value) return
if (
!project.value ||
recoveryBlocked.value ||
!(action === 'resume-generation' ? canGenerate.value : canRewrite.value)
)
return
const id = project.value.id
await runOperation(id, action === 'resume-generation' ? '恢复剧集生成' : '恢复剧本改写', async () => {
const started = await projectsApi.resume(id, action)
@@ -75,6 +140,17 @@ async function resume(action: 'resume-generation' | 'resume-rewrite') {
await refresh()
}
/** 重读项目、保存记录与任务状态,不启动或恢复生成。 */
async function refreshTask() {
await Promise.all([
refresh(),
backgroundExecution.discoveryError.value || !backgroundExecution.executionId.value
? backgroundExecution.discover()
: Promise.resolve(),
backgroundExecution.executionId.value ? backgroundExecution.query.refresh() : Promise.resolve()
])
}
/** 导出已读取的完整剧集正文;没有剧集时不生成空文件。 */
function exportScript() {
if (!project.value || !episodes.value.length) return
@@ -86,7 +162,7 @@ function exportScript() {
</script>
<template>
<WorkspacePage split compact class="script-workspace-page"
<WorkspacePage split compact class="script-workspace-page" :class="{ 'script-creation-complete': complete }"
><template #header
><div class="stage-strip">
<!-- 以下是创作阶段进度 -->
@@ -95,73 +171,60 @@ function exportScript() {
v-for="(stage, index) in stages"
:key="stage.label"
class="stage-item"
:class="{ done: stage.done }"
:class="{ done: stage.done, 'stage-error': stage.error }"
:data-stage="stage.node"
:data-status="stage.status"
:aria-label="`${stage.label}:${stage.statusLabel}`"
:aria-current="stage.status === 'running' ? 'step' : undefined"
>
<Check v-if="stage.done" :size="15" /><Circle v-else :size="13" /><span>{{ stage.label }}</span
<LoaderCircle v-if="stage.status === 'running'" :size="15" class="animate-spin" />
<CircleAlert v-else-if="stage.error" :size="15" />
<Check v-else-if="stage.done" :size="15" /><Circle v-else :size="13" /><span
>{{ stage.label }} · {{ stage.statusLabel }}</span
><ArrowRight v-if="index < stages.length - 1" :size="13" class="stage-arrow" />
</div>
</div>
</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
<!-- 以下是紧凑任务摘要与入口,详细记录及恢复操作放入弹窗 -->
<div v-if="project" class="script-task-toolbar">
<div
class="script-task-summary flex flex-wrap items-center gap-x-4 gap-y-2 text-xs text-muted"
role="status"
>
<span v-if="targetMinutes !== null">整剧目标约 {{ targetMinutes }} 分钟</span>
</div>
<!-- 以下是唯一的创作任务进度与恢复操作模块,随标题区滚动 -->
<WorkflowExecutionPanel
v-if="backgroundExecution.executionId.value"
title="剧本创作任务"
:execution="backgroundExecution.query.data.value"
:loading="backgroundExecution.query.loading.value"
:error="backgroundExecution.query.error.value"
@refresh="backgroundExecution.query.refresh"
@dismiss="backgroundExecution.dismiss"
/>
<div v-if="!complete" class="mt-5 flex flex-wrap items-center justify-between gap-4">
<p class="text-sm text-muted">
已写入 {{ episodes.length }}<span v-if="total"> / {{ total }}</span> 集<span v-if="!total">
· 等待计划集数</span
>。{{
project?.status === 'generating'
? '剧本仍在生成,请等待状态更新。'
: '如中途停止,可从当前阶段继续。'
}}
</p>
<div class="flex flex-wrap gap-2">
<ConfirmAction
:loading="isOperationRunning(operation, '恢复分集剧本生成') || backgroundExecution.active.value"
label="恢复生成"
description="用于剧集尚未写完的情况。系统会从已保存的角色、世界观和剧集进度继续生成。"
acknowledgement
:disabled="!canGenerate || operation.pending || backgroundExecution.active.value || !!error"
@confirm="resume('resume-generation')"
/><ConfirmAction
:loading="isOperationRunning(operation, '恢复剧本改写') || backgroundExecution.active.value"
label="恢复改写"
description="用于剧集已齐全但审核未通过的情况。系统会从已保存的改写进度继续审核和调整。"
acknowledgement
:disabled="!canRewrite || operation.pending || backgroundExecution.active.value || !!error"
@confirm="resume('resume-rewrite')"
/>
<span
:class="{
'text-danger': taskError || backgroundExecution.query.data.value?.status === 'failed'
}"
>{{ taskSummary }}</span
>
<span
>已写入 {{ episodes.length }}<template v-if="total"> / {{ total }}</template> 集</span
>
<span
>时长规划:{{
project.durationMode === 'auto'
? '自动'
: project.durationMode === 'fixed_episode_count'
? '固定集数'
: '弹性集数'
}}</span
>
<span v-if="targetMinutes !== null">整剧目标约 {{ targetMinutes }} 分钟</span>
</div>
<WorkspaceActionTooltip label="查看创作任务" mobile-only>
<NButton
class="workspace-action-button script-task-button"
size="small"
aria-label="查看创作任务"
aria-haspopup="dialog"
:aria-expanded="taskOpen"
@click="taskOpen = true"
>
<template #icon><ClipboardList :size="15" aria-hidden="true" /></template>
<span class="script-task-button-label">创作任务</span>
</NButton>
</WorkspaceActionTooltip>
</div>
<NProgress
v-if="total && !complete"
aria-label="已写入剧集数量"
type="line"
:show-indicator="false"
:height="4"
:percentage="Math.min(100, Math.max(0, (Math.min(episodes.length, total) / Math.max(1, total)) * 100))"
class="mt-4"
></NProgress>
</template>
<div class="script-section">
<!-- 以下是剧本内容标签与直接导出模块 -->
@@ -183,7 +246,7 @@ function exportScript() {
<EmptyState
v-else
title="剧本正在酝酿"
description="剧集写入数据库后会自动出现在这里,角色与世界观生成期间请等待状态更新。"
description="先规划全剧故事,再展开分集剧本;剧集保存后会自动出现在这里。"
/>
</div>
<NScrollbar v-if="tab !== 'episodes'" class="panel-scroll"
@@ -247,15 +310,15 @@ function exportScript() {
<EmptyState v-else title="尚无世界观" description="世界观会在角色设定之后生成。" />
</div>
<div v-if="tab === 'review'" class="p-6 lg:p-8">
<p v-if="typeof state?.reviewPassed === 'boolean'" class="text-sm">
{{ state.reviewPassed ? '最近工作流审核通过' : '最近工作流审核未通过' }}
<p v-if="typeof reviewPassed === 'boolean'" class="text-sm">
{{ reviewPassed ? '最近工作流审核通过' : '最近工作流审核未通过' }}
</p>
<EmptyState
v-else
title="暂无可用审核结果"
description="工作流返回审核结果后会在这里显示。"
/><NCollapse
v-if="state?.rewriteSuggestion"
v-if="reviewPassed === false && state?.rewriteSuggestion"
class="mt-5 text-sm"
:default-expanded-names="['details']"
><NCollapseItem name="details"
@@ -273,6 +336,90 @@ function exportScript() {
</div>
</div></WorkspacePage
>
<!-- 以下是创作任务弹窗,后台观察独立于弹窗显隐,正文可滚动、底栏固定 -->
<AppDialog
v-model:open="taskOpen"
title="创作任务"
description="查看当前进度与保存记录,需要时继续未完成的创作。"
:width="800"
>
<div v-if="taskOpen" class="script-task-sections">
<WorkflowExecutionPanel
title="剧本创作任务"
:execution="backgroundExecution.query.data.value"
:loading="backgroundExecution.query.loading.value"
:error="taskError"
embedded
@refresh="refreshTask"
/>
<p v-if="!backgroundExecution.query.data.value && !taskError" class="text-sm text-muted">
{{
backgroundExecution.query.loading.value || backgroundExecution.discovering.value
? '正在读取创作任务…'
: '暂无创作任务记录,当前展示已保存的剧本内容。'
}}
</p>
<!-- 以下是独立的剧集保存进度,数量不代表审核通过 -->
<section aria-label="剧集进度">
<WorkspaceSectionHeading title="剧集进度">
<template #actions>
<span class="text-sm text-muted"
>已写入 {{ episodes.length }}<span v-if="total"> / {{ total }}</span> 集</span
>
</template>
</WorkspaceSectionHeading>
</section>
<!-- 以下是缺少规划时的恢复限制,保留真实能力边界 -->
<section
v-if="!complete && !hasStoryPlan && !recoveryBlocked && project?.status !== 'generating'"
aria-label="恢复提示"
>
<ContextNotice type="warning" title="暂不能恢复生成" emphasized>
缺少已保存的故事规划。需要重新生成时,请新建剧本。
</ContextNotice>
</section>
<!-- 以下是默认收起的技术详情,不与日常进度和恢复提示混排 -->
<NCollapse v-if="backgroundExecution.query.data.value" class="text-sm text-muted">
<NCollapseItem name="task-details" title="高级详情">
<dl class="grid gap-2 pt-2">
<dt class="text-xs text-muted">任务编号</dt>
<dd class="break-all font-mono text-xs leading-6">
{{ backgroundExecution.query.data.value.id }}
</dd>
</dl>
</NCollapseItem>
</NCollapse>
</div>
<!-- 以下是固定底栏,恢复操作继续使用原有费用与任务停止确认 -->
<template #footer>
<div class="script-task-footer">
<NButton @click="taskOpen = false">关闭</NButton>
<WorkspaceRefreshButton
label="刷新状态"
:loading="backgroundExecution.query.loading.value || backgroundExecution.discovering.value"
@refresh="refreshTask"
/>
<template v-if="!complete">
<ConfirmAction
:loading="isOperationRunning(operation, '恢复剧集生成')"
label="恢复生成"
description="从已保存的故事规划继续编写剧集,再生成角色设定、世界观并审核。已有完整剧集时会核对来源并继续未完成的设定。可能产生模型调用费用。"
acknowledgement
:disabled="!canGenerate || recoveryBlocked"
@confirm="resume('resume-generation')"
/><ConfirmAction
:loading="isOperationRunning(operation, '恢复剧本改写')"
label="恢复改写"
description="用于当前审核明确未通过的情况。系统会核对已保存的审核与剧集来源,继续改写和审核。可能产生模型调用费用。"
acknowledgement
:disabled="!canRewrite || recoveryBlocked"
@confirm="resume('resume-rewrite')"
/>
</template>
</div>
</template>
</AppDialog>
</template>
<style>
@@ -306,12 +453,15 @@ function exportScript() {
.stage-item.done {
@apply text-ink;
}
.stage-item.stage-error {
color: var(--app-danger);
}
.stage-arrow {
@apply ml-3 text-muted;
}
@media (max-width: 760px) {
/* 手机直接通过内容 Tab 查看结果,隐藏重复的流程进度行以增加正文空间。 */
.script-workspace-page .stage-strip {
/* 生成期间手机仍可查看规划和节点状态;完成后保留正文阅读空间。 */
.script-workspace-page.script-creation-complete .stage-strip {
display: none;
}
}
@@ -367,10 +517,6 @@ function exportScript() {
/* 标签栏下方使用与页面上方相同的模块间距。 */
margin-top: var(--app-content-gap);
}
/* 任务详情与恢复操作在有界提示区滚动,为正文保留可用高度。 */
.script-workspace-page .workspace-heading-scroll {
max-height: min(40dvh, 320px);
}
.script-workspace-page .workspace-heading {
display: flex;
flex-direction: column;
@@ -380,4 +526,34 @@ function exportScript() {
margin-block: 0;
flex-shrink: 0;
}
/* 页面只保留一行任务摘要,窄屏自然换行,不挤占剧本阅读区域。 */
.script-task-toolbar {
@apply flex items-center justify-between gap-3;
}
.script-task-summary {
@apply min-w-0 flex-1;
}
/* 弹窗操作按可用宽度换行,所有关闭、刷新和恢复入口始终可见。 */
.script-task-footer {
@apply flex w-full flex-wrap items-center justify-end gap-2;
}
/* 按信息层级分组,状态、保存进度和恢复提示之间使用统一的双倍模块间距。 */
.script-task-sections {
display: grid;
gap: calc(var(--app-content-gap) * 2);
}
@media (max-width: 639px) {
.script-task-button-label {
display: none;
}
.n-button.script-task-button {
width: 40px;
height: 40px;
min-width: 40px;
padding: 0;
}
.script-task-button .n-button__icon {
margin: 0;
}
}
</style>
+90
View File
@@ -0,0 +1,90 @@
import type { ProjectDetail } from '../projects/types'
import type { WorkflowExecution, WorkflowExecutionStatus } from '../workflows/execution.types'
import type { Checkpoint } from '../workflows/types'
/** 创作阶段的只读展示,状态沿用服务端执行枚举,未知时保留空值。 */
export interface DramaStage {
/** 正式工作流节点。 */
node: string
/** 中文阶段名称。 */
label: string
/** 来自执行记录或已保存输出的状态。 */
status: WorkflowExecutionStatus | null
/** 面向用户的阶段说明。 */
statusLabel: string
/** 当前阶段是否明确审核通过或保存完成。 */
done: boolean
/** 节点失败或审核未通过,需要使用错误样式。 */
error: boolean
}
/** 创作流程展示顺序只用于排版,不能按位置补齐前序节点的成功状态。 */
const nodes = [
['generateStoryPlan', '故事规划'],
['generateEpisode', '编写剧集'],
['generateCharacter', '角色设定'],
['generateWorld', '世界观'],
['reviewDrama', '审核与改写'],
['finishProject', '完成']
] as const
/** 改写相关节点归入已有审核阶段,不影响其它节点的状态。 */
const reviewNodes = ['reviewDrama', 'generateRewriteSuggestion', 'rewrite', 'resumeRewrite']
/**
* 合并当前执行与最新保存记录,既不由节点顺序推断成功,也不复用新任务之前的旧审核结果。
* @param project 正式项目详情
* @param checkpoint 当前创作工作流的最新保存记录
* @param execution 当前持久化任务
* @returns 各阶段的只读展示
*/
export function dramaStages(
project: ProjectDetail | null,
checkpoint: Checkpoint | undefined,
execution: WorkflowExecution | null
): DramaStage[] {
const state = checkpoint?.state
const currentSnapshot =
!execution ||
(!!checkpoint && Date.parse(checkpoint.createdAt) >= Date.parse(execution.startedAt ?? execution.createdAt))
const saved = currentSnapshot ? state : undefined
const count = project?.episodeCount ?? saved?.episodeCount
const completed: Record<string, boolean> = {
// 恢复服务明确复用最新保存记录中的规划;不从 Episode、Character 或执行顺序反推规划成功。
generateStoryPlan:
!!state?.storyPlan &&
(currentSnapshot ||
execution?.metadata?.action === 'resume-generation' ||
execution?.metadata?.action === 'resume-rewrite'),
generateEpisode: !!count && (saved?.episodes?.length ?? 0) >= count,
generateCharacter: !!saved?.characters,
generateWorld: !!saved?.world,
reviewDrama: typeof saved?.reviewPassed === 'boolean',
finishProject: project?.status === 'completed'
}
return nodes.map(([node, label]) => {
const current =
execution?.stage === node || (node === 'reviewDrama' && reviewNodes.includes(execution?.stage ?? ''))
const status: WorkflowExecutionStatus | null =
current && execution?.status !== 'completed'
? (execution?.status ?? null)
: completed[node]
? 'completed'
: execution && ['pending', 'running'].includes(execution.status)
? 'pending'
: null
const rejected = node === 'reviewDrama' && status === 'completed' && saved?.reviewPassed === false
return {
node,
label,
status,
statusLabel: rejected
? '未通过'
: status === null
? '待确认'
: { pending: '等待更新', running: '进行中', completed: '已完成', failed: '失败' }[status],
done: status === 'completed' && !rejected,
error: status === 'failed' || rejected
}
})
}
+2 -1
View File
@@ -66,7 +66,8 @@ watch(id, () => {
generationRevision.value = 0
})
const operation = computed(() => getOperation(id.value))
const createDramaExecution = useWorkflowExecution(id, 'create-drama')
/** 从服务端发现创作任务,刷新或换浏览器后也能继续观察故事规划等节点。 */
const createDramaExecution = useWorkflowExecution(id, 'create-drama', { discover: true })
/** 项目内跨页面继续观察首帧后台任务,维持活动锁并在真实终态后释放。 */
useWorkflowExecution(id, 'keyframe-quality')
/** 既有生成入口在跨页面时继续观察,保持项目活动锁。 */
@@ -125,7 +125,7 @@ const rules = computed(() => ({
<AppDrawer
v-model:open="open"
title="新建剧本"
description="从一个故事想法开始。提交后,工作流将依次生成角色、世界观和剧集,并进行审核。"
description="从一个故事想法开始。提交后,先规划全剧故事,再编写分集剧本、生成角色设定与世界观,最后审核。"
:busy="busy"
class="create-project-drawer"
>
+14
View File
@@ -97,11 +97,25 @@ export interface ProjectDetail extends Project {
/** Create Drama checkpoint 中页面使用的状态切片。 */
export interface DramaState {
/** 服务端已校验并保存的整剧规划;页面只读取其存在性,不复制规划校验规则。 */
storyPlan?: unknown
/** 保存记录中的派生角色结果,正式展示仍读取项目详情。 */
characters?: unknown
/** 保存记录中的派生世界观结果,正式展示仍读取项目详情。 */
world?: unknown
/** 服务端保存的审核结果,用于确认是否存在可恢复的审核来源。 */
review?: unknown
/** 服务端确认的计划集数。 */
episodeCount?: number
/** 当前保存记录中的完整剧集正文。 */
episodes?: Episode[]
/** 已执行的改写次数。 */
retryCount?: number
/** 当前审核是否明确通过,缺失表示尚无结论。 */
reviewPassed?: boolean
/** 当前保存的改写建议。 */
rewriteSuggestion?: unknown
/** 当前保存的定向改写计划。 */
rewritePlan?: unknown
}
+100 -29
View File
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { userFacingText } from '../../lib/user-facing-text'
import ContextNotice from '../../components/ui/ContextNotice.vue'
import WorkspaceSectionHeading from '../../components/ui/WorkspaceSectionHeading.vue'
import { computed } from 'vue'
import { NButton, NCollapse, NCollapseItem, NProgress, NTag } from 'naive-ui'
@@ -22,8 +23,10 @@ const props = withDefaults(
error: string
/** 是否展示运行、完成和错误详情;关闭后由调用方单独呈现问题。 */
showStatusHint?: boolean
/** 嵌入弹窗时使用扁平正文,标题、关闭及刷新操作由外层统一提供。 */
embedded?: boolean
}>(),
{ title: '制作任务', showStatusHint: true }
{ title: '制作任务', showStatusHint: true, embedded: false }
)
/** 刷新状态与隐藏任务记录事件。 */
const emit = defineEmits<{ refresh: []; dismiss: [] }>()
@@ -82,6 +85,10 @@ const progressLabel = computed(() =>
const statusLabel = computed(() => {
const labels = { pending: '等待开始', running: '执行中', completed: '已完成', failed: '失败' }
if (!props.execution) return ''
if (scriptCreation.value && props.execution.status === 'completed') {
if (result.value.projectStatus === 'need_review') return '执行结束 · 待修订'
if (result.value.projectStatus !== 'completed') return '执行结束 · 结果待确认'
}
if (breakdownTask.value && props.execution.status === 'completed') {
if (breakdownInvalid.value) return '执行结束 · 校验未通过'
if (breakdownNeedsReview.value) return '执行结束 · 待修订'
@@ -104,6 +111,12 @@ const staleMotionPlanCount = computed(() => {
})
/** 业务未通过或结果未知时,不把任务执行结束展示为全成功。 */
const statusType = computed(() => {
if (scriptCreation.value && props.execution?.status === 'completed')
return result.value.projectStatus === 'completed'
? 'success'
: result.value.projectStatus === 'need_review'
? 'warning'
: 'default'
if (diagnosisTask.value)
return props.execution?.status === 'failed'
? 'error'
@@ -199,15 +212,14 @@ function isInputMode(value: unknown, inputMode: string): boolean {
<template>
<section
v-if="execution || error"
class="panel mt-4 p-5"
:class="{ 'breakdown-execution-card': breakdownTask }"
:class="[embedded ? '' : 'panel mt-4 p-5', { 'breakdown-execution-card': breakdownTask }]"
:data-task-state="breakdownTask ? breakdownState : undefined"
:aria-label="title"
>
<div class="flex flex-wrap items-start justify-between gap-3">
<div v-if="!embedded" class="flex flex-wrap items-start justify-between gap-3">
<div>
<div class="flex flex-wrap items-center gap-2">
<h3 class="text-sm font-semibold">{{ title }}</h3>
<h3 v-if="!embedded" class="text-sm font-semibold">{{ title }}</h3>
<LoaderCircle v-if="!finished" :size="14" class="animate-spin text-muted" aria-hidden="true" />
<NTag v-if="execution" size="small" :type="statusType" :bordered="false">{{ statusLabel }}</NTag>
</div>
@@ -218,7 +230,7 @@ function isInputMode(value: unknown, inputMode: string): boolean {
</div>
<div class="flex items-center gap-2">
<NButton
v-if="finished || error"
v-if="!embedded && (finished || error)"
class="icon-button"
quaternary
aria-label="隐藏制作任务记录"
@@ -229,6 +241,33 @@ function isInputMode(value: unknown, inputMode: string): boolean {
</div>
</div>
<!-- 以下是弹窗内的任务状态与简洁元信息,用标题和对齐区分说明层级 -->
<template v-else>
<WorkspaceSectionHeading title="任务状态">
<template #actions>
<NTag v-if="execution" size="small" :type="statusType" :bordered="false">{{ statusLabel }}</NTag>
</template>
</WorkspaceSectionHeading>
<dl v-if="execution" class="mt-4 grid grid-cols-2 gap-x-6 gap-y-4">
<div v-if="!finished" class="col-span-2">
<dt class="text-xs text-muted">当前阶段</dt>
<dd class="mt-2 flex items-center gap-2 text-sm">
<LoaderCircle :size="14" class="animate-spin text-muted" aria-hidden="true" />{{
executionStageLabel(execution.stage)
}}
</dd>
</div>
<div>
<dt class="text-xs text-muted">更新时间</dt>
<dd class="mt-2 text-sm">{{ formatDate(execution.updatedAt) }}</dd>
</div>
<div>
<dt class="text-xs text-muted">处理范围</dt>
<dd class="mt-2 text-sm">{{ scopeLabel || '未提供范围' }}</dd>
</div>
</dl>
</template>
<template v-if="execution">
<!-- 以下是拆解任务的直接可见摘要,替代折叠详情和重复进度说明 -->
<dl v-if="breakdownTask" class="mt-4 grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-2 xl:grid-cols-4">
@@ -256,11 +295,12 @@ function isInputMode(value: unknown, inputMode: string): boolean {
v-if="execution.total > 0 && ((!breakdownTask && !diagnosisTask) || !finished)"
type="line"
:percentage="percentage"
:color="scriptCreation && result.projectStatus !== 'completed' ? 'var(--app-muted)' : undefined"
:height="5"
:show-indicator="false"
class="mt-4"
/>
<p v-if="!breakdownTask" class="mt-3 text-xs">
<p v-if="!breakdownTask && (!embedded || execution.total > 0)" class="mt-3 text-xs">
<template v-if="execution.total > 0"
>{{ progressLabel }} {{ execution.current }} / {{ execution.total }}</template
>
@@ -270,7 +310,9 @@ function isInputMode(value: unknown, inputMode: string): boolean {
: breakdownTask
? '拆解进行中,等待下一阶段结果'
: scriptCreation
? '正在创作剧本'
? execution.status === 'pending'
? '等待开始创作剧本'
: '正在创作剧本'
: '正在准备本次任务'
}}</template>
<template v-if="execution.currentResourceId && !scriptCreation && !breakdownTask">
@@ -280,7 +322,9 @@ function isInputMode(value: unknown, inputMode: string): boolean {
<ContextNotice
v-if="execution.status === 'running' && showStatusHint"
type="info"
:show-icon="false"
:show-icon="embedded"
:emphasized="embedded"
:title="embedded ? '任务进行中' : undefined"
class="mt-3"
>
{{
@@ -290,24 +334,40 @@ function isInputMode(value: unknown, inputMode: string): boolean {
<ContextNotice
v-else-if="execution.status === 'completed' && showStatusHint"
:type="
diagnosisTask
? 'info'
: breakdownInvalid
? 'warning'
: keyframeEdit
? result.passed === true
? 'success'
: result.validationSkipped === true
? 'info'
: 'warning'
: videoQuality && staleMotionPlanCount > 0
scriptCreation
? result.projectStatus === 'completed'
? 'success'
: result.projectStatus === 'need_review'
? 'warning'
: keyframeQuality &&
(!keyframeCounts || keyframeCounts.repairFailed + keyframeCounts.failed > 0)
: 'info'
: diagnosisTask
? 'info'
: breakdownInvalid
? 'warning'
: keyframeEdit
? result.passed === true
? 'success'
: result.validationSkipped === true
? 'info'
: 'warning'
: videoQuality && staleMotionPlanCount > 0
? 'warning'
: 'success'
: keyframeQuality &&
(!keyframeCounts || keyframeCounts.repairFailed + keyframeCounts.failed > 0)
? 'warning'
: 'success'
"
:show-icon="embedded"
:emphasized="embedded"
:title="
embedded
? scriptCreation && result.projectStatus === 'need_review'
? '审核仍需处理'
: scriptCreation && result.projectStatus !== 'completed'
? '结果待确认'
: '任务已完成'
: undefined
"
:show-icon="false"
class="mt-3"
>
<p>
@@ -317,7 +377,9 @@ function isInputMode(value: unknown, inputMode: string): boolean {
: breakdownTask
? '剧本拆解已结束,请查看候选与校验结果。'
: scriptCreation
? '剧本创作任务已结束,可查看最新剧本内容。'
? result.projectStatus === 'need_review'
? '剧本创作任务已结束,审核仍需处理,请查看当前审核结果。'
: '剧本创作任务已结束,可查看最新剧本内容。'
: '本轮任务已结束,可查看最新镜头资产状态。'
}}
</p>
@@ -361,7 +423,9 @@ function isInputMode(value: unknown, inputMode: string): boolean {
<ContextNotice
v-else-if="execution.status === 'failed' && showStatusHint"
type="error"
:show-icon="false"
:show-icon="embedded"
:emphasized="embedded"
:title="embedded ? '任务未完成' : undefined"
class="mt-3"
>
<p>{{ userFacingText(execution.error) || '制作任务执行失败。' }}</p>
@@ -395,7 +459,7 @@ function isInputMode(value: unknown, inputMode: string): boolean {
</p>
</div>
<!-- 以下是非拆解任务的 Naive 详情折叠模块 -->
<NCollapse v-if="!breakdownTask" class="mt-3 text-xs text-muted">
<NCollapse v-if="!breakdownTask && !embedded" class="mt-3 text-xs text-muted">
<NCollapseItem name="task-details" title="任务详情">
<p class="mt-2 break-all font-mono">任务编号 · {{ execution.id }}</p>
<!-- 以下是逐镜已结束质量任务的持久化状态模块 -->
@@ -420,9 +484,16 @@ function isInputMode(value: unknown, inputMode: string): boolean {
>
动作版本过期 {{ staleMotionPlanCount }} · 这些候选已停止质量流程,其余镜头继续处理。
</p>
<ContextNotice v-if="error" type="error" :show-icon="false" class="mt-3">
<ContextNotice
v-if="error"
type="error"
:show-icon="embedded"
:emphasized="embedded"
:title="embedded ? '状态读取失败' : undefined"
class="mt-3"
>
{{ error }}。任务可能仍在运行,请先重新读取状态;不要直接重复提交。
<NButton text class="ml-3" :loading="loading" @click="emit('refresh')">重试读取</NButton>
<NButton v-if="!embedded" text class="ml-3" :loading="loading" @click="emit('refresh')">重试读取</NButton>
</ContextNotice>
</section>
</template>
+3 -1
View File
@@ -48,14 +48,16 @@ export function executionStageLabel(stage: string | null) {
if (!stage) return '等待任务开始'
const labels: Record<string, string> = {
createProject: '初始化项目',
generateStoryPlan: '生成故事规划',
generateCharacter: '生成角色设定',
generateWorld: '生成世界观',
generateEpisode: '生成分集剧本',
buildActionSnapshots: '整理剧本动作记录',
reviewDrama: '审核剧本',
generateRewriteSuggestion: '生成改写建议',
rewrite: '改写剧本',
finishProject: '完成剧本创作',
resumeGeneration: '恢复分集剧本生成',
resumeGeneration: '恢复剧本创作',
resumeRewrite: '恢复剧本改写',
breakdown: '拆解剧本',
subject_ready: '主体已整理完成',