From 3d2c198e52847766958468a7b8c49c5ba18e99c0 Mon Sep 17 00:00:00 2001 From: GJ Date: Sun, 11 Oct 2026 21:41:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(short-drama-agent-front):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=BA=AB=E4=BB=BD=E7=AE=A1=E7=90=86=E4=B8=8E=E9=95=9C?= =?UTF-8?q?=E5=A4=B4=E7=B4=A0=E6=9D=90=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ShotProductionAssets.vue | 18 +- .../subject-identity/SubjectIdentityPage.vue | 464 +++++++++--------- .../SubjectIdentitySkeleton.vue | 28 +- .../components/IdentityDetailSkeleton.vue | 23 +- .../components/IdentityGallery.vue | 315 +++++------- .../components/IdentityImageCard.vue | 308 ++++++++++++ .../components/IdentityImageDialog.vue | 20 +- .../subject-identity/useSubjectIdentity.ts | 2 - src/lib/candidate-layout.ts | 9 + src/styles/admin.css | 66 +++ tests/components/ui/DirectoryItem.test.ts | 3 +- tests/features/production/production.test.ts | 4 +- .../subject-identity/identity.test.ts | 396 +++++++++------ tests/features/workflows/pages.test.ts | 33 +- 14 files changed, 1060 insertions(+), 629 deletions(-) create mode 100644 src/features/subject-identity/components/IdentityImageCard.vue create mode 100644 src/lib/candidate-layout.ts diff --git a/src/features/production/components/ShotProductionAssets.vue b/src/features/production/components/ShotProductionAssets.vue index 8b1eaa6..5ec71de 100644 --- a/src/features/production/components/ShotProductionAssets.vue +++ b/src/features/production/components/ShotProductionAssets.vue @@ -9,6 +9,7 @@ import { AssetImage } from '../../../components/ui' import { usePolling } from '../../../composables/usePolling' import { useQuery } from '../../../composables/useQuery' import { errorMessage } from '../../../lib/http' +import { candidateDialogWidth } from '../../../lib/candidate-layout' import type { DesignedShot } from '../../storyboard/types' import { storyboardApi } from '../../storyboard/api' import ConfirmAction from '../../workflows/ConfirmAction.vue' @@ -308,15 +309,6 @@ async function refreshAfterReview() { await refreshAll() } const keyframeCandidates = computed(() => keyframes.value.filter(item => item.id !== currentKeyframe.value?.id)) -/** - * 按候选数量计算弹窗宽度,每项 260px,每行最多五项,预留间距和左右内边距。 - * @param count 当前候选数量 - * @returns 弹窗的期望宽度,单位为像素 - */ -function candidateDialogWidth(count: number): number { - const columns = Math.max(1, Math.min(5, count)) - return columns * 260 + (columns - 1) * 12 + 48 -} /** 首帧弹窗按当前候选数适配一至五列,实际宽度由公共弹窗限制在视口内。 */ const keyframeCandidatesWidth = computed(() => candidateDialogWidth(keyframeCandidates.value.length)) /** 视频弹窗与首帧共用固定列宽,少量候选不留多余的整列空白。 */ @@ -953,9 +945,10 @@ defineExpose({ inspectSpecs, inspecting }) .keyframe-card .asset-image { @apply aspect-square rounded-none; } +/* 素材按可用宽度等分列,自动收起空列,让首尾卡片与内容区左右边缘对齐。 */ .video-input-grid { - @apply grid gap-3; - grid-template-columns: repeat(auto-fill, minmax(180px, 220px)); + @apply grid w-full gap-3; + grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); } .video-input-grid .asset-image { @apply aspect-square rounded-none; @@ -991,8 +984,9 @@ defineExpose({ inspectSpecs, inspecting }) .asset-candidate-grid { @apply max-w-none grid-cols-[minmax(0,_1fr)]; } + /* 窄屏优先并排展示两列;素材较少时仍等分占满可用宽度。 */ .video-input-grid { - @apply grid-cols-[repeat(2,_minmax(0,_1fr))]; + grid-template-columns: repeat(auto-fit, minmax(min(120px, 100%), 1fr)); } .generation-settings-panel { @apply p-4; diff --git a/src/features/subject-identity/SubjectIdentityPage.vue b/src/features/subject-identity/SubjectIdentityPage.vue index 34a9585..024f645 100644 --- a/src/features/subject-identity/SubjectIdentityPage.vue +++ b/src/features/subject-identity/SubjectIdentityPage.vue @@ -15,12 +15,13 @@ import { NInput, NInputNumber, NSelect, - NTag + NTag, + type ScrollbarInst } from 'naive-ui' import { computed, ref, watch } from 'vue' import { useRoute, useRouter, type LocationQueryRaw } from 'vue-router' import { Check, Circle, UserCheck } from '@lucide/vue' -import { AssetImage, DirectoryItem, EmptyState, StatusBadge } from '../../components/ui' +import { DirectoryItem, EmptyState, StatusBadge } from '../../components/ui' import { downloadText } from '../../lib/format' import ConfirmAction from '../workflows/ConfirmAction.vue' import { castingStatusLabel, currentAnchor } from './model' @@ -35,7 +36,7 @@ import IdentityGallery from './components/IdentityGallery.vue' import IdentityImageDialog from './components/IdentityImageDialog.vue' import CastingCandidateDialog from './components/CastingCandidateDialog.vue' import IdentityThumbnail from './components/IdentityThumbnail.vue' -import type { IdentitySubject } from './types' +import type { IdentitySubject, IdentityViewType } from './types' /** 主体身份工作区按正式主体聚合,不把同一主体的多个 Form 当成不同身份。 */ const route = useRoute() @@ -70,7 +71,6 @@ const { canGenerateImage, canGenerateCandidate, activeIdentityGeneration, - latestIdentityFailure, batchValid, candidateLimitValid, save, @@ -90,7 +90,7 @@ const { const stageAccess = useProjectStageAccess(projectId, projectContext.stageReadiness) /** 当前项目是否允许进入形态图片,以及尚未开放的具体原因。 */ const subjectImagesAccess = computed(() => stageAccess.sections.value['subject-images']) -/** 当前主体的生成进度或失败原因统一放在两栏上方,切换主体时跟随正式详情更新。 */ +/** 只在两栏上方展示当前生成进度,历史失败在候选弹窗的对应图片卡片内说明。 */ const generationFeedback = computed(() => { if (!subject.value) return null if (activeIdentityGeneration.value) @@ -98,11 +98,6 @@ const generationFeedback = computed(() => { type: 'info' as const, message: `${subject.value.name} 的身份图片正在生成,刷新页面不会重复提交,请等待当前任务完成。` } - if (latestIdentityFailure.value) - return { - type: 'error' as const, - message: `最近一次身份图片生成失败:${latestIdentityFailure.value.error || '未返回具体错误'}。可以调整模型参数后重新生成。` - } return null }) /** 首次读取目录才替换整页,刷新已有主体时保留选择与阅读位置。 */ @@ -115,6 +110,8 @@ const identityBatchModule = ref<'all' | 'character' | 'scene' | 'prop'>('all') /** 单主体稳定母版质量生成弹窗开关。 */ const qualityOpen = ref(false) const imageOpen = ref(false) +/** 从失败记录重试时保留原视角,普通生成仍使用弹窗默认视角。 */ +const retryImageView = ref() const castingOpen = ref(false) const pendingSelection = ref('') const anchor = computed(() => currentAnchor(images.value)) @@ -142,11 +139,34 @@ const filtered = computed(() => ) /** 主体目录根节点,复用分镜与生产目录的自动定位和平滑滚动。 */ const subjectDirectoryRoot = ref(null) +/** 桌面主体正文的独立滚动容器,切换主体时通过组件公开方法回到顶部。 */ +const identityDetailScrollbar = ref(null) +/** 图片管理组件,步骤引导通过公开入口打开候选弹窗。 */ +const identityGallery = ref | null>(null) +/** 手机正文起点,用于在页面共用滚动容器中定位新主体的内容顶部。 */ +const identityContentRoot = ref(null) useDirectorySelection( subjectDirectoryRoot, () => selectedId.value, () => filtered.value.map(item => item.id) ) +/** 只在主体实际改变后重置正文,刷新身份或取消切换时保留当前阅读位置。 */ +watch( + selectedId, + (id, previousId) => { + if (!id || !previousId || id === previousId) return + identityDetailScrollbar.value?.scrollTo({ top: 0, behavior: 'instant' }) + if (!window.matchMedia('(max-width: 760px)').matches) return + const content = identityContentRoot.value + const viewport = content?.closest('.project-view') + if (!content || !viewport) return + viewport.scrollTo({ + top: viewport.scrollTop + content.getBoundingClientRect().top - viewport.getBoundingClientRect().top, + behavior: 'instant' + }) + }, + { flush: 'post' } +) /** 深链接仅在目标 ID 变化时选择,不因目录轮询把用户切回原主体。 */ const linkedSubjectId = computed( @@ -165,6 +185,10 @@ watch(selectedId, () => { castingOpen.value = false pendingSelection.value = '' }) +/** 关闭生成弹窗后清除重试视角,避免影响下一次普通生成。 */ +watch(imageOpen, open => { + if (!open) retryImageView.value = undefined +}) /** 当前主体写入地址,刷新和返回页面后恢复相同主体,再定位到对应目录项。 */ watch( selectedId, @@ -212,6 +236,39 @@ function chooseAnchor(imageId: string) { if (subject.value?.module === 'character') void confirmCasting(imageId) else void confirmStableAnchor(imageId) } +/** 当前主体生图暂不可用时,在失败记录旁说明具体恢复步骤。 */ +const imageRetryDisabledReason = computed(() => { + if (operation.value.pending) return '当前操作尚未结束,请等待完成后再重新生成。' + if (activeIdentityGeneration.value) return '此主体已有图片正在生成,请等待当前任务完成。' + if (dirty.value) return '请先保存下方身份文本修改,再重新生成图片。' + if (catalog.error.value || !catalog.data.value || detail.error.value || !detail.data.value) + return '主体数据读取失败或尚未完成,请先点击“刷新身份”或重试读取目录。' + if (styleQuery.error.value || !styleQuery.data.value) return '视觉风格尚未读取成功,请刷新页面后重试。' + if (blocked.value) return '当前项目暂不允许生成图片,请检查剧本与拆解状态,或刷新页面后重试。' + if (!hasStyle.value) return '请先在视觉风格页面保存项目风格。' + if (generationModelsQuery.error.value || !generationModelsQuery.data.value) + return '生成模型目录尚未读取成功,请刷新页面后重试。' + if (profileQuery.error.value) return '项目生成配置读取失败,请刷新页面后重试。' + if (!hasCreativeProfile.value) return '请先在“项目配置”中选择生成模型。' + if (!identity.value?.generationPrompt?.trim()) return '请先填写并保存核心提示词,或使用 AI 生成主体身份。' + if (subject.value?.module === 'character' && (castingQuery.error.value || !castingQuery.data.value)) + return '角色选角状态尚未读取成功,请刷新页面后重试。' + return '' +}) +/** + * 重新生成只打开原图片类型对应的参数弹窗,费用确认前不发送请求。 + * @param imageId 当前主体中失败图片的正式编号 + */ +function retryIdentityImage(imageId: string) { + const image = images.value.find(item => item.id === imageId && item.status === 'failed') + if (!image || imageRetryDisabledReason.value) return + if (subject.value?.module === 'character' && image.viewType === 'primary') { + if (canGenerateCandidate.value) castingOpen.value = true + } else if (canGenerateImage.value) { + retryImageView.value = image.viewType + imageOpen.value = true + } +} /** 新回执自动展开,避免折叠区隐藏部分失败诊断。 */ const toolsOpen = ref(false) watch( @@ -299,8 +356,8 @@ const nextAction = computed<{ action: IdentityFlowAction; title: string; descrip return { action: 'confirm', title: '第 3 步:确认并锁定', - description: '在下方选择母版;人物会同时锁定,场景和道具还需保存锁定状态。', - label: '前往确认母版' + description: '在“管理候选”弹窗中确认母版;人物会同时锁定,场景和道具还需保存锁定状态。', + label: '管理候选并确认' } return { action: 'forms', @@ -325,7 +382,7 @@ function runNextAction() { if (subject.value?.module === 'character') castingOpen.value = true else imageOpen.value = true } else if (nextAction.value.action === 'confirm') { - document.querySelector('#identity-reference-gallery')?.scrollIntoView({ behavior: 'smooth', block: 'start' }) + identityGallery.value?.openCandidates() } else if (nextAction.value.action === 'lock') { document.querySelector('#identity-lock')?.scrollIntoView({ behavior: 'smooth', block: 'center' }) } else if (nextAction.value.action === 'forms' && subjectImagesAccess.value.enabled) { @@ -676,9 +733,10 @@ function runNextAction() { -
- - - -

当前主体有未保存修改,切换会丢弃草稿。

-
- 放弃草稿并切换继续编辑 -
+ +
+ -
-
-
-

- {{ subject.name }} {{ subject.ref }} -

-
- - 刷新身份 - -
- {{ detail.error.value }} 查询失败时不允许生成或覆盖。 - - - - - -
-

此主体的形态

-
- {{ form.name }}{{ form.isDefault ? ' · 默认' : '' }} +

+ 此角色尚无正式形态,但可以先完成 Identity 与选角。 +

+ 查看此主体形态图片 →
-

- 此角色尚无正式形态,但可以先完成 Identity 与选角。 -

- 查看此主体形态图片 → -
-
-
+ + +
/* 本组件专属布局与 Naive 内部结构覆盖。 */ @reference "../../styles/styles.css"; -.identity-workspace { - @apply grid grid-cols-[240px_minmax(0,_1fr)] items-start gap-3; -} /* 主体目录根节点只用于定位,保留桌面纵向和手机横向的自然布局。 */ .identity-directory-items { display: contents; } +/* 目录由可用工作区高度约束,标题与搜索之外的空间供列表独立滚动。 */ .identity-subject-list { - @apply max-h-[560px] overflow-hidden; + @apply min-h-0 flex-1 overflow-hidden; } .casting-stats { @apply grid grid-cols-[repeat(5,_minmax(0,_1fr))] gap-2.5; @@ -965,12 +1024,6 @@ function runNextAction() { @apply mt-[5px] font-mono text-[13px]; } @media (max-width: 900px) { - .identity-workspace { - @apply grid-cols-[minmax(0,_1fr)]; - } - .identity-subject-list { - @apply max-h-[220px]; - } .casting-stats { @apply grid-cols-[repeat(2,_minmax(0,_1fr))]; } @@ -1064,37 +1117,6 @@ function runNextAction() { .identity-tools-intro { @apply mb-6; } -.identity-workspace { - @apply flex-1 min-h-0 items-stretch overflow-hidden; -} -.identity-workspace { - @apply grid-cols-[clamp(240px,_22%,_280px)_minmax(0,_1fr)]; -} -.identity-workspace > div { - @apply min-h-0 overflow-hidden overscroll-contain; -} -.identity-detail, -.identity-detail > .n-scrollbar-container, -.identity-detail .n-scrollbar-content, -.identity-detail .panel { - @apply w-full min-w-0 max-w-full; -} -.identity-detail .n-scrollbar-content { - @apply wrap-anywhere; -} -.identity-detail .panel { - @apply box-border; -} -/* AssetImage 的通用 width:100% 不得撑满母版摘要行,否则会把说明文字挤到最右侧。 */ -.identity-anchor > .asset-image { - @apply h-20 w-20 shrink-0 aspect-square; -} -.identity-anchor > div { - @apply min-w-0; -} -.identity-subject-list { - @apply max-h-none min-h-0 flex-1; -} .directory-filters { @apply grid gap-3 p-3 shrink-0; } @@ -1104,15 +1126,10 @@ function runNextAction() { .identity-subject-list-content { @apply gap-0.5 pt-0 px-0 pb-2; } +/* 目录条目沿用分镜公共底色与选中反馈,仅调整缩略图所需间距。 */ .n-button.identity-subject-item { @apply min-h-[86px] py-2.5 px-3.5; } -.n-button.identity-subject-item:not(.selected) { - @apply bg-(--app-surface); -} -.n-button.identity-subject-item:not(.selected):hover { - @apply bg-(--app-subtle); -} .identity-subject-item .directory-item-body { @apply gap-[3px]; } @@ -1156,27 +1173,12 @@ function runNextAction() { flex: none; overflow: visible; } - .identity-workspace-page .identity-workspace { - height: auto; - flex: none; - overflow: visible; - grid-template-rows: auto auto; - } - .identity-workspace-page .identity-workspace > .identity-detail, - .identity-workspace-page .identity-detail > .n-scrollbar-container { - height: auto; - max-height: none; - overflow: visible; - } .identity-next-action { @apply items-start flex-col; } .identity-next-action > .n-button { @apply w-full; } - .identity-workspace { - @apply grid-cols-[minmax(0,_1fr)] grid-rows-[auto_minmax(0,_1fr)] gap-3; - } .identity-directory { @apply h-auto; } diff --git a/src/features/subject-identity/SubjectIdentitySkeleton.vue b/src/features/subject-identity/SubjectIdentitySkeleton.vue index 7187d60..3946cbc 100644 --- a/src/features/subject-identity/SubjectIdentitySkeleton.vue +++ b/src/features/subject-identity/SubjectIdentitySkeleton.vue @@ -22,14 +22,14 @@ import IdentityDetailSkeleton from './components/IdentityDetailSkeleton.vue' -
+
-
diff --git a/src/features/subject-identity/components/IdentityImageCard.vue b/src/features/subject-identity/components/IdentityImageCard.vue new file mode 100644 index 0000000..9639cdb --- /dev/null +++ b/src/features/subject-identity/components/IdentityImageCard.vue @@ -0,0 +1,308 @@ + + + + + diff --git a/src/features/subject-identity/components/IdentityImageDialog.vue b/src/features/subject-identity/components/IdentityImageDialog.vue index 6b17f2f..b438630 100644 --- a/src/features/subject-identity/components/IdentityImageDialog.vue +++ b/src/features/subject-identity/components/IdentityImageDialog.vue @@ -16,12 +16,21 @@ import type { GenerateIdentityImageInput, IdentityImage, IdentityViewType } from /** 身份图生成配置;默认自动引用母版,不提供后端不存在的“忽略母版”开关。 */ const props = defineProps<{ + /** 正式主体编号。 */ subjectId: string + /** 当前主体名称。 */ subjectName: string + /** 主体类型,决定允许生成的视角。 */ module?: string + /** 从失败记录重新生成时使用的原视角。 */ + initialViewType?: IdentityViewType + /** 当前主体的身份图片,供选择母版参考。 */ images: IdentityImage[] + /** 当前操作是否禁止提交。 */ disabled: boolean + /** 可用模型及动态参数目录。 */ catalog: GenerationModelCatalog + /** 已保存的项目默认生成配置。 */ profile: CreativeProfile }>() /** open 的当前界面状态与输入绑定。 */ @@ -55,11 +64,16 @@ const valid = computed( Boolean(provider.value) && (!referenceImageId.value || references.value.some(image => image.id === referenceImageId.value)) ) -/** 监听界面目标变化并重置关联确认状态。 */ +/** 打开或切换重试目标时恢复原视角,并重新读取项目默认参数与费用确认。 */ watch( - () => [open.value, props.subjectId], + () => [open.value, props.subjectId, props.initialViewType], () => { - viewType.value = props.module === 'character' ? 'front' : 'primary' + viewType.value = + props.module === 'character' + ? props.initialViewType && props.initialViewType !== 'primary' + ? props.initialViewType + : 'front' + : 'primary' referenceImageId.value = '' prompt.value = '' const selected = diff --git a/src/features/subject-identity/useSubjectIdentity.ts b/src/features/subject-identity/useSubjectIdentity.ts index ba2ca7e..f1029f1 100644 --- a/src/features/subject-identity/useSubjectIdentity.ts +++ b/src/features/subject-identity/useSubjectIdentity.ts @@ -155,7 +155,6 @@ export function useSubjectIdentity() { const activeIdentityGeneration = computed(() => images.value.find(image => image.status === 'pending' || image.status === 'generating') ) - const latestIdentityFailure = computed(() => images.value.find(image => image.status === 'failed')) const canGenerateCandidate = computed( () => canGenerateImage.value && @@ -635,7 +634,6 @@ export function useSubjectIdentity() { canGenerateImage, canGenerateCandidate, activeIdentityGeneration, - latestIdentityFailure, batchValid, candidateLimitValid, save, diff --git a/src/lib/candidate-layout.ts b/src/lib/candidate-layout.ts new file mode 100644 index 0000000..a637ad2 --- /dev/null +++ b/src/lib/candidate-layout.ts @@ -0,0 +1,9 @@ +/** + * 按 260px 候选卡片计算弹窗宽度,每行最多五项,并预留列间距和内边距。 + * @param count 当前候选数量 + * @returns 弹窗期望宽度,单位为像素,实际宽度由公共弹窗适配视口 + */ +export function candidateDialogWidth(count: number): number { + const columns = Math.max(1, Math.min(5, count)) + return columns * 260 + (columns - 1) * 12 + 48 +} diff --git a/src/styles/admin.css b/src/styles/admin.css index 513456e..7e38fe1 100644 --- a/src/styles/admin.css +++ b/src/styles/admin.css @@ -409,6 +409,46 @@ body { :root:not([data-theme='dark']) .workspace-surface > .directory-panel { background: color-mix(in srgb, var(--app-subtle) 60%, var(--app-body)); } +/* 融合目录工作区沿用分镜的列宽和间距,真实页面与骨架共享同一背景和尺寸约束。 */ +.directory-workspace { + display: grid; + grid-template-columns: clamp(240px, 22%, 280px) minmax(0, 1fr); + align-items: stretch; + gap: 12px; + flex: 1; + min-width: 0; + min-height: 0; + overflow: hidden; +} +.directory-workspace > .directory-panel { + --app-field: var(--app-control); + --app-field-hover: var(--app-control-hover); + background: transparent; +} +/* 详情面板只负责约束高度,正文与图片滚动统一交给内部 NScrollbar。 */ +.directory-workspace-detail, +.directory-workspace-detail > .panel-scroll, +.directory-workspace-detail > .panel-scroll > .n-scrollbar-container, +.directory-workspace-content { + width: 100%; + min-width: 0; + max-width: 100%; +} +.directory-workspace-detail { + height: 100%; + min-height: 0; + overflow: hidden; +} +.directory-workspace-content { + box-sizing: border-box; + padding: 20px; + overflow-wrap: anywhere; +} +@media (min-width: 1024px) { + .directory-workspace-content { + padding: 28px; + } +} .image-history.n-scrollbar, .table-scroll.n-scrollbar { height: auto; @@ -558,6 +598,32 @@ body { align-items: stretch; padding-bottom: 12px; } + /* 手机目录横向浏览,详情自然撑高;两部分继续共用融合背景和页面滚动。 */ + .directory-workspace { + height: auto; + flex: none; + grid-template-columns: minmax(0, 1fr); + grid-template-rows: auto auto; + gap: 8px; + overflow: visible; + } + .directory-workspace > .directory-panel { + height: auto; + } + .directory-workspace > .directory-panel > .panel-scroll { + height: auto; + flex: none; + } + .directory-workspace-detail, + .directory-workspace-detail > .panel-scroll, + .directory-workspace-detail > .panel-scroll > .n-scrollbar-container { + height: auto; + max-height: none; + overflow: visible; + } + .directory-workspace-content { + padding: 12px; + } /* 分镜和生产共用紧凑手机工具栏,剧集选择与两个操作入口保持同行。 */ .compact-shot-workspace .workspace-toolbar { display: grid; diff --git a/tests/components/ui/DirectoryItem.test.ts b/tests/components/ui/DirectoryItem.test.ts index 55fb384..768e97a 100644 --- a/tests/components/ui/DirectoryItem.test.ts +++ b/tests/components/ui/DirectoryItem.test.ts @@ -63,7 +63,8 @@ describe('统一目录条目', () => { expect(css).toMatch(/\.n-button\.identity-subject-item\s*\{[^}]*min-height:\s*86px;[^}]*padding:\s*10px 14px/) expect(css).not.toMatch(/\.n-button\.identity-subject-item\s*\{[^}]*border-bottom:/) expect(css).toMatch(/\.identity-thumbnail\s*\{[^}]*width:\s*48px;[^}]*height:\s*64px/) - expect(css).toMatch(/\.n-button\.identity-subject-item:not\(\.selected\)\s*\{[^}]*var\(--app-surface\)/) + // 融合工作区由外层承载背景,目录不再重复铺设独立底色。 + expect(css).toMatch(/\.directory-workspace > \.directory-panel\s*\{[^}]*background:\s*transparent/) }) it('侧栏与主体、镜头、剧集目录统一直角满行,保留文字内边距和移动端滚动', () => { diff --git a/tests/features/production/production.test.ts b/tests/features/production/production.test.ts index ab9c9db..fcec82c 100644 --- a/tests/features/production/production.test.ts +++ b/tests/features/production/production.test.ts @@ -51,7 +51,7 @@ describe('镜头生产数据契约', () => { expect(source).toContain('v-if="currentVideo" class="video-grid mt-4"') expect(source).toMatch(/\.keyframe-grid,\s*\.video-grid\s*\{[^}]*max-w-\[260px\][^}]*grid-cols-1/) expect(source).toMatch( - /\.video-input-grid\s*\{[^}]*grid-template-columns:\s*repeat\(auto-fill, minmax\(180px, 220px\)\)/ + /\.video-input-grid\s*\{[^}]*grid-template-columns:\s*repeat\(auto-fit, minmax\(min\(180px, 100%\), 1fr\)\)/ ) expect(source).toMatch(/\.keyframe-card \.asset-image\s*\{[^}]*aspect-square/) const videoCard = readFileSync('src/features/production/components/VideoCard.vue', 'utf8') @@ -62,7 +62,7 @@ describe('镜头生产数据契约', () => { expect(source).not.toContain('class="video-input-ref"') expect(source).not.toContain('{{ reference.subjectFormName }} · {{ reference.subjectRef }}') expect(source).toMatch( - /@media \(max-width: 760px\)[\s\S]*?\.video-input-grid\s*\{[^}]*grid-cols-\[repeat\(2,_minmax\(0,_1fr\)\)\]/ + /@media \(max-width: 760px\)[\s\S]*?\.video-input-grid\s*\{[^}]*grid-template-columns:\s*repeat\(auto-fit, minmax\(min\(120px, 100%\), 1fr\)\)/ ) }) diff --git a/tests/features/subject-identity/identity.test.ts b/tests/features/subject-identity/identity.test.ts index 286bb07..2e0048a 100644 --- a/tests/features/subject-identity/identity.test.ts +++ b/tests/features/subject-identity/identity.test.ts @@ -1,10 +1,11 @@ import { imageCatalog, generationProfile } from '../../fixtures/generation' import { flushPromises, mount, type VueWrapper } from '@vue/test-utils' import { afterEach, describe, expect, it, vi } from 'vitest' -import { NButton, NImage, NScrollbar } from 'naive-ui' -import { AppDialog, AssetImage } from '@/components/ui' +import { NButton, NImage } from 'naive-ui' +import { AppDialog } from '@/components/ui' import IdentityImageDialog from '@/features/subject-identity/components/IdentityImageDialog.vue' import IdentityGallery from '@/features/subject-identity/components/IdentityGallery.vue' +import IdentityImageCard from '@/features/subject-identity/components/IdentityImageCard.vue' import CastingCandidateDialog from '@/features/subject-identity/components/CastingCandidateDialog.vue' import { subjectIdentityApi } from '@/features/subject-identity/api' import { @@ -16,7 +17,7 @@ import { } from '@/features/subject-identity/model' import { identityImageFixture } from '@/features/subject-identity/testing/fixtures' import { formFixture } from '@/features/subject-images/testing/fixtures' -import { expandSections, selectControl } from '@/testing/naive' +import { selectControl } from '@/testing/naive' let wrapper: VueWrapper | undefined afterEach(() => { @@ -26,13 +27,29 @@ afterEach(() => { vi.unstubAllGlobals() }) -/** 从真实 Naive 弹窗内获取确认按钮。 */ +/** + * 按可见文本或无障碍名称查找真实弹窗与标签操作按钮。 + * @param label 按钮文本或无障碍名称 + * @returns 对应的原生按钮 + */ function button(label: string) { - const item = [...document.querySelectorAll('button')].find(element => element.textContent?.trim() === label) + const item = [...document.querySelectorAll('button')].find( + element => element.textContent?.trim() === label || element.getAttribute('aria-label') === label + ) if (!item) throw new Error(`缺少按钮 ${label}`) return item } +/** + * 在指定图片卡片中获取操作按钮,避免不同候选的同名按钮混用。 + * @param card 当前图片卡片 + * @param label 目标操作文本 + * @returns 当前卡片的按钮包装器 + */ +function cardButton(card: VueWrapper, label: string) { + return card.findAllComponents(NButton).find(item => item.text() === label)! +} + /** 修改 Portal 表单控件并触发 Vue 绑定。 */ function input(selector: string, value: string) { if (selector === '#identity-view' || selector === '#identity-reference') { @@ -48,7 +65,78 @@ function input(selector: string, value: string) { const creativeProfile = generationProfile('project-1') describe('身份图与母版契约', () => { - it('详情大图 contain 完整显示,历史仍为 cover,缩略图只切换记录', async () => { + it('主页面只显示权威母版,所有候选与辅助、失败和进行中记录在管理弹窗中浏览', async () => { + const images = [ + identityImageFixture({ id: 'candidate', isAnchor: false }), + identityImageFixture({ + id: 'failed', + status: 'failed', + imageUrl: null, + isAnchor: false, + error: '模型超时' + }), + identityImageFixture({ + id: 'anchor', + imageUrl: '/storage/anchor.png', + provider: 'qwen-image', + model: 'qwen-image-3.0-pro' + }), + identityImageFixture({ id: 'front', viewType: 'front', isAnchor: false }), + identityImageFixture({ id: 'pending', status: 'pending', imageUrl: null, isAnchor: false }), + identityImageFixture({ id: 'generating', status: 'generating', imageUrl: null, isAnchor: false }) + ] + wrapper = mount(IdentityGallery, { + attachTo: document.body, + props: { subjectName: '林夏', module: 'character', identityLocked: true, disabled: false, images } + }) + expect(wrapper.findAll('.identity-anchor-grid .identity-image-card')).toHaveLength(1) + expect(wrapper.getComponent(NImage).props()).toMatchObject({ + objectFit: 'cover', + previewDisabled: false + }) + expect(wrapper.getComponent(NImage).props('src')).toContain('/storage/anchor.png') + expect(wrapper.text()).not.toContain('qwen-image') + expect(wrapper.find('.image-history').exists()).toBe(false) + expect(document.querySelector('.identity-candidate-grid')).toBeNull() + button('管理候选(5)').click() + await flushPromises() + const dialog = document.querySelector('[role="dialog"][aria-label="身份候选管理"]')! + expect(dialog.querySelectorAll('.identity-image-card')).toHaveLength(5) + expect(dialog.querySelector('[aria-label="身份图片 anchor"]')).toBeNull() + for (const id of ['candidate', 'failed', 'front', 'pending', 'generating']) { + expect(dialog.querySelector(`[aria-label="身份图片 ${id}"]`)).not.toBeNull() + } + expect(dialog.textContent).toContain('排队中') + expect(dialog.textContent).toContain('生成中') + expect(wrapper.emitted('anchor')).toBeUndefined() + expect(wrapper.emitted('validate')).toBeUndefined() + expect(wrapper.emitted('regenerate')).toBeUndefined() + }) + + it('候选未确认时不填补母版空状态,无图片时不提供管理入口', async () => { + wrapper = mount(IdentityGallery, { + attachTo: document.body, + props: { + subjectName: '林夏', + module: 'character', + identityLocked: false, + disabled: false, + images: [identityImageFixture({ id: 'candidate', isAnchor: false })] + } + }) + expect(wrapper.text()).toContain('尚未确认身份母版') + expect(wrapper.find('.identity-anchor-grid').exists()).toBe(false) + button('管理候选(1)').click() + await flushPromises() + expect(document.querySelector('[aria-label="身份图片 candidate"]')).not.toBeNull() + expect(wrapper.emitted('anchor')).toBeUndefined() + await wrapper.setProps({ images: [] }) + expect(wrapper.text()).toContain('尚无身份母版') + expect(wrapper.find('.identity-anchor-grid').exists()).toBe(false) + expect(wrapper.findAll('button').some(item => item.text().includes('管理候选'))).toBe(false) + }) + + it('失败详情按需在浮层显示,关闭管理同步收起详情,重试仅发出原记录 ID', async () => { wrapper = mount(IdentityGallery, { attachTo: document.body, props: { @@ -57,141 +145,66 @@ describe('身份图与母版契约', () => { identityLocked: true, disabled: false, images: [ - identityImageFixture({ id: 'anchor', imageUrl: '/storage/anchor.png' }), + identityImageFixture({ id: 'anchor' }), identityImageFixture({ - id: 'front', - viewType: 'front', + id: 'interrupted', + status: 'failed', + imageUrl: null, isAnchor: false, - imageUrl: '/storage/front.png' + error: '服务重启时图片 Provider 请求状态不可恢复,请人工确认后重新生成' }) ] } }) - const images = wrapper.findAllComponents(NImage) - expect(images).toHaveLength(3) - expect(images.map(image => image.props('objectFit'))).toEqual(['contain', 'cover', 'cover']) - expect(images.map(image => image.props('previewDisabled'))).toEqual([false, true, true]) - expect(wrapper.find('a[target="_blank"]').exists()).toBe(false) - expect(wrapper.text()).not.toContain('打开原图') - await wrapper.get('[aria-label="查看身份图片 front"] img').trigger('click') + expect(wrapper.find('.identity-image-failure').exists()).toBe(false) + button('管理候选(1)').click() await flushPromises() - expect(wrapper.get('[aria-label="查看身份图片 front"]').attributes('aria-pressed')).toBe('true') - expect(document.querySelector('.n-image-preview-container')).toBeNull() - const main = wrapper.get('.asset-image-preview img') - expect((main.element as HTMLImageElement).style.objectFit).toBe('contain') - expect(main.attributes('src')).toContain('/storage/front.png') - await main.trigger('click') + const card = document.querySelector('[aria-label="身份图片 interrupted"]')! + expect(card.textContent).not.toContain('核对原任务结果') + expect(document.querySelector('.identity-image-failure')).toBeNull() + expect(button('生成失败,查看失败原因').getAttribute('aria-expanded')).toBe('false') + button('生成失败,查看失败原因').click() await flushPromises() - const original = document.querySelector('.n-image-preview')! - expect(original.getAttribute('src')).toBe(main.attributes('src')) - expect(original.style.objectFit).not.toBe('cover') + const failure = document.querySelector('.identity-image-failure')! + expect(failure.closest('.identity-failure-scroll.n-scrollbar')).not.toBeNull() + expect(failure.closest('.identity-image-card')).toBeNull() + expect(failure.closest('.app-dialog')).toBeNull() + expect(button('生成失败,查看失败原因').getAttribute('aria-expanded')).toBe('true') + expect(failure.textContent).toContain('图片生成中断,结果未确认') + expect(failure.textContent).toContain('核对原任务结果') + expect(failure.textContent).toContain('重复生成和计费') + expect(failure.textContent).not.toContain('Provider') + expect(failure.querySelector('button')).toBeNull() + expect(failure.textContent).not.toContain('查看当前母版') + document.querySelector('[aria-label="身份候选管理"] .n-card-header__close')!.click() + await flushPromises() + expect( + wrapper + .findAllComponents(AppDialog) + .find(item => item.props('title') === '身份候选管理')! + .props('open') + ).toBe(false) + button('管理候选(1)').click() + await flushPromises() + expect(button('生成失败,查看失败原因').getAttribute('aria-expanded')).toBe('false') + button('生成失败,查看失败原因').click() + await flushPromises() + button('生成失败,查看失败原因').dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })) + await flushPromises() + expect(button('生成失败,查看失败原因').getAttribute('aria-expanded')).toBe('false') + button('重新生成角色候选图').click() + await flushPromises() + expect(wrapper.emitted('regenerate')).toEqual([['interrupted']]) expect(wrapper.emitted('anchor')).toBeUndefined() + expect( + wrapper + .findAllComponents(AppDialog) + .find(item => item.props('title') === '身份候选管理')! + .props('open') + ).toBe(false) }) - it('身份图库使用精简资产,不展示已移除的提示词、模型信息和启停状态', () => { - wrapper = mount(IdentityGallery, { - props: { - subjectName: '林夏', - module: 'character', - identityLocked: true, - disabled: false, - images: [identityImageFixture({ provider: 'qwen-image', model: 'qwen-image-3.0-pro' })] - } - }) - expect(wrapper.text()).toContain('当前身份母版') - expect(wrapper.text()).not.toContain('本次实际提示词') - expect(wrapper.text()).not.toContain('停用') - expect(wrapper.text()).not.toContain('qwen-image') - expect(wrapper.text()).toContain('创建于') - }) - - it('全部历史记录显示在预览下方,候选、辅助、失败和进行中图片均可切换查看', async () => { - const images = [ - identityImageFixture({ - id: 'candidate', - imageUrl: '/storage/candidate.png', - isAnchor: false - }), - identityImageFixture({ - id: 'failed', - status: 'failed', - imageUrl: null, - isAnchor: false, - - error: '图片模型超时' - }), - identityImageFixture({ id: 'anchor', imageUrl: '/storage/anchor.png', width: 4096, height: 4096 }), - identityImageFixture({ id: 'front', imageUrl: '/storage/front.png', viewType: 'front', isAnchor: false }), - identityImageFixture({ id: 'pending', status: 'pending', imageUrl: null, isAnchor: false }), - identityImageFixture({ - id: 'generating', - status: 'generating', - imageUrl: null, - isAnchor: false - }) - ] - wrapper = mount(IdentityGallery, { - attachTo: document.body, - props: { subjectName: '林夏', module: 'character', identityLocked: true, disabled: false, images } - }) - const history = wrapper.get('[aria-label="身份图片历史"]') - expect(history.findAll('.image-history-item')).toHaveLength(6) - expect(wrapper.getComponent(NScrollbar).props()).toMatchObject({ - xScrollable: true, - trigger: 'none', - contentStyle: { width: 'max-content' } - }) - expect(wrapper.get('.asset-image-preview').element.nextElementSibling?.textContent).toContain('历史记录 · 6 条') - expect(wrapper.get('.image-history-heading').element.nextElementSibling).toBe(history.element) - expect(history.text()).toContain('当前母版') - expect(history.text()).toContain('母版候选') - expect(history.text()).toContain('正面') - expect(history.text()).toContain('生成失败') - expect(history.text()).toContain('排队中') - expect(history.text()).toContain('生成中') - expect(history.get('[aria-label="查看身份图片 anchor"]').attributes('aria-pressed')).toBe('true') - for (const image of images) { - await history.get(`[aria-label="查看身份图片 ${image.id}"]`).trigger('click') - expect(history.findAll('[aria-pressed="true"]')).toHaveLength(1) - expect(history.get(`[aria-label="查看身份图片 ${image.id}"]`).attributes('aria-pressed')).toBe('true') - const preview = wrapper - .findAllComponents(AssetImage) - .find(item => item.classes().includes('asset-image-preview'))! - expect(preview.props('src')).toBe(image.status === 'completed' ? image.imageUrl : null) - expect(preview.props('alt')).toBe(`林夏 · ${image.viewType === 'primary' ? '身份母版' : '正面'}`) - } - await history.get('[aria-label="查看身份图片 failed"]').trigger('click') - expect(wrapper.get('.asset-image-preview').text()).toContain('本次生成失败') - expect(wrapper.findAll('[role="alert"]').map(item => item.text())).toContain('图片模型超时') - expect(button('确认选角并锁定').disabled).toBe(true) - expect(wrapper.emitted('anchor')).toBeUndefined() - }) - - it('刷新新增历史不会切回母版或重置横向位置,当前记录移除后才回退', async () => { - const anchor = identityImageFixture({ id: 'anchor' }) - const front = identityImageFixture({ id: 'front', viewType: 'front', isAnchor: false }) - wrapper = mount(IdentityGallery, { - props: { - subjectName: '林夏', - module: 'character', - identityLocked: true, - disabled: false, - images: [anchor, front] - } - }) - await wrapper.get('[aria-label="查看身份图片 front"]').trigger('click') - const viewport = wrapper.get('.image-history .n-scrollbar-container').element - viewport.scrollLeft = 120 - await wrapper.setProps({ images: [identityImageFixture({ id: 'new', isAnchor: false }), anchor, front] }) - expect(wrapper.get('[aria-label="查看身份图片 front"]').attributes('aria-pressed')).toBe('true') - expect(wrapper.get('.image-history .n-scrollbar-container').element).toBe(viewport) - expect(viewport.scrollLeft).toBe(120) - await wrapper.setProps({ images: [anchor] }) - expect(wrapper.get('[aria-label="查看身份图片 anchor"]').attributes('aria-pressed')).toBe('true') - expect(wrapper.get('.image-history-heading').text()).toContain('历史记录 · 1 条') - }) - - it('切换历史取消上一张的确认,只有再次确认才能发出当前候选 ID', async () => { + it('辅助图失败保留真实原因,草稿阻塞时说明恢复方向并禁止重试', async () => { wrapper = mount(IdentityGallery, { attachTo: document.body, props: { @@ -199,30 +212,85 @@ describe('身份图与母版契约', () => { module: 'character', identityLocked: false, disabled: false, - images: ['candidate-a', 'candidate-b'].map(id => identityImageFixture({ id, isAnchor: false })) + retryDisabledReason: '请先保存身份文本修改,再重新生成图片。', + images: [ + identityImageFixture({ + id: 'failed-front', + viewType: 'front', + status: 'failed', + imageUrl: null, + isAnchor: false, + error: '图片模型超时' + }) + ] } }) + button('管理候选(1)').click() + await flushPromises() + expect(document.querySelector('[aria-label="身份图片 failed-front"]')!.textContent).not.toContain( + '图片模型超时' + ) + button('生成失败,查看失败原因').click() + await flushPromises() + const notice = document.querySelector('.identity-image-failure')! + expect(notice.textContent).toContain('图片模型超时') + expect(notice.textContent).not.toContain('后台服务重启') + expect(notice.textContent).toContain('请先保存身份文本修改') + expect(button('重新生成辅助参考图').disabled).toBe(true) + button('重新生成辅助参考图').click() + await flushPromises() + expect(wrapper.emitted('regenerate')).toBeUndefined() + await wrapper.setProps({ retryDisabledReason: '' }) + button('重新生成辅助参考图').click() + await flushPromises() + expect(wrapper.emitted('regenerate')).toEqual([['failed-front']]) + }) + + it('明确确认目标后才提交指定候选,刷新同一母版保持管理弹窗,新母版返回后关闭弹窗', async () => { + const anchor = identityImageFixture({ id: 'anchor' }) + const candidate = identityImageFixture({ id: 'candidate', isAnchor: false }) + wrapper = mount(IdentityGallery, { + attachTo: document.body, + props: { + subjectName: '林夏', + module: 'character', + identityLocked: true, + disabled: false, + images: [anchor, candidate] + } + }) + button('管理候选(1)').click() + await flushPromises() + const management = wrapper.findAllComponents(AppDialog).find(item => item.props('title') === '身份候选管理')! button('确认选角并锁定').click() await flushPromises() - expect(document.querySelector('[role="dialog"][aria-label="确认选角并锁定"]')).not.toBeNull() - expect(button('确认演员选择').disabled).toBe(false) - await wrapper.get('[aria-label="查看身份图片 candidate-b"]').trigger('click') - expect(wrapper.findComponent(AppDialog).props('open')).toBe(false) + expect(wrapper.emitted('anchor')).toBeUndefined() + button('取消').click() + await flushPromises() expect(wrapper.emitted('anchor')).toBeUndefined() button('确认选角并锁定').click() await flushPromises() button('确认演员选择').click() - expect(wrapper.emitted('anchor')).toEqual([['candidate-b']]) - }) - - it('无历史图片时只展示空状态,不伪造缩略图或母版', () => { - wrapper = mount(IdentityGallery, { - props: { subjectName: '林夏', module: 'character', identityLocked: false, disabled: false, images: [] } + await flushPromises() + expect(wrapper.emitted('anchor')).toEqual([['candidate']]) + expect(management.props('open')).toBe(true) + await wrapper.setProps({ + images: [anchor, { ...candidate }, identityImageFixture({ id: 'new', isAnchor: false })] }) - expect(wrapper.text()).toContain('身份参考图 · 0') - expect(wrapper.text()).toContain('尚无身份参考图') - expect(wrapper.find('.image-history').exists()).toBe(false) - expect(wrapper.find('.asset-image-preview').exists()).toBe(false) + expect(management.props('open')).toBe(true) + expect(wrapper.get('.identity-anchor-grid .identity-image-card').attributes('aria-label')).toBe( + '身份图片 anchor' + ) + await wrapper.setProps({ + images: [ + { ...anchor, isAnchor: false }, + { ...candidate, isAnchor: true } + ] + }) + expect(management.props('open')).toBe(false) + expect(wrapper.get('.identity-anchor-grid .identity-image-card').attributes('aria-label')).toBe( + '身份图片 candidate' + ) }) it('启用的辅助视角不是母版,primary 候选停用时仍可选为母版', () => { @@ -347,7 +415,7 @@ describe('身份图与母版契约', () => { expect(select.props('value')).toBe('front') }) - it('辅助图不能切换母版,精简资产不展示内部提示词', async () => { + it('辅助图只有校验入口,不能通过候选弹窗切换母版', async () => { wrapper = mount(IdentityGallery, { attachTo: document.body, props: { @@ -358,10 +426,12 @@ describe('身份图与母版契约', () => { images: [identityImageFixture({ viewType: 'front', isAnchor: false })] } }) - expect(button('确认选角并锁定').disabled).toBe(true) - await expandSections() - expect(wrapper.text()).not.toContain('本次实际提示词') - expect(wrapper.find('script').exists()).toBe(false) + button('管理候选(1)').click() + await flushPromises() + const card = wrapper.findAllComponents(IdentityImageCard)[0]! + expect(card.findAllComponents(NButton).some(item => item.text() === '确认选角并锁定')).toBe(false) + expect(card.text()).toContain('不能直接设为身份母版') + expect(card.text()).not.toContain('本次实际提示词') expect(wrapper.emitted('anchor')).toBeUndefined() }) @@ -383,7 +453,7 @@ describe('身份图与母版契约', () => { expect(wrapper.emitted('anchor')).toEqual([['identity-image-1']]) }) - it('图片操作加载只对应提交目标,不能重复确认,切换图片不会错误显示加载', async () => { + it('多张候选同时可见时加载只绑定提交目标,操作期间所有重复提交均禁用', async () => { wrapper = mount(IdentityGallery, { attachTo: document.body, props: { @@ -394,24 +464,28 @@ describe('身份图与母版契约', () => { images: ['first', 'second'].map(id => identityImageFixture({ id, isAnchor: false })) } }) + button('管理候选(2)').click() + await flushPromises() + const cards = wrapper.findAllComponents(IdentityImageCard) + const first = cards.find(item => item.props('image').id === 'first')! + const second = cards.find(item => item.props('image').id === 'second')! await wrapper.setProps({ pendingOperation: { projectId: 'project-1', subjectId: 'subject-1', imageId: 'first', kind: 'confirm' } }) - const confirm = wrapper.findAllComponents(NButton).find(item => item.text() === '确认选角并锁定')! - expect(confirm.props('loading')).toBe(true) - expect(button('确认选角并锁定').disabled).toBe(true) - button('确认选角并锁定').click() + expect(cardButton(first, '确认选角并锁定').props('loading')).toBe(true) + expect(cardButton(second, '确认选角并锁定').props('loading')).toBe(false) + expect(cardButton(first, '确认选角并锁定').props('disabled')).toBe(true) + expect(cardButton(second, '确认选角并锁定').props('disabled')).toBe(true) + await cardButton(second, '确认选角并锁定').trigger('click') expect(wrapper.emitted('anchor')).toBeUndefined() - await wrapper.get('[aria-label="查看身份图片 second"]').trigger('click') - expect(confirm.props('loading')).toBe(false) await wrapper.setProps({ pendingOperation: { projectId: 'project-1', subjectId: 'subject-1', imageId: 'second', kind: 'validate' } }) - const validate = wrapper.findAllComponents(NButton).find(item => item.text() === '校验此身份图片')! - expect(validate.props('loading')).toBe(true) - expect(button('校验此身份图片').disabled).toBe(true) + expect(cardButton(first, '校验此身份图片').props('loading')).toBe(false) + expect(cardButton(second, '校验此身份图片').props('loading')).toBe(true) + expect(cardButton(second, '校验此身份图片').props('disabled')).toBe(true) await wrapper.setProps({ pendingOperation: null }) - expect(validate.props('loading')).toBe(false) + expect(cardButton(second, '校验此身份图片').props('loading')).toBe(false) }) it('选角候选发送当前图片 Provider 与动态参数,不携带旧宽高字段', async () => { diff --git a/tests/features/workflows/pages.test.ts b/tests/features/workflows/pages.test.ts index 3aac832..1e14213 100644 --- a/tests/features/workflows/pages.test.ts +++ b/tests/features/workflows/pages.test.ts @@ -350,7 +350,7 @@ describe('视觉风格与主体身份工作区', () => { ) }) - it('生成进度与失败提示位于两栏上方,切换主体后不会保留其它主体的状态,完成后隐藏', async () => { + it('生成进度保留全栏提示,失败详情按需在浮层显示,切换后不串主体状态', async () => { /** 两个主体分别处于生成中与失败状态,所有查询均使用隔离的测试响应。 */ const first = formFixture() const second = { ...formFixture(), id: 'second-form', subjectId: 'second-subject', images: [] } @@ -398,9 +398,16 @@ describe('视觉风格与主体身份工作区', () => { .find(item => item.text().includes('第二个主体'))! .trigger('click') await flushPromises() - expect(wrapper!.get('.identity-generation-feedback').text()).toContain('模型暂时不可用') - expect(wrapper!.get('.identity-generation-feedback').text()).not.toContain('林知夏 的身份图片正在生成') - expect(wrapper!.findAll('.identity-generation-feedback')).toHaveLength(1) + expect(wrapper!.find('.identity-generation-feedback').exists()).toBe(false) + expect(wrapper!.find('.identity-image-failure').exists()).toBe(false) + button('管理候选(1)').click() + await flushPromises() + expect(document.querySelector('.identity-candidate-grid')?.textContent).not.toContain('模型暂时不可用') + expect(document.querySelector('.identity-image-failure')).toBeNull() + button('生成失败,查看失败原因').click() + await flushPromises() + expect(document.querySelector('.identity-image-failure')?.textContent).toContain('模型暂时不可用') + expect(document.querySelectorAll('.identity-image-failure')).toHaveLength(1) vi.mocked(subjectIdentityApi.listImages).mockResolvedValue([ identityImageFixture({ identityId: `identity-${second.subjectId}`, status: 'completed' }) ]) @@ -411,6 +418,7 @@ describe('视觉风格与主体身份工作区', () => { .trigger('click') await flushPromises() expect(wrapper!.find('.identity-generation-feedback').exists()).toBe(false) + expect(document.querySelector('.identity-image-failure')).toBeNull() }) it('主体目录与详情分别显示骨架,查询失败结束占位并可重试恢复', async () => { @@ -448,7 +456,7 @@ describe('视觉风格与主体身份工作区', () => { expect(wrapper!.get('.subject-identity-skeleton').attributes('aria-busy')).toBe('true') expect(wrapper!.get('.subject-identity-skeleton').text()).toBe('') expect(wrapper!.find('#identity-description').exists()).toBe(false) - expect(wrapper!.text()).not.toContain('尚无身份参考图') + expect(wrapper!.text()).not.toContain('尚无身份母版') rejectCatalog(new Error('主体目录读取失败')) await flushPromises() expect(wrapper!.find('.subject-identity-skeleton').exists()).toBe(false) @@ -467,7 +475,7 @@ describe('视觉风格与主体身份工作区', () => { button('刷新身份').click() await flushPromises() expect(wrapper!.get('#identity-description').element.value).toBe('') - expect(wrapper!.text()).toContain('尚无身份参考图') + expect(wrapper!.text()).toContain('尚无身份母版') }) it('已有身份刷新保留草稿与图库,图片操作归属图库并遵守未保存限制', async () => { @@ -1071,6 +1079,8 @@ describe('视觉风格与主体身份工作区', () => { }) stubFetch(fetcher) await mountAssets('identity') + button('管理候选(1)').click() + await flushPromises() button('设为身份母版').click() await flushPromises() expect(fetcher.mock.calls.some(([, init]) => init?.method === 'PUT')).toBe(false) @@ -1079,14 +1089,13 @@ describe('视觉风格与主体身份工作区', () => { expect(fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')?.[0]).toBe( '/api/subjects/subject-db-1/identity/images/candidate/stable-anchor' ) - expect(wrapper!.text()).toContain('当前身份母版') + expect(wrapper!.text()).toContain('身份母版') expect(getOperation(fixture.id)).toMatchObject({ noticeType: 'success', notice: '林知夏 的身份母版已确认并锁定。' }) - const anchorImage = wrapper! - .findAllComponents(NImage) - .find(image => image.props('alt')?.endsWith('当前身份母版'))! + // 仅检查正文母版预览,目录缩略图使用相同身份标识但不提供原图预览。 + const anchorImage = wrapper!.get('.identity-anchor-grid').getComponent(NImage) expect(anchorImage.props()).toMatchObject({ objectFit: 'cover', previewDisabled: false }) }) @@ -1202,6 +1211,8 @@ describe('视觉风格与主体身份工作区', () => { stubFetch(fetcher) await mountAssets('identity') expect(wrapper!.text()).toContain('等待确认演员') + button('管理候选并确认').click() + await flushPromises() button('确认选角并锁定').click() await flushPromises() button('确认演员选择').click() @@ -1210,7 +1221,7 @@ describe('视觉风格与主体身份工作区', () => { expect(put[0]).toBe('/api/subjects/subject-db-1/identity/images/casting-1/casting') expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/anchor'))).toBe(false) expect(wrapper!.text()).toContain('主体身份已完成') - expect(wrapper!.text()).toContain('演员身份已确认并锁定') + expect(wrapper!.get('.identity-gallery').text()).toContain('已确认并锁定') }) it('切换主体会取消旧查询,迟到的身份结果不覆盖当前主体', async () => {