feat(short-drama-agent-front): 适配故事规划并优化任务弹窗
This commit is contained in:
1 parent
48fce3975f
commit
5836b90934
12 files changed
+960
-133
No files matched your search
@@ -1,5 +1,21 @@
|
||||
# 接口数据同步说明
|
||||
|
||||
## 2026-10-28 Story Plan 创作流程适配
|
||||
|
||||
核对同级后端 `dev@c6ad973c` 的项目创建路由、创作 Graph、节点保存中间件、恢复服务和任务订阅;只修改前端根目录 `dev`。
|
||||
|
||||
- 正式顺序为故事规划 → 分集剧本 → 角色设定 → 世界观 → 动作记录整理 → 审核/改写。页面复用原阶段条与任务面板,动作记录整理显示在任务当前阶段,不新增独立业务步骤。
|
||||
- `POST /projects` 请求和 202 回执未变。继续发送标题、主题、风格及原有时长预算,复用全部创建输入组件与默认值,只更新顺序说明。
|
||||
- 不存在 Story Plan 独立查询接口。读取现有项目详情、`GET /projects/:id/checkpoints`、项目级 `workflow-executions/latest|events` 和按任务编号查询接口;规划是否已保存仅来自最新创作记录的 `state.storyPlan`,不从后续节点顺序推断、不回退历史规划、不在页面复制规划校验。
|
||||
- 项目布局开启创作任务发现;页面在任务编号、节点或执行状态变化后重读项目与保存记录。SSE 使用完整持久化任务,不按旧节点序号过滤。刷新、直接进入及服务端另行启动均复用原发现能力。
|
||||
- 新执行开始前的旧审核、角色和世界观不用于完成当前节点。`resume-generation` 仍可沿用最新保存规划,但派生设定与审核等待本次保存记录确认。完整剧集的派生阶段失败也可恢复生成;有当前审核结论时停止生成恢复,明确未通过且有审核来源才开放原有改写恢复。连续剧集前缀、费用确认及项目活动锁保留。
|
||||
- 任务执行完成和审核通过分别展示。任务 `result.projectStatus=need_review` 使用待修订样式,缺少结论保持待确认;不会仅因 HTTP 成功或任务结束标绿。
|
||||
- 创作页只保留阶段、摘要与入口,详细状态和恢复操作放入公共 `AppDialog`。弹窗按任务状态、剧集进度与恢复提示分组,编号放在默认收起的高级详情;固定底栏集中关闭、只读刷新及原有费用确认。关闭弹窗不停止任务观察,状态读取失败也可以关闭并重读。
|
||||
- 注意事项复用 `ContextNotice` 的按需强调样式:项目主题的中性底面、图标与短标题突出待处理和恢复受限说明;普通信息继续以留白分组。明确失败或成功仅复用项目既有状态色,并进一步降低底面强度;深浅主题自动同步,不把待审或结果未知标为绿色成功。
|
||||
- 当前后端失败回执把 `stage` 统一改成 `failed`,恢复生成也只有整体 `resumeGeneration` 阶段,未持久化逐节点失败状态。页面显示任务失败与明确保存的结果,无法确认的具体节点保持待确认;缺少规划时没有独立规划恢复入口,提示新建重试,不虚构 API 或猜测失败节点。
|
||||
|
||||
浏览器验收使用已有本地 Chrome 标签页与 `localhost:4312` 隔离样例接口;样例与临时服务位于 `/tmp`,不进入产品代码,不连接真实生成服务。真实模型、正式数据写入及付费端到端生成不在本次验收范围。
|
||||
|
||||
## 2026-10-19 导航修复复核与配置冲突同步
|
||||
|
||||
后端基线 `dev@6a6fd52d`,前端根目录 dev;保留已有未提交工作,不修改后端、不提交或推送。
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -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"
|
||||
>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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: '主体已整理完成',
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import CreateDramaPage from '@/features/create-drama/CreateDramaPage.vue'
|
||||
import { projectContextKey } from '@/features/projects/context'
|
||||
import { workflowExecutionApi } from '@/features/workflows/execution-api'
|
||||
import type { WorkflowExecution } from '@/features/workflows/execution.types'
|
||||
import type { Checkpoint } from '@/features/workflows/types'
|
||||
import { testProjectContext } from '@/testing/project-context'
|
||||
import AppDialog from '@/components/ui/AppDialog.vue'
|
||||
import { projectsApi } from '@/features/projects/api'
|
||||
|
||||
/** 服务端已校验并保存的规划;前端不重新执行规划业务校验。 */
|
||||
const storyPlan = {
|
||||
premise: '一封信改变命运',
|
||||
episodeCount: 1,
|
||||
entities: [],
|
||||
episodes: [
|
||||
{
|
||||
episode: 1,
|
||||
goal: '找到寄信人',
|
||||
events: [{ id: 'event-1', description: '收到来信', entityIds: [], prerequisites: [], outcome: '开始调查' }],
|
||||
openQuestions: []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造持久化任务,不连接真实模型。
|
||||
* @param projectId 所属项目
|
||||
* @param overrides 当前状态覆盖
|
||||
* @returns 真实任务查询结构
|
||||
*/
|
||||
function execution(projectId: string, overrides: Partial<WorkflowExecution> = {}): WorkflowExecution {
|
||||
return {
|
||||
id: `task-${projectId}`,
|
||||
projectId,
|
||||
workflowName: 'create-drama',
|
||||
status: 'running',
|
||||
stage: 'generateStoryPlan',
|
||||
current: 0,
|
||||
total: 0,
|
||||
currentResourceId: projectId,
|
||||
metadata: {},
|
||||
result: null,
|
||||
error: null,
|
||||
startedAt: '2026-10-28T00:00:00Z',
|
||||
completedAt: null,
|
||||
createdAt: '2026-10-28T00:00:00Z',
|
||||
updatedAt: '2026-10-28T00:01:00Z',
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按节点完成后持久化的契约构造保存记录。
|
||||
* @param state 保存的状态
|
||||
* @param nodeName 保存节点
|
||||
* @returns 创作保存记录
|
||||
*/
|
||||
function checkpoint(state: Checkpoint['state'], nodeName = 'generateStoryPlan'): Checkpoint {
|
||||
return {
|
||||
checkpointId: `cp-${nodeName}`,
|
||||
workflowName: 'create-drama',
|
||||
createdAt: '2026-10-28T00:00:30Z',
|
||||
metadata: { nodeName },
|
||||
state
|
||||
}
|
||||
}
|
||||
|
||||
/** 测试持有的页面与项目上下文。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
let context: ReturnType<typeof testProjectContext>
|
||||
|
||||
/**
|
||||
* 挂载真实创作页并读取指定的持久化任务。
|
||||
* @param task 任务查询结果
|
||||
* @returns 当前页面
|
||||
*/
|
||||
async function open(task: WorkflowExecution | null) {
|
||||
if (task) {
|
||||
localStorage.setItem(`short-drama:workflow-execution:${task.projectId}:create-drama`, task.id)
|
||||
vi.spyOn(workflowExecutionApi, 'get').mockResolvedValue(task)
|
||||
}
|
||||
wrapper = mount(CreateDramaPage, {
|
||||
attachTo: document.body,
|
||||
global: { provide: { [projectContextKey as symbol]: context } }
|
||||
})
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* 从页面入口打开真实任务弹窗。
|
||||
* @param page 当前创作页面
|
||||
* @returns 挂载到弹层的任务内容
|
||||
*/
|
||||
async function openTask(page = wrapper!) {
|
||||
await page.get('button[aria-label="查看创作任务"]').trigger('click')
|
||||
await flushPromises()
|
||||
return new DOMWrapper(document.querySelector<HTMLElement>('.app-dialog[aria-label="创作任务"]')!)
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
localStorage.clear()
|
||||
document.body.innerHTML = ''
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
describe('故事规划创作进度与恢复', () => {
|
||||
it('页面仅保留摘要和入口,任务与恢复说明按需进入弹窗且操作都在固定底栏', async () => {
|
||||
context = testProjectContext('compact-task')
|
||||
context.data.value!.project.status = 'failed'
|
||||
const resume = vi.spyOn(projectsApi, 'resume')
|
||||
const page = await open(
|
||||
execution(context.project.value!.id, { status: 'failed', stage: 'failed', error: '验收任务中断' })
|
||||
)
|
||||
expect(page.get('.script-task-summary').text()).toContain('创作任务失败')
|
||||
expect(page.text()).not.toContain('验收任务中断')
|
||||
expect(page.find('[aria-label="剧本创作任务"]').exists()).toBe(false)
|
||||
const dialog = await openTask(page)
|
||||
expect(dialog.text()).toContain('验收任务中断')
|
||||
expect(dialog.text()).toContain('缺少已保存的故事规划')
|
||||
expect(dialog.find('button[aria-label="隐藏制作任务记录"]').exists()).toBe(false)
|
||||
const footer = dialog.get('.dialog-footer')
|
||||
expect(footer.find('button[aria-label="恢复生成"]').exists()).toBe(true)
|
||||
expect(footer.find('button[aria-label="恢复改写"]').exists()).toBe(true)
|
||||
const close = footer.findAll('button').find(item => item.text() === '关闭')!
|
||||
expect(close.exists()).toBe(true)
|
||||
await close.trigger('click')
|
||||
await flushPromises()
|
||||
expect(page.getComponent(AppDialog).props('open')).toBe(false)
|
||||
expect(resume).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('运行中也能关闭任务弹窗,关闭后继续观察且重开显示新阶段', async () => {
|
||||
vi.useFakeTimers()
|
||||
context = testProjectContext('close-active-task')
|
||||
context.data.value!.project.status = 'generating'
|
||||
const task = execution(context.project.value!.id)
|
||||
const page = await open(task)
|
||||
const dialog = await openTask(page)
|
||||
await dialog
|
||||
.get('.dialog-footer')
|
||||
.findAll('button')
|
||||
.find(item => item.text() === '关闭')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(page.getComponent(AppDialog).props('open')).toBe(false)
|
||||
vi.mocked(workflowExecutionApi.get).mockResolvedValue({
|
||||
...task,
|
||||
stage: 'generateEpisode',
|
||||
updatedAt: '2026-10-28T00:02:00Z'
|
||||
})
|
||||
await vi.advanceTimersByTimeAsync(1600)
|
||||
await flushPromises()
|
||||
expect(page.get('.script-task-summary').text()).toContain('生成分集剧本')
|
||||
const reopened = await openTask(page)
|
||||
expect(reopened.text()).toContain('生成分集剧本')
|
||||
expect(reopened.get('button[aria-label="恢复生成"]').attributes('disabled')).toBeDefined()
|
||||
})
|
||||
|
||||
it('状态读取失败仍可关闭,通过底栏刷新重读后清除旧错误且不恢复生成', async () => {
|
||||
context = testProjectContext('task-read-error')
|
||||
context.data.value!.project.status = 'generating'
|
||||
const task = execution(context.project.value!.id)
|
||||
const page = await open(task)
|
||||
const dialog = await openTask(page)
|
||||
vi.mocked(workflowExecutionApi.get).mockRejectedValueOnce(new Error('任务读取暂时失败'))
|
||||
const refresh = dialog
|
||||
.get('.dialog-footer')
|
||||
.findAll('button')
|
||||
.find(item => item.text() === '刷新状态')!
|
||||
await refresh.trigger('click')
|
||||
await flushPromises()
|
||||
expect(dialog.text()).toContain('任务读取暂时失败')
|
||||
expect(page.get('.script-task-summary').text()).toContain('任务状态读取异常')
|
||||
expect(dialog.findAll('button').filter(item => item.text() === '关闭')).toHaveLength(1)
|
||||
expect(dialog.findAll('button').some(item => item.text() === '重试读取')).toBe(false)
|
||||
vi.mocked(workflowExecutionApi.get).mockResolvedValue({
|
||||
...task,
|
||||
stage: 'generateEpisode',
|
||||
updatedAt: '2026-10-28T00:02:00Z'
|
||||
})
|
||||
await refresh.trigger('click')
|
||||
await flushPromises()
|
||||
expect(dialog.text()).not.toContain('任务读取暂时失败')
|
||||
expect(page.get('.script-task-summary').text()).toContain('生成分集剧本')
|
||||
})
|
||||
it.each(['generateEpisode', 'generateCharacter', 'generateWorld', 'reviewDrama'])(
|
||||
'采用服务端当前 %s 节点,不把其它阶段顺带标为完成',
|
||||
async stage => {
|
||||
context = testProjectContext(`current-${stage}`)
|
||||
context.data.value!.project.status = 'generating'
|
||||
context.data.value!.project.episodes = []
|
||||
const page = await open(execution(context.project.value!.id, { stage }))
|
||||
expect(page.get(`[data-stage="${stage}"]`).attributes('data-status')).toBe('running')
|
||||
expect(page.findAll('.stage-item').some(item => item.classes().includes('done'))).toBe(false)
|
||||
}
|
||||
)
|
||||
it.each(['pending', 'running'] as const)('规划节点采用任务的 %s 状态,后续节点不抢先完成', async status => {
|
||||
context = testProjectContext(`plan-${status}`)
|
||||
context.data.value!.project.status = 'generating'
|
||||
context.data.value!.project.episodes = []
|
||||
const page = await open(execution(context.project.value!.id, { status }))
|
||||
const stages = page.findAll('.stage-item')
|
||||
expect(stages.map(item => item.attributes('data-stage'))).toEqual([
|
||||
'generateStoryPlan',
|
||||
'generateEpisode',
|
||||
'generateCharacter',
|
||||
'generateWorld',
|
||||
'reviewDrama',
|
||||
'finishProject'
|
||||
])
|
||||
expect(stages[0]!.attributes('data-status')).toBe(status)
|
||||
expect(stages.slice(1).every(item => item.attributes('data-status') !== 'completed')).toBe(true)
|
||||
})
|
||||
|
||||
it('真实失败回执只报告整体失败时,不猜测具体失败节点', async () => {
|
||||
context = testProjectContext('plan-failed-unknown')
|
||||
context.data.value!.project.status = 'failed'
|
||||
context.data.value!.project.episodes = []
|
||||
const page = await open(
|
||||
execution(context.project.value!.id, { status: 'failed', stage: 'failed', error: '故事规划生成中断' })
|
||||
)
|
||||
const dialog = await openTask(page)
|
||||
expect(dialog.get('[aria-label="剧本创作任务"]').text()).toContain('故事规划生成中断')
|
||||
expect(page.get('[data-stage="generateStoryPlan"]').attributes('data-status')).toBeUndefined()
|
||||
expect(page.findAll('.stage-item').every(item => !item.classes().includes('done'))).toBe(true)
|
||||
})
|
||||
|
||||
it('刷新后从当前保存规划恢复完成状态,剧集生成不依赖角色或世界观', async () => {
|
||||
context = testProjectContext('plan-saved')
|
||||
context.data.value!.project.status = 'failed'
|
||||
context.data.value!.project.episodes = []
|
||||
context.data.value!.checkpoints = [checkpoint({ storyPlan, episodeCount: 1 })]
|
||||
const page = await open(execution(context.project.value!.id, { status: 'failed', stage: 'failed' }))
|
||||
const dialog = await openTask(page)
|
||||
expect(page.get('[data-stage="generateStoryPlan"]').attributes('data-status')).toBe('completed')
|
||||
expect(page.get('[data-stage="generateEpisode"]').attributes('data-status')).toBeUndefined()
|
||||
expect(dialog.get('button[aria-label="恢复生成"]').attributes('disabled')).toBeUndefined()
|
||||
expect(dialog.get('button[aria-label="恢复改写"]').attributes('disabled')).toBeDefined()
|
||||
})
|
||||
|
||||
it('派生设定失败且正式剧集已齐全时仍允许恢复生成,不误开恢复改写', async () => {
|
||||
context = testProjectContext('derive-failed')
|
||||
context.data.value!.project.status = 'failed'
|
||||
context.data.value!.checkpoints = [
|
||||
checkpoint({ storyPlan, episodes: context.project.value!.episodes, episodeCount: 1 }, 'generateEpisode')
|
||||
]
|
||||
const page = await open(execution(context.project.value!.id, { status: 'failed', stage: 'failed' }))
|
||||
const dialog = await openTask(page)
|
||||
expect(page.get('[data-stage="generateEpisode"]').attributes('data-status')).toBe('completed')
|
||||
expect(page.get('[data-stage="generateCharacter"]').attributes('data-status')).toBeUndefined()
|
||||
expect(dialog.get('button[aria-label="恢复生成"]').attributes('disabled')).toBeUndefined()
|
||||
expect(dialog.get('button[aria-label="恢复改写"]').attributes('disabled')).toBeDefined()
|
||||
})
|
||||
|
||||
it('恢复期间不以旧保存记录或数据库设定把当前节点及审核标为完成', async () => {
|
||||
context = testProjectContext('resume-new')
|
||||
context.data.value!.project.status = 'generating'
|
||||
context.data.value!.project.characters = [{ id: 'old', name: '旧角色' }]
|
||||
context.data.value!.project.world = { era: '旧世界观' }
|
||||
context.data.value!.checkpoints = [
|
||||
{
|
||||
...checkpoint({ storyPlan, reviewPassed: true, episodes: context.project.value!.episodes }),
|
||||
createdAt: '2026-10-27T00:00:00Z'
|
||||
}
|
||||
]
|
||||
const page = await open(
|
||||
execution(context.project.value!.id, {
|
||||
stage: 'resumeGeneration',
|
||||
metadata: { action: 'resume-generation' }
|
||||
})
|
||||
)
|
||||
expect(page.get('[data-stage="reviewDrama"]').attributes('data-status')).not.toBe('completed')
|
||||
expect(page.get('[data-stage="generateCharacter"]').attributes('data-status')).not.toBe('completed')
|
||||
expect(page.get('[data-stage="generateWorld"]').attributes('data-status')).not.toBe('completed')
|
||||
})
|
||||
|
||||
it('审核未通过使用当前明确结论,允许恢复改写且不显示审核成功', async () => {
|
||||
context = testProjectContext('review-failed')
|
||||
context.data.value!.project.status = 'need_review'
|
||||
context.data.value!.checkpoints = [
|
||||
checkpoint({ storyPlan, reviewPassed: false, review: { passed: false } }, 'reviewDrama')
|
||||
]
|
||||
const page = await open(execution(context.project.value!.id, { status: 'completed', stage: 'completed' }))
|
||||
const dialog = await openTask(page)
|
||||
expect(page.get('[data-stage="reviewDrama"]').text()).toContain('未通过')
|
||||
expect(page.get('[data-stage="reviewDrama"]').classes()).not.toContain('done')
|
||||
expect(dialog.get('button[aria-label="恢复改写"]').attributes('disabled')).toBeUndefined()
|
||||
expect(dialog.get('button[aria-label="恢复生成"]').attributes('disabled')).toBeDefined()
|
||||
})
|
||||
|
||||
it('最新记录缺少规划时不回退历史规划或由已有剧集推断成功', async () => {
|
||||
context = testProjectContext('plan-missing')
|
||||
context.data.value!.project.status = 'failed'
|
||||
context.data.value!.project.episodes = []
|
||||
context.data.value!.checkpoints = [
|
||||
{ ...checkpoint({ storyPlan }), createdAt: '2026-10-27T00:00:00Z' },
|
||||
checkpoint({}, 'createProject')
|
||||
]
|
||||
const page = await open(execution(context.project.value!.id, { status: 'failed', stage: 'failed' }))
|
||||
const dialog = await openTask(page)
|
||||
expect(dialog.get('button[aria-label="恢复生成"]').attributes('disabled')).toBeDefined()
|
||||
expect(dialog.text()).toContain('缺少已保存的故事规划')
|
||||
})
|
||||
|
||||
it('节点切换重读项目与保存记录,不需要等到整个任务结束', async () => {
|
||||
context = testProjectContext('stage-update')
|
||||
context.data.value!.project.status = 'generating'
|
||||
const task = execution(context.project.value!.id)
|
||||
await open(task)
|
||||
await openTask()
|
||||
vi.mocked(context.refresh).mockClear()
|
||||
vi.mocked(workflowExecutionApi.get).mockResolvedValue({
|
||||
...task,
|
||||
stage: 'generateEpisode',
|
||||
updatedAt: '2026-10-28T00:02:00Z'
|
||||
})
|
||||
await wrapper!.getComponent({ name: 'WorkflowExecutionPanel' }).vm.$emit('refresh')
|
||||
await flushPromises()
|
||||
expect(context.refresh).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -31,6 +31,50 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('服务端任务发现', () => {
|
||||
it('创作任务无本地句柄也能发现,SSE 不按旧节点顺序过滤阶段,失败终态拒绝迟到事件', async () => {
|
||||
const task = { ...record('story-plan-discovery'), workflowName: 'create-drama', stage: 'generateStoryPlan' }
|
||||
/** 只模拟浏览器连接,查询和事件均使用正式任务结构。 */
|
||||
class StoryEventSource extends EventTarget {
|
||||
/** 本次任务订阅。 */
|
||||
static last: StoryEventSource
|
||||
/** 组件销毁时关闭连接。 */
|
||||
close = vi.fn<() => void>()
|
||||
/** 登记当前订阅供测试发送服务端事件。 */
|
||||
constructor() {
|
||||
super()
|
||||
StoryEventSource.last = this
|
||||
}
|
||||
}
|
||||
vi.stubGlobal('EventSource', StoryEventSource)
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: task })))
|
||||
)
|
||||
const scope = effectScope()
|
||||
const tracker = scope.run(() => useWorkflowExecution(ref(task.projectId), 'create-drama', { discover: true }))!
|
||||
await flushPromises()
|
||||
expect(tracker.query.data.value?.stage).toBe('generateStoryPlan')
|
||||
expect(tracker.active.value).toBe(true)
|
||||
for (const stage of ['generateWorld', 'generateEpisode', 'generateCharacter', 'reviewDrama']) {
|
||||
task.stage = stage
|
||||
StoryEventSource.last.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(task) }))
|
||||
await flushPromises()
|
||||
expect(tracker.query.data.value?.stage).toBe(stage)
|
||||
}
|
||||
task.status = 'failed'
|
||||
task.stage = 'failed'
|
||||
StoryEventSource.last.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(task) }))
|
||||
await flushPromises()
|
||||
StoryEventSource.last.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
data: JSON.stringify({ ...task, status: 'running', stage: 'generateStoryPlan' })
|
||||
})
|
||||
)
|
||||
await flushPromises()
|
||||
expect(tracker.query.data.value?.status).toBe('failed')
|
||||
expect(tracker.active.value).toBe(false)
|
||||
scope.stop()
|
||||
})
|
||||
it('页面保持打开时通过事件接上新任务,终态不被迟到运行消息重新激活', async () => {
|
||||
const task = record('discovery-stream')
|
||||
/** 仅模拟浏览器事件连接,所有任务仍来自测试响应。 */
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { effectScope, ref } from 'vue'
|
||||
import { NTag } from 'naive-ui'
|
||||
import WorkflowExecutionPanel from '@/features/workflows/WorkflowExecutionPanel.vue'
|
||||
import ContextNotice from '@/components/ui/ContextNotice.vue'
|
||||
import { executionPercentage, executionStageLabel, useWorkflowExecution } from '@/features/workflows/execution'
|
||||
import type { WorkflowExecution } from '@/features/workflows/execution.types'
|
||||
|
||||
@@ -30,6 +32,54 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('WorkflowExecution 前端契约', () => {
|
||||
it.each([
|
||||
{ projectStatus: 'need_review', type: 'warning', role: 'alert' },
|
||||
{ projectStatus: 'completed', type: 'success', role: undefined },
|
||||
{ projectStatus: undefined, type: 'info', role: undefined }
|
||||
])(
|
||||
'弹窗提示按实际结果突出注意事项,不将待审或未知结果显示为成功:$projectStatus',
|
||||
({ projectStatus, type, role }) => {
|
||||
const wrapper = mount(WorkflowExecutionPanel, {
|
||||
props: {
|
||||
execution: execution({
|
||||
workflowName: 'create-drama',
|
||||
status: 'completed',
|
||||
result: { projectStatus }
|
||||
}),
|
||||
loading: false,
|
||||
error: '',
|
||||
embedded: true
|
||||
}
|
||||
})
|
||||
const notice = wrapper.getComponent(ContextNotice)
|
||||
expect(notice.props('type')).toBe(type)
|
||||
expect(notice.attributes('role')).toBe(role)
|
||||
expect(notice.find('strong').exists()).toBe(true)
|
||||
expect(notice.find('svg').exists()).toBe(true)
|
||||
wrapper.unmount()
|
||||
}
|
||||
)
|
||||
it.each([
|
||||
{ projectStatus: 'completed', color: 'success', label: '已完成' },
|
||||
{ projectStatus: 'need_review', color: 'warning', label: '待修订' },
|
||||
{ projectStatus: undefined, color: 'default', label: '结果待确认' }
|
||||
])('创作任务结束按明确项目审核结果展示:$projectStatus', ({ projectStatus, color, label }) => {
|
||||
const wrapper = mount(WorkflowExecutionPanel, {
|
||||
props: {
|
||||
execution: execution({
|
||||
workflowName: 'create-drama',
|
||||
status: 'completed',
|
||||
stage: 'completed',
|
||||
result: { projectStatus }
|
||||
}),
|
||||
loading: false,
|
||||
error: ''
|
||||
}
|
||||
})
|
||||
expect(wrapper.getComponent(NTag).props('type')).toBe(color)
|
||||
expect(wrapper.getComponent(NTag).text()).toContain(label)
|
||||
wrapper.unmount()
|
||||
})
|
||||
it('拆解进度区分抽取计数与工作流完成,校验失败不显示全成功', () => {
|
||||
const wrapper = mount(WorkflowExecutionPanel, {
|
||||
props: {
|
||||
|
||||
Reference in new issue
Block a user