diff --git a/.gitignore b/.gitignore index 48541ce..969a636 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ coverage .DS_Store .worktree/ .worktrees/ + +.pnpm-store/ diff --git a/docs/superpowers/plans/2026-10-08-shot-selection-project-settings.md b/docs/superpowers/plans/2026-10-08-shot-selection-project-settings.md new file mode 100644 index 0000000..a85bcfc --- /dev/null +++ b/docs/superpowers/plans/2026-10-08-shot-selection-project-settings.md @@ -0,0 +1,53 @@ +# 镜头定位与项目配置 Implementation Plan + +> **For agentic workers:** 本次在当前 worktree 内逐项执行,保持用户已确认的范围。 + +**Goal:** 刷新后恢复镜头,清理独立刷新按钮,统一项目配置入口。 + +**Architecture:** 共享地址同步 composable 接入两个现有页面查询。ProjectLayout 打开 AppDialog 并复用 CreativeProfileSettings,配置修订通过项目注入上下文通知消费者。 + +**Tech Stack:** Vue 3、TypeScript、Vue Router、Naive UI、Tailwind。 + +## Global Constraints + +- 全部新增/修改函数、类型、响应式声明和页面模块写中文注释。 +- 页面和功能在本地 Chrome 的 localhost:4314 验证,不使用 Playwright。 +- 用户未要求本次提交,不提交、不推送;不执行付费生成。 + +### Task 1: 地址保存镜头选择 + +Files: 新建 src/features/storyboard/useShotSelection.ts;修改 useStoryboard.ts、useProduction.ts、ProductionPage.vue;新增 tests/features/storyboard/shot-selection.test.ts。 + +- [x] 用真实 memory router 写恢复、选镜头保留其它参数、切集清旧镜头、外部导航测试;先运行确认缺失功能失败。 +- [x] 导出 useShotSelection(currentEpisode: () => number),使用注入 route/router 与独立 ref;写入 router.replace({query: {...route.query, episodeNo: String(currentEpisode()), shotId}}),切集删除 shotId。 +- [x] 两个 hook 复用选择;移除生产页重复 route 同步;无效明确 ID 不回退其它镜头。 +- [x] 运行定向测试及 Chrome 刷新和地址导航验证。 + +### Task 2: 项目配置弹窗 + +Files: ProjectLayout.vue、CreativeProfileSettings.vue;新建 ProjectSettingsDialog.vue 与 context.ts(generation-config);调整现有配置消费者。 + +- [x] 标题栏增加“项目配置”;AppDialog 显示宽高比、图片配置、视频配置,图片与视频左右两列,小屏单列;操作按钮放 footer。 +- [x] 保留模型 schema 与现有保存 payload;保存期间 busy 锁关闭;读取和保存捕获原项目及请求归属。 +- [x] 注入项目配置 revision,保存后自增;单镜参数和已打开配置查询重新读取;配置错误恢复共用新入口。 +- [x] Chrome 打开、滚动、保存相同配置并刷新核对,取消修改不写入。 + +### Task 3: 清理独立刷新图标 + +Files: 搜索全部 src 下 RefreshCw 的组件。 + +- [x] 移除只有图标的 NButton(图库同时移除包装 NPopover);保留有文字的刷新操作与错误重试。 +- [x] 清理无用图标导入、按钮说明文字,保留仍被操作完成后调用的 refresh 函数。 +- [x] 格式化修改文件,lint、类型检查、构建;Chrome 核对各页面,检视地址恢复和配置弹窗。 + +用户后续调整:项目配置弹窗改为图片、视频左右布局,操作按钮放在 footer;保存草稿原样保留实际项目参数。 + +验收记录:Chrome 在 localhost:4314 验证分镜与生产选择刷新恢复、配置左右布局、footer 按钮、标题下 description slot、2px 间距、有效参数启用保存和取消草稿隔离;其它页面独立刷新图标已删除。49 项定向检查通过,类型、lint 与构建通过;全量检查的既有失败已在交付前同步修正并全部通过。 + +现有守株待兔项目配置 size=1080*1920 已被当前后端目录拒绝,真实保存验证得到该错误;表单保留原值并先提示校验问题。未写入替代尺寸,也未执行付费模型调用。 + +用户最新要求:新增与本次调整的布局、间距和文字样式优先直接使用 Tailwind utility class,减少自定义 class。 + +## 本次交付检查 + +用户明确要求提交、合并 dev、检查无错误后推送。完整 pnpm check 已通过:44 个测试文件、349 项测试全部通过,lint、格式与类型检查通过;build 通过。同步了旧参数 schema、202 执行句柄、readiness 门禁和 Modal 测试契约,并排除其它 worktree 的重复测试。修复新建 footer 校验、图库配置修订更新、失效镜头正文提示及内嵌配置操作锁。Chrome 验证空白创建输入被拦截、失效镜头可从目录恢复,未执行付费模型调用。 diff --git a/docs/superpowers/specs/2026-10-08-shot-selection-project-settings-design.md b/docs/superpowers/specs/2026-10-08-shot-selection-project-settings-design.md new file mode 100644 index 0000000..42dd990 --- /dev/null +++ b/docs/superpowers/specs/2026-10-08-shot-selection-project-settings-design.md @@ -0,0 +1,17 @@ +# 镜头定位与项目配置设计 + +用户已确认:两个镜头页面通过地址的 episodeNo、shotId 恢复选择,保留其它参数;全站移除独立刷新图标;项目标题栏右侧打开图片、视频左右布局,操作按钮放 footer 的配置弹窗。 + +- 共用镜头选择 composable,选择镜头时写入正式 ID 与当前剧集;切集清除旧 ID;浏览器导航从地址同步。无 ID 首次显示首镜,错误 ID 不代选其它镜头。 +- 配置使用现有 creative-profile GET/PUT 与 generation-models。宽高比在前,图片和视频区域左右两列,小屏回落单列,操作放 footer;使用 AppDialog 内滚动,保存期间禁止关闭,操作期间禁止保存。 +- 保留带文字的刷新、重试与后台观察逻辑,移除全站仅有刷新图标的按钮及无用导入。 +- 配置成功保存后通知当前项目消费者,重新读取默认参数;关闭未保存配置不影响实际生产。 +- 开发在当前 worktree;后续按用户明确授权提交、合并 dev 并推送;localhost:4314 本地 Chrome 验证选择刷新、跨页、弹窗排版与保存。 + +用户后续调整:项目配置弹窗改为图片、视频左右布局,操作按钮放在 footer;保存草稿原样保留实际项目参数。 + +公共 AppDialog 新增 description slot:说明固定在 header 内标题下方,标题与说明间距 2px,正文滚动不带走说明。原 description 属性保留作为 slot 默认文本。按真实目录校验配置,旧尺寸不兼容时原样展示并提示重新选择,不自动写入替代尺寸。 + +用户最新要求:新增与本次调整的布局、间距和文字样式优先直接使用 Tailwind utility class,减少自定义 class。 + +字段说明收敛:使用公共 FieldLabel,在 label 后放问号图标;点击图标通过 NPopover 查看后端 schema 的完整说明。GenerationOptionFields 与 GenerationModelControls 共享此组件,项目配置、首帧质量、身份候选与形态图等弹窗同步生效。原字段下方说明不再占据版面,实时错误、校验问题、费用确认和实际数据保持直接可见。新组件全部使用 Tailwind utility class。 diff --git a/index.html b/index.html index 0d32723..345b3a4 100644 --- a/index.html +++ b/index.html @@ -26,4 +26,3 @@ - diff --git a/src/App.vue b/src/App.vue index be07395..4b03a9b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -145,7 +145,11 @@ const menuOptions = computed(() => { disabled ? h( 'span', - { class: 'admin-menu-label', title: sectionAccess?.reason || '请先完成前面的制作步骤', 'aria-disabled': 'true' }, + { + class: 'admin-menu-label', + title: sectionAccess?.reason || '请先完成前面的制作步骤', + 'aria-disabled': 'true' + }, label ) : h(RouterLink, { to: target }, () => diff --git a/src/components/ui/AppDialog.vue b/src/components/ui/AppDialog.vue index d8e2f2b..eabc411 100644 --- a/src/components/ui/AppDialog.vue +++ b/src/components/ui/AppDialog.vue @@ -2,14 +2,29 @@ import { NModal, NScrollbar } from 'naive-ui' import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue' -/** Naive UI 管理焦点锁定、Esc、遮罩与主题;长弹窗只滚动内部正文。 */ -defineProps<{ title: string; description: string; busy?: boolean; wide?: boolean }>() +/** 公共弹窗的标题、说明、操作状态和宽度。 */ +withDefaults( + defineProps<{ + /** 弹窗标题,同时作为可访问名称。 */ + title: string + /** 标题下的默认说明,可使用 description slot 覆盖。 */ + description?: string + /** 提交期间锁定关闭操作。 */ + busy?: boolean + /** 使用宽弹窗布局。 */ + wide?: boolean + }>(), + { description: '', busy: false, wide: false } +) +/** 弹窗显隐状态,关闭行为由 Naive 管理。 */ const open = defineModel('open', { default: false }) +/** 正文测量锚点,不包含固定 header 与 footer。 */ const bodyAnchor = ref(null) +/** 可用正文滚动高度。 */ const bodyHeight = ref(0) let layoutObserver: ResizeObserver | undefined -/** 正文使用内容高度与剩余视口高度的较小值;为 NScrollbar 提供明确滚动高度。 */ +/** 正文使用内容高度与剩余视口高度的较小值,扣除固定标题、说明与 footer。 */ function updateBodyHeight() { const card = bodyAnchor.value?.closest('.app-dialog') const scrollContent = bodyAnchor.value?.parentElement @@ -20,27 +35,34 @@ function updateBodyHeight() { const contentStyle = content ? getComputedStyle(content) : null const available = Math.max( 0, - window.innerHeight - 32 - (header?.offsetHeight ?? 0) - (footer?.offsetHeight ?? 0) - - (contentStyle ? parseFloat(contentStyle.paddingTop) + parseFloat(contentStyle.paddingBottom) : 0) - - 2 + window.innerHeight - + 32 - + (header?.offsetHeight ?? 0) - + (footer?.offsetHeight ?? 0) - + (contentStyle ? parseFloat(contentStyle.paddingTop) + parseFloat(contentStyle.paddingBottom) : 0) - + 2 ) bodyHeight.value = Math.min(scrollContent.scrollHeight, available) } -watch(open, async shown => { - layoutObserver?.disconnect() - if (!shown) return - await nextTick() - updateBodyHeight() - const card = bodyAnchor.value?.closest('.app-dialog') - const scrollContent = bodyAnchor.value?.parentElement - if (!card || !scrollContent) return - layoutObserver = new ResizeObserver(updateBodyHeight) - const header = card.querySelector('.n-card-header') - const footer = card.querySelector('.n-card__footer') - if (header) layoutObserver.observe(header) - if (footer) layoutObserver.observe(footer) - layoutObserver.observe(scrollContent) -}, { flush: 'post' }) +watch( + open, + async shown => { + layoutObserver?.disconnect() + if (!shown) return + await nextTick() + updateBodyHeight() + const card = bodyAnchor.value?.closest('.app-dialog') + const scrollContent = bodyAnchor.value?.parentElement + if (!card || !scrollContent) return + layoutObserver = new ResizeObserver(updateBodyHeight) + const header = card.querySelector('.n-card-header') + const footer = card.querySelector('.n-card__footer') + if (header) layoutObserver.observe(header) + if (footer) layoutObserver.observe(footer) + layoutObserver.observe(scrollContent) + }, + { flush: 'post', immediate: true } +) onMounted(() => window.addEventListener('resize', updateBodyHeight)) onBeforeUnmount(() => { layoutObserver?.disconnect() @@ -53,7 +75,6 @@ onBeforeUnmount(() => { { role="dialog" :aria-label="title" > + + + diff --git a/src/features/production/components/ShotProductionAssets.vue b/src/features/production/components/ShotProductionAssets.vue index c66286f..afb390e 100644 --- a/src/features/production/components/ShotProductionAssets.vue +++ b/src/features/production/components/ShotProductionAssets.vue @@ -1,7 +1,7 @@ diff --git a/src/features/projects/context.ts b/src/features/projects/context.ts index 6ece356..28a0d41 100644 --- a/src/features/projects/context.ts +++ b/src/features/projects/context.ts @@ -23,7 +23,8 @@ export function useProjectData(id: Ref) { const projectId = id.value if (!projectId || !query.data.value) return const nextReadiness = await projectsApi.stageReadiness(projectId) - if (id.value === projectId && query.data.value) query.data.value = { ...query.data.value, stageReadiness: nextReadiness } + if (id.value === projectId && query.data.value) + query.data.value = { ...query.data.value, stageReadiness: nextReadiness } } return { ...query, project, checkpoints, stageReadiness, refreshStageReadiness } } diff --git a/src/features/projects/useProjectStageAccess.ts b/src/features/projects/useProjectStageAccess.ts index ec77ef2..62c4c68 100644 --- a/src/features/projects/useProjectStageAccess.ts +++ b/src/features/projects/useProjectStageAccess.ts @@ -35,8 +35,16 @@ export function useProjectStageAccess(projectId: Ref, readiness: Ref, readiness: Ref
- 正在读取正式分镜数据……
-
+
- +

BEAT {{ shot.beatNo }} / SHOT {{ shot.shotNo }} @@ -502,6 +493,12 @@ const rules = { concurrency: integerRule('批量并发'), maxRepairAttempts: int

+ +
number) { + /** 当前页面地址,非路由环境保留本地选择。 */ + const route = inject(routeLocationKey, undefined) + /** 当前路由导航器,替换选择参数不产生逐镜头历史。 */ + const router = inject(routerKey, undefined) + /** 当前选择的剧集,缺省时由页面决定首次有效剧集。 */ + const episode = ref() + /** 当前选择的正式镜头 ID。 */ + const shotId = ref('') + + /** 地址变化只读取选择,不触发反向写入或重置其它参数。 */ + watch( + () => [route?.query.episodeNo, route?.query.shotId], + () => { + const number = Number(queryText(route?.query.episodeNo)) + episode.value = Number.isSafeInteger(number) && number > 0 ? number : undefined + shotId.value = queryText(route?.query.shotId) + }, + { immediate: true, flush: 'sync' } + ) + + /** + * 仅替换当前页面的选择参数,保留来源动作、筛选参数与 hash。 + * @param query 更新后的地址参数 + */ + function replaceSelection(query: LocationQueryRaw) { + if (router && route) void router.replace({ path: route.path, query, hash: route.hash }) + } + + /** 切换剧集立即清除旧镜头,避免把上集 ID 带到下集。 */ + const selectedEpisode = computed({ + get: () => episode.value, + set: (number: number | undefined) => { + episode.value = number + shotId.value = '' + const query: LocationQueryRaw = { ...route?.query } + delete query.shotId + if (number && Number.isSafeInteger(number) && number > 0) query.episodeNo = String(number) + else delete query.episodeNo + replaceSelection(query) + } + }) + /** 选择镜头同时写入有效剧集和正式 ID,刷新后按地址恢复。 */ + const selectedShot = computed({ + get: () => shotId.value, + set: (value: string) => { + shotId.value = value.trim() + const query: LocationQueryRaw = { ...route?.query } + const number = currentEpisode() + if (Number.isSafeInteger(number) && number > 0) query.episodeNo = String(number) + if (shotId.value) query.shotId = shotId.value + else delete query.shotId + replaceSelection(query) + } + }) + return { selectedEpisode, selectedShot } +} diff --git a/src/features/storyboard/useStoryboard.ts b/src/features/storyboard/useStoryboard.ts index 1aee679..34a765c 100644 --- a/src/features/storyboard/useStoryboard.ts +++ b/src/features/storyboard/useStoryboard.ts @@ -1,3 +1,4 @@ +import { useShotSelection } from './useShotSelection' import { useWorkflowExecution } from '../workflows/execution' import type { StoryboardBatchResult, PromptBatchResult, StoryboardShotRegenerationResult } from './types' import { computed, ref, watch } from 'vue' @@ -22,10 +23,8 @@ export function useStoryboard() { const context = useProjectContext() /** 当前工作区的响应式状态或派生业务条件。 */ const id = computed(() => context.project.value?.id ?? '') - /** 当前工作区的响应式状态或派生业务条件。 */ - const selectedEpisode = ref() - /** 当前工作区的响应式状态或派生业务条件。 */ - const selectedShot = ref('') + /** 两个镜头工作区共用地址选择,刷新恢复同一正式镜头。 */ + const { selectedEpisode, selectedShot } = useShotSelection(() => episodeNo.value) /** 当前工作区的响应式状态或派生业务条件。 */ const concurrency = ref(2) /** 当前工作区的响应式状态或派生业务条件。 */ @@ -88,12 +87,14 @@ export function useStoryboard() { ) /** 重生成接口未返回新正文时,明确标记辅助剧情信息不可用。 */ const episodeSourceUnavailable = computed(() => !!session.value.invalidatedEpisodeSources[episodeNo.value]) - /** 当前工作区的响应式状态或派生业务条件。 */ + /** 当前剧集的正式镜头目录。 */ const shots = computed(() => mergeDesignedShots(data.value?.directions ?? null, data.value?.visualStates ?? null, source.value) ) - /** 当前工作区的响应式状态或派生业务条件。 */ - const shot = computed(() => shots.value.find(item => item.shotId === selectedShot.value) ?? shots.value[0]) + /** 明确指定的镜头不存在时不代选其它镜头;首次进入才选择第一镜。 */ + const shot = computed(() => + selectedShot.value ? shots.value.find(item => item.shotId === selectedShot.value) : shots.value[0] + ) /** 当前工作区的响应式状态或派生业务条件。 */ const prerequisites = computed(() => storyboardPrerequisites(context.checkpoints.value, episodeNo.value)) /** 当前工作区的响应式状态或派生业务条件。 */ diff --git a/src/features/subject-identity/SubjectIdentityPage.vue b/src/features/subject-identity/SubjectIdentityPage.vue index 45fb399..f4370b0 100644 --- a/src/features/subject-identity/SubjectIdentityPage.vue +++ b/src/features/subject-identity/SubjectIdentityPage.vue @@ -18,7 +18,7 @@ import { } from 'naive-ui' import { computed, ref, watch } from 'vue' import { useRoute, useRouter } from 'vue-router' -import { Check, Circle, RefreshCw, UserCheck } from '@lucide/vue' +import { Check, Circle, UserCheck } from '@lucide/vue' import { AssetImage, DirectoryItem, EmptyState, StatusBadge } from '../../components/ui' import { downloadText } from '../../lib/format' import ConfirmAction from '../workflows/ConfirmAction.vue' @@ -154,12 +154,6 @@ function exportReceipt() { downloadText('subject-identities-receipt.json', JSON.stringify(session.value.receipt, null, 2), 'application/json') } -/** 目录刷新同时读取正式形态和 Character Casting,避免无形态角色状态滞后。 */ -function refreshDirectory() { - thumbnailRefreshKey.value++ - void Promise.all([catalog.refresh(), castingQuery.refresh()]) -} - /** Character 使用确认选角事务;Scene / Prop 保留普通母版切换。 */ async function submitIdentityImage(input: Parameters[0]) { await generateImage(input) @@ -273,8 +267,8 @@ const nextAction = computed<{ action: IdentityFlowAction; title: string; descrip } }) +/** 原配置恢复入口打开标题栏共用的全局配置弹窗。 */ function openProfileSettings() { - toolsOpen.value = true if (route.query.configure !== 'profile') void router.replace({ query: { ...route.query, configure: 'profile' } }) } @@ -301,14 +295,6 @@ async function profileSaved() { operation.value.error = '' await profileQuery.refresh() } - -watch( - () => route.query.configure, - value => { - if (value === 'profile') openProfileSettings() - }, - { immediate: true } -) diff --git a/src/features/subject-identity/components/IdentityImageDialog.vue b/src/features/subject-identity/components/IdentityImageDialog.vue index ba79373..6b17f2f 100644 --- a/src/features/subject-identity/components/IdentityImageDialog.vue +++ b/src/features/subject-identity/components/IdentityImageDialog.vue @@ -6,7 +6,7 @@ import { NFormItem } from 'naive-ui' import { fieldRule } from '../../../lib/form-rules' import { NAlert, NButton, NCheckbox, NInput, NSelect } from 'naive-ui' import { computed, onBeforeUnmount, ref, watch } from 'vue' -import { AppDialog } from '../../../components/ui' +import { AppDialog, FieldLabel } from '../../../components/ui' import GenerationModelControls from '../../generation-config/components/GenerationModelControls.vue' import type { CreativeProfile, GenerationModelCatalog, GenerationOptions } from '../../generation-config/types' import { subjectIdentityApi } from '../api' @@ -197,7 +197,14 @@ const rules = { path="referenceImageId" label="身份锚定来源" :label-props="{ for: 'identity-reference' }" - > + + -

- 只能选择此主体已完成的图片。后端需取得 Provider 可访问的远程地址;本地预览可见不保证远程地址仍有效。 -

generationConfigApi.catalog(signal), @@ -67,9 +68,17 @@ export function useSubjectIdentity() { }, false ) + /** 全局配置成功保存后重新读取主体生图的实际默认参数。 */ + const generationRevision = useProjectGenerationRevision() + /** 配置查询按当前项目和修订号隔离。 */ + const profileKey = computed(() => JSON.stringify([projectId.value, generationRevision.value])) + /** 主体身份使用保存后的正式项目配置。 */ const profileQuery = usePolling( - projectId, - async (id, signal) => ({ profile: await generationConfigApi.profile(id, signal) }), + profileKey, + async (key, signal) => { + const [id] = JSON.parse(key) as [string, number] + return { profile: await generationConfigApi.profile(id, signal) } + }, false ) const castingQuery = usePolling( diff --git a/src/features/subject-images/SubjectImagesPage.vue b/src/features/subject-images/SubjectImagesPage.vue index 85736e5..0b314a3 100644 --- a/src/features/subject-images/SubjectImagesPage.vue +++ b/src/features/subject-images/SubjectImagesPage.vue @@ -6,30 +6,10 @@ import WorkspacePage from '../../components/ui/WorkspacePage.vue' import ActionMenu from '../../components/ui/ActionMenu.vue' import DetailDisclosure from '../../components/ui/DetailDisclosure.vue' import WorkspaceTools from '../../components/ui/WorkspaceTools.vue' -import { - NAlert, - NButton, - NCheckbox, - NInput, - NInputNumber, - NPopover, - NScrollbar, - NSelect, - NTag -} from 'naive-ui' +import { NAlert, NButton, NCheckbox, NInput, NInputNumber, NPopover, NScrollbar, NSelect, NTag } from 'naive-ui' import { computed, onScopeDispose, ref, watch, type Directive } from 'vue' import { useRoute, useRouter } from 'vue-router' -import { - Search, - RefreshCw, - Download, - ImagePlus, - ArrowLeft, - ArrowRight, - LayoutGrid, - Columns3, - Settings2 -} from '@lucide/vue' +import { Search, Download, ImagePlus, ArrowLeft, ArrowRight, LayoutGrid, Columns3, Settings2 } from '@lucide/vue' import { AssetImage, EmptyState, StatusBadge } from '../../components/ui' import { downloadText } from '../../lib/format' import ConfirmAction from '../workflows/ConfirmAction.vue' @@ -377,60 +357,60 @@ const rules = { concurrency: integerRule('批量并发'), limit: integerRule('

- 图库不自动刷新,可点击“刷新图库”读取最新记录。主图供分镜引用,候选图和历史失败记录均保留;过期主图不会自动删除或替换。 + 图库在进入和操作完成后读取最新记录。主图供分镜引用,候选图和历史失败记录均保留;过期主图不会自动删除或替换。

-

项目批量生图

- -
- - - - - 项目批量生图 + +
+ + 已有主图也新增候选图 - - -
-
-

- 作用于整个项目,不受下方筛选影响。上限只限制本次真正生图数量,其余显示为“待后续处理”,不计入跳过。默认使用项目尺寸与正式提示词,不会启动视频生成。 -

-
+ :input-props="{ id: 'image-concurrency' }" + :value="typeof concurrency === 'number' ? concurrency : null" + @update:value="concurrency = $event ?? 0" + :min="1" + :step="1" + > +
+ + 已有主图也新增候选图 + + + + +

+ 作用于整个项目,不受下方筛选影响。上限只限制本次真正生图数量,其余显示为“待后续处理”,不计入跳过。默认使用项目尺寸与正式提示词,不会启动视频生成。 +

+
@@ -598,25 +578,7 @@ const rules = { concurrency: integerRule('批量并发'), limit: integerRule(' 瀑布流布局 - - - 刷新图库 - + diff --git a/src/features/subject-images/useSubjectImages.ts b/src/features/subject-images/useSubjectImages.ts index fd86f69..53aff51 100644 --- a/src/features/subject-images/useSubjectImages.ts +++ b/src/features/subject-images/useSubjectImages.ts @@ -4,6 +4,7 @@ import { ApiError } from '../../lib/http' import { useProjectContext } from '../projects/context' import { getOperation, runOperation } from '../workflows/operations' import { workflowCheckpoints } from '../workflows/selectors' +import { useProjectGenerationRevision } from '../generation-config/context' import { generationConfigApi } from '../generation-config/api' import { subjectImagesApi } from './api' import { getImageSession, hasRunningImages } from './model' @@ -24,18 +25,26 @@ export function useSubjectImages() { const promptConcurrency = ref(3) const promptForce = ref(false) const batchModule = ref<'all' | SubjectModule>('all') - const generationModelsQuery = usePolling( - id, - async (_id, signal) => generationConfigApi.catalog(signal), - false - ) + const generationModelsQuery = usePolling(id, async (_id, signal) => generationConfigApi.catalog(signal), false) + /** 项目配置保存后重新读取实际默认参数,避免图库生图沿用旧模型。 */ + const generationRevision = useProjectGenerationRevision() + /** 配置查询按项目和保存修订号隔离。 */ + const profileKey = computed(() => JSON.stringify([id.value, generationRevision.value])) + /** 当前图库使用后端最新保存的项目配置。 */ const profileQuery = usePolling( - id, - async (projectId, signal) => ({ profile: await generationConfigApi.profile(projectId, signal) }), + profileKey, + async (key, signal) => { + const [projectId] = JSON.parse(key) as [string, number] + return { profile: await generationConfigApi.profile(projectId, signal) } + }, false ) - const queryRef = {} as { current?: ReturnType>>> } - const pollInterval = computed(() => queryDataHasRunningImages(queryRef.current?.data.value ?? null) ? 4000 : false) + const queryRef = {} as { + current?: ReturnType>>> + } + const pollInterval = computed(() => + queryDataHasRunningImages(queryRef.current?.data.value ?? null) ? 4000 : false + ) const query = usePolling( id, async (projectId, signal) => { @@ -53,10 +62,7 @@ export function useSubjectImages() { return forms } catch (error) { if (error instanceof ApiError && error.status === 404) - throw new Error( - '暂时无法读取形态图片,请稍后重试。', - { cause: error } - ) + throw new Error('暂时无法读取形态图片,请稍后重试。', { cause: error }) throw error } }, diff --git a/src/features/visual-style/VisualStylePage.vue b/src/features/visual-style/VisualStylePage.vue index 1b26dbc..c62e908 100644 --- a/src/features/visual-style/VisualStylePage.vue +++ b/src/features/visual-style/VisualStylePage.vue @@ -2,7 +2,7 @@ import WorkspacePage from '../../components/ui/WorkspacePage.vue' import DetailDisclosure from '../../components/ui/DetailDisclosure.vue' import { NAlert, NButton } from 'naive-ui' -import { LoaderCircle, LockKeyhole, LockKeyholeOpen, Palette, RefreshCw, TriangleAlert } from '@lucide/vue' +import { LoaderCircle, LockKeyhole, LockKeyholeOpen, Palette, TriangleAlert } from '@lucide/vue' import { computed, ref } from 'vue' import { useQuery } from '../../composables/useQuery' import { runOperation } from '../workflows/operations' @@ -32,7 +32,7 @@ const nextReady = computed(() => projectContext.stageReadiness.value?.visualStyl /** 状态是只读说明,与操作按钮分组;读取失败不能被误报成尚未创建。 */ const statusInfo = computed(() => { - if (query.error.value) return { label: '读取失败', hint: '请刷新重试,现有内容不会被覆盖', icon: TriangleAlert } + if (query.error.value) return { label: '读取失败', hint: '请重试读取,现有内容不会被覆盖', icon: TriangleAlert } if (!query.data.value) return { label: '正在读取', hint: '正在获取项目视觉风格', icon: LoaderCircle } if (!style.value) return { label: '尚未创建', hint: '可使用 AI 生成,或在下方手动填写', icon: Palette } return style.value.isLocked @@ -126,52 +126,46 @@ function removeImage(image: VisualStyleImage) { description="调用文本模型生成整体及分类风格。重新生成会覆盖已保存的文本与硬约束;旧身份、旧图片和已有提示词不会自动更新。" @confirm="generate" /> - -
- {{ query.error.value }} 当前内容读取失败,请刷新后重试;已有内容不会被覆盖。 - -

- 有未保存修改,AI 重生成暂不可用。刷新不会覆盖编辑内容;离开页面不会自动保存。 -

- - AI - 生成时,若项目和世界观没有明确其它人物背景,人物风格默认采用中国人物选角基线;人工填写的人物背景和角色事实优先。修改风格只影响之后的生成,旧资产不会自动更新。 -

正在读取视觉风格…

- + {{ query.error.value }} 当前内容读取失败;已有内容不会被覆盖。 + 重试读取 + +

+ 有未保存修改,AI 重生成暂不可用。刷新不会覆盖编辑内容;离开页面不会自动保存。 +

+ + AI + 生成时,若项目和世界观没有明确其它人物背景,人物风格默认采用中国人物选角基线;人工填写的人物背景和角色事实优先。修改风格只影响之后的生成,旧资产不会自动更新。 +

正在读取视觉风格…

+
diff --git a/src/features/workflows/WorkflowDiagnosticsDialog.vue b/src/features/workflows/WorkflowDiagnosticsDialog.vue index cbe9c30..d21e888 100644 --- a/src/features/workflows/WorkflowDiagnosticsDialog.vue +++ b/src/features/workflows/WorkflowDiagnosticsDialog.vue @@ -1,7 +1,7 @@ ', - negativePrompt: '模糊', - status: 'prompt_ready' - } - }) - ) + const fetcher = vi.fn().mockImplementation(async (_url, init) => + init?.method !== 'POST' + ? jsonResponse({ shotId: 'shot-db-1-1', references: [], missing: [] }) + : new Response( + JSON.stringify({ + data: { + shotId: 'shot-db-1-1', + updatedAt: '2026-09-10T00:00:00Z', + videoPrompt: '', + negativePrompt: '模糊', + status: 'prompt_ready' + } + }) + ) ) - vi.stubGlobal('fetch', fetcher) + stubFetch(fetcher) wrapper = mount(ShotTools, { attachTo: document.body, props: { projectId: fixture.id, shot: designedShot(), disabled: false } }) - expect(fetcher).not.toHaveBeenCalled() + expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true) await confirmGeneration('读取/生成提示词') - expect(fetcher.mock.calls[0]?.[0]).toBe('/api/storyboard-shots/shot-db-1-1/video-prompt') - expect(JSON.parse(fetcher.mock.calls[0]![1]!.body as string)).toEqual({ force: false }) + const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')! + expect(post[0]).toBe('/api/storyboard-shots/shot-db-1-1/video-prompt') + expect(JSON.parse(post[1]!.body as string)).toEqual({ force: false }) expect(wrapper.text()).toContain('') expect(wrapper.find('script').exists()).toBe(false) }) it('提示词生成缺少主首帧时保存当前剧集和镜头作为恢复位置', async () => { - vi.stubGlobal( - 'fetch', + stubFetch( vi.fn().mockResolvedValue( new Response( JSON.stringify({ - message: - '服务器内部错误 Shot 缺少可用于视频 0 秒起点校验的 Primary Keyframe: shot-db-1-1' + message: '服务器内部错误 Shot 缺少可用于视频 0 秒起点校验的 Primary Keyframe: shot-db-1-1' }), { status: 500 } ) @@ -1451,8 +1528,7 @@ describe('工作台页面交互', () => { }) }) it('项目筛选无结果时可清除条件并返回真实列表', async () => { - vi.stubGlobal( - 'fetch', + stubFetch( vi.fn().mockImplementation(async () => new Response(JSON.stringify({ data: [fixture] }))) ) const router = createRouter({ @@ -1463,10 +1539,6 @@ describe('工作台页面交互', () => { wrapper = mount(ProjectsPage, { attachTo: document.body, global: { plugins: [router] } }) await flushPromises() expect(wrapper.getComponent(NRadioGroup).props('size')).toBe('medium') - const refresh = wrapper.get('[aria-label="刷新项目"]') - expect(refresh.classes()).toContain('icon-button') - expect(refresh.find('.n-button__icon svg').exists()).toBe(true) - expect(refresh.text()).toBe('') expect(wrapper.text()).toContain('雨夜来信') await wrapper.get('input[aria-label="搜索项目"]').setValue('不存在的关键词') expect(wrapper.text()).toContain('没有匹配的剧本') @@ -1478,11 +1550,16 @@ describe('工作台页面交互', () => { it('新建弹窗提交真实参数并返回 202 的项目 ID', async () => { const fetcher = vi .fn() - .mockResolvedValue(new Response('{"projectId":"created","status":"generating"}', { status: 202 })) - vi.stubGlobal('fetch', fetcher) + .mockResolvedValue( + new Response('{"projectId":"created","executionId":"create-1","status":"pending"}', { status: 202 }) + ) + stubFetch(fetcher) wrapper = mount(CreateProjectDialog, { attachTo: document.body }) button('新建剧本').click() await flushPromises() + const title = document.querySelector('#title')! + title.value = ' 雨夜来信标题 ' + title.dispatchEvent(new Event('input', { bubbles: true })) const topic = document.querySelector('#topic')! topic.value = ' 雨夜来信 ' topic.dispatchEvent(new Event('input', { bubbles: true })) @@ -1491,8 +1568,9 @@ describe('工作台页面交互', () => { count.dispatchEvent(new Event('input', { bubbles: true })) document.querySelector('form')!.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })) await flushPromises() - expect(wrapper.emitted('created')).toEqual([['created']]) + expect(wrapper.emitted('created')).toEqual([['created', 'create-1']]) expect(JSON.parse(fetcher.mock.calls[0]![1]!.body as string)).toEqual({ + title: '雨夜来信标题', topic: '雨夜来信', style: '', episodeCount: 6 @@ -1507,7 +1585,7 @@ describe('工作台页面交互', () => { ) return new Response('{"data":{"workflowExecution":{"status":"completed"}}}') }) - vi.stubGlobal('fetch', fetcher) + stubFetch(fetcher) const provided = context() wrapper = mount(BreakdownPage, { attachTo: document.body, diff --git a/tests/fixtures/generation.ts b/tests/fixtures/generation.ts new file mode 100644 index 0000000..0ed5910 --- /dev/null +++ b/tests/fixtures/generation.ts @@ -0,0 +1,49 @@ +import type { CreativeProfile, GenerationModelCatalog } from '@/features/generation-config/types' + +/** 模拟后端图片目录,只开放该模型支持的尺寸枚举。 */ +export const imageCatalog: GenerationModelCatalog = { + defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' }, + images: [ + { + type: 'image', + provider: 'qwen-image', + providerLabel: 'Qwen', + model: 'qwen-image-3.0-pro', + modelLabel: 'Qwen Image', + supported: true, + enabled: true, + isDefault: true, + capabilities: {}, + generationOptions: [ + { + key: 'size', + label: '图片尺寸', + type: 'size', + required: true, + options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }] + } + ], + defaults: { size: '2048*2048' }, + projectConstraints: [] + } + ], + videos: [] +} + +/** + * 构造与目录一致的正式项目生成配置。 + * @param projectId 当前正式项目 ID + * @returns 项目画布、模型和有限尺寸参数 + */ +export function generationProfile(projectId: string): CreativeProfile { + return { + projectId, + aspectRatio: '1:1', + imageProvider: 'qwen-image', + imageModel: 'qwen-image-3.0-pro', + imageOptions: { size: '2048*2048' }, + videoProvider: 'seedance', + videoModel: 'seedance', + videoOptions: {} + } +} diff --git a/tests/lib/http.test.ts b/tests/lib/http.test.ts index a45bdf1..b30f1b1 100644 --- a/tests/lib/http.test.ts +++ b/tests/lib/http.test.ts @@ -1,4 +1,8 @@ import { afterEach, describe, expect, it, vi } from 'vitest' +import { flushPromises } from '@vue/test-utils' +import { effectScope, ref } from 'vue' +import { useWorkflowExecution } from '@/features/workflows/execution' +import type { WorkflowExecution } from '@/features/workflows/execution.types' import { ApiError, optionalResource, request } from '@/lib/http' import { projectsApi } from '@/features/projects/api' import { breakdownApi } from '@/features/breakdown/api' @@ -184,21 +188,69 @@ describe('后端 API 契约', () => { ]) }) - it('长工作流不使用普通查询的超时,不自动重试 POST', async () => { + it('拆解返回 202 观察句柄,后续轮询失败终态不会自动重发 POST', async () => { vi.useFakeTimers() - let finish!: (value: Response) => void - const fetcher = vi.fn<(url: string, options: RequestInit) => Promise>().mockImplementation( - () => - new Promise(resolve => { - finish = resolve - }) + /** 真实执行查询字段,开始回执与失败终态分别由不同接口返回。 */ + const record: WorkflowExecution = { + id: 'http-breakdown-execution', + projectId: 'http-breakdown-project', + workflowName: 'breakdown', + status: 'running', + stage: 'breakdown', + current: 0, + total: 1, + currentResourceId: null, + metadata: null, + result: null, + error: null, + startedAt: '2026-10-08T00:00:00Z', + completedAt: null, + createdAt: '2026-10-08T00:00:00Z', + updatedAt: '2026-10-08T00:00:00Z' + } + const fetcher = vi.fn().mockImplementation( + async (_url, init) => + new Response( + JSON.stringify({ + data: init?.method === 'POST' ? { executionId: record.id, status: 'pending', total: 1 } : record + }), + { status: init?.method === 'POST' ? 202 : 200 } + ) ) vi.stubGlobal('fetch', fetcher) - const running = breakdownApi.run('p', 'start', { groupSize: 3, modules: ['prop'] }) - await vi.advanceTimersByTimeAsync(120_000) - expect(fetcher).toHaveBeenCalledTimes(1) - expect(fetcher.mock.calls[0]![1].signal?.aborted).toBe(false) - finish(new Response('{"data":{"workflowExecution":{"status":"failed"}}}')) - expect(await running).toMatchObject({ workflowExecution: { status: 'failed' } }) + const started = await breakdownApi.run(record.projectId, 'start', { groupSize: 3, modules: ['prop'] }) + expect(started).toEqual({ executionId: record.id, status: 'pending', total: 1 }) + expect(fetcher.mock.calls[0]?.[0]).toBe('/api/projects/http-breakdown-project/breakdown/start') + expect(JSON.parse(String(fetcher.mock.calls[0]?.[1]?.body))).toEqual({ groupSize: 3, modules: ['prop'] }) + const scope = effectScope() + const tracker = scope.run(() => useWorkflowExecution(ref(record.projectId), 'breakdown'))! + try { + await tracker.track(started.executionId) + await flushPromises() + expect(tracker.active.value).toBe(true) + expect(tracker.query.data.value?.status).toBe('running') + record.status = 'failed' + record.error = '后端抽取失败' + record.completedAt = '2026-10-08T00:01:00Z' + await vi.advanceTimersByTimeAsync(1_500) + await flushPromises() + expect(tracker.query.data.value).toMatchObject({ status: 'failed', error: '后端抽取失败' }) + expect(tracker.active.value).toBe(false) + const completedCount = fetcher.mock.calls.length + await vi.advanceTimersByTimeAsync(120_000) + expect(fetcher).toHaveBeenCalledTimes(completedCount) + expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(1) + expect( + fetcher.mock.calls + .slice(1) + .every( + ([url, init]) => + url === '/api/workflow-executions/http-breakdown-execution' && init?.method === 'GET' + ) + ).toBe(true) + } finally { + tracker.dismiss() + scope.stop() + } }) }) diff --git a/vitest.config.ts b/vitest.config.ts index 44acb0d..60401f1 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,10 +1,15 @@ import { fileURLToPath, URL } from 'node:url' -import { defineConfig } from 'vitest/config' +import { configDefaults, defineConfig } from 'vitest/config' import vue from '@vitejs/plugin-vue' /** 使用轻量 DOM 测试 API、异步状态和 Vue 页面行为。 */ export default defineConfig({ plugins: [vue()], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } }, - test: { environment: 'happy-dom', restoreMocks: true } + test: { + environment: 'happy-dom', + restoreMocks: true, + /** 只检查当前 checkout,避免收集其它隔离 worktree 中的重复测试。 */ + exclude: [...configDefaults.exclude, '**/.worktrees/**', '**/.worktree/**'] + } })