Files
short-drama-agent-front/src/features/subject-identity/SubjectIdentityPage.vue
T

1224 lines
63 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import AppForm from '../../components/ui/AppForm.vue'
import { NFormItem } from 'naive-ui'
import { integerRule } from '../../lib/form-rules'
import { useDirectorySelection } from '../../composables/useDirectorySelection'
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
import WorkspaceTools from '../../components/ui/WorkspaceTools.vue'
import {
NScrollbar,
NAlert,
NButton,
NCheckbox,
NCollapse,
NCollapseItem,
NInput,
NInputNumber,
NSelect,
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 { DirectoryItem, EmptyState, StatusBadge } from '../../components/ui'
import { downloadText } from '../../lib/format'
import ConfirmAction from '../workflows/ConfirmAction.vue'
import { castingStatusLabel, currentAnchor } from './model'
import { useSubjectIdentity } from './useSubjectIdentity'
import { useProjectContext } from '../projects/context'
import { useProjectStageAccess } from '../projects/useProjectStageAccess'
import StableAnchorQualityDialog from './components/StableAnchorQualityDialog.vue'
import IdentityEditor from './components/IdentityEditor.vue'
import SubjectIdentitySkeleton from './SubjectIdentitySkeleton.vue'
import IdentityDetailSkeleton from './components/IdentityDetailSkeleton.vue'
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, IdentityViewType } from './types'
/** 主体身份工作区按正式主体聚合,不把同一主体的多个 Form 当成不同身份。 */
const route = useRoute()
const router = useRouter()
const projectContext = useProjectContext()
const {
projectId,
operation,
selectedId,
subject,
subjects,
catalog,
generationModelsQuery,
castingQuery,
styleQuery,
profileQuery,
detail,
identity,
images,
session,
concurrency,
candidateLimit,
force,
editorRevision,
dirty,
blocked,
castingBlocked,
detailBlocked,
hasStyle,
hasCreativeProfile,
canGenerateText,
canGenerateImage,
canGenerateCandidate,
activeIdentityGeneration,
batchValid,
candidateLimitValid,
save,
generate,
generateProject,
generateStableAnchors,
generateCastingCandidates,
generateImage,
generateCastingCandidate,
confirmStableAnchor,
confirmCasting,
validateImage,
generateStableAnchorQuality,
pendingImageOperation
} = useSubjectIdentity()
/** 所有形态图片入口复用侧栏和路由的服务端阶段准入规则。 */
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)
return {
type: 'info' as const,
message: `${subject.value.name} 的身份图片正在生成,刷新页面不会重复提交,请等待当前任务完成。`
}
return null
})
/** 首次读取目录才替换整页,刷新已有主体时保留选择与阅读位置。 */
const initialLoading = computed(() => catalog.loading.value && !catalog.data.value)
/** 切换主体时只替换尚未返回的详情,不遮挡已读取的主体目录。 */
const detailInitialLoading = computed(() => detail.loading.value && !detail.data.value)
const search = ref('')
const module = ref('all')
const identityBatchModule = ref<'all' | 'character' | 'scene' | 'prop'>('all')
/** 单主体稳定母版质量生成弹窗开关。 */
const qualityOpen = ref(false)
const imageOpen = ref(false)
/** 从失败记录重试时保留原视角,普通生成仍使用弹窗默认视角。 */
const retryImageView = ref<IdentityViewType>()
const castingOpen = ref(false)
const pendingSelection = ref('')
const anchor = computed(() => currentAnchor(images.value))
const thumbnailRefreshKey = ref(0)
const casting = computed(() => {
const value = castingQuery.data.value
return value && Array.isArray(value.items) ? value : null
})
const castingBySubject = computed(() => new Map(casting.value?.items.map(item => [item.subjectId, item]) ?? []))
/** 详情与选角数据已有母版地址时直接复用,避免对每个角色重复查询。 */
function thumbnailSource(item: IdentitySubject): string | null | undefined {
if (item.id === selectedId.value && detail.data.value) return anchor.value?.imageUrl ?? null
const row = castingBySubject.value.get(item.id)
if (row) return row.anchorImageUrl || (row.anchorImageId ? undefined : null)
if (item.id === selectedId.value) return null
return undefined
}
const filtered = computed(() =>
subjects.value.filter(
item =>
(module.value === 'all' || item.module === module.value) &&
`${item.name} ${item.ref}`.toLowerCase().includes(search.value.trim().toLowerCase())
)
)
/** 主体目录根节点,复用分镜与生产目录的自动定位和平滑滚动。 */
const subjectDirectoryRoot = ref<HTMLElement | null>(null)
/** 桌面主体正文的独立滚动容器,切换主体时通过组件公开方法回到顶部。 */
const identityDetailScrollbar = ref<ScrollbarInst | null>(null)
/** 图片管理组件,步骤引导通过公开入口打开候选弹窗。 */
const identityGallery = ref<InstanceType<typeof IdentityGallery> | null>(null)
/** 手机正文起点,用于在页面共用滚动容器中定位新主体的内容顶部。 */
const identityContentRoot = ref<HTMLElement | null>(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<HTMLElement>('.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(
() => subjects.value.find(item => item.id === route.query.subjectId || item.ref === route.query.subjectRef)?.id
)
watch(
linkedSubjectId,
id => {
if (id) select(id)
},
{ immediate: true }
)
watch(selectedId, () => {
qualityOpen.value = false
imageOpen.value = false
castingOpen.value = false
pendingSelection.value = ''
})
/** 关闭生成弹窗后清除重试视角,避免影响下一次普通生成。 */
watch(imageOpen, open => {
if (!open) retryImageView.value = undefined
})
/** 当前主体写入地址,刷新和返回页面后恢复相同主体,再定位到对应目录项。 */
watch(
selectedId,
id => {
if (!id || !subjects.value.some(item => item.id === id) || route.query.subjectId === id) return
const query: LocationQueryRaw = { ...route.query, subjectId: id }
delete query.subjectRef
void router.replace({ query })
},
{ flush: 'post' }
)
/** 切换主体前确认放弃当前草稿,避免误丢尚未保存的文本。 */
function select(id: string) {
if (id === selectedId.value) return
if (dirty.value) pendingSelection.value = id
else selectedId.value = id
}
/** 用户明确放弃草稿后切换,查询层会取消旧请求。 */
function discardAndSelect() {
if (!pendingSelection.value) return
dirty.value = false
selectedId.value = pendingSelection.value
}
/** 保存真实回执便于定位部分失败主体。 */
function exportReceipt() {
downloadText('subject-identities-receipt.json', JSON.stringify(session.value.receipt, null, 2), 'application/json')
}
/** Character 使用确认选角事务;Scene / Prop 保留普通母版切换。 */
async function submitIdentityImage(input: Parameters<typeof generateImage>[0]) {
await generateImage(input)
if (!operation.value.error) imageOpen.value = false
}
async function submitCastingCandidate(input: Parameters<typeof generateCastingCandidate>[0]) {
await generateCastingCandidate(input)
if (!operation.value.error) castingOpen.value = false
}
/** Character 使用确认选角事务;Scene / Prop 保留普通母版切换。 */
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(
() => session.value.receipt,
receipt => {
if (receipt) {
toolsOpen.value = true
}
}
)
const formModel = computed(() => ({ concurrency: concurrency.value, candidateLimit: candidateLimit.value }))
const rules = { concurrency: integerRule('并发数'), candidateLimit: integerRule('本批上限') }
type IdentityFlowAction = 'style' | 'profile' | 'identity' | 'candidate' | 'confirm' | 'lock' | 'forms'
const primaryCandidate = computed(() =>
images.value.find(image => image.viewType === 'primary' && image.status === 'completed' && image.imageUrl)
)
/**
* Scene / Prop 的 primary 完成图本身即可进入确认母版阶段。
* Character 仍以正式 Anchor / Casting 状态为准。
*/
const referenceImageReady = computed(() =>
subject.value?.module === 'character' ? !!anchor.value || !!primaryCandidate.value : !!primaryCandidate.value
)
const identityTextReady = computed(() => !!identity.value?.generationPrompt?.trim())
const candidateReady = computed(() => referenceImageReady.value)
const identityReady = computed(() => !!anchor.value && !!identity.value?.isLocked)
const identityFlow = computed(() => {
const character = subject.value?.module === 'character'
return [
{ label: '身份文本', done: identityTextReady.value },
{ label: character ? '角色候选图' : '身份参考图', done: candidateReady.value },
{ label: '确认并锁定', done: identityReady.value }
]
})
const currentFlowIndex = computed(() => {
const index = identityFlow.value.findIndex(step => !step.done)
return index < 0 ? identityFlow.value.length : index
})
/** 按身份文本、角色候选图和母版确认状态说明下一步,明确 AI 生成的是文本还是图片。 */
const nextAction = computed<{ action: IdentityFlowAction; title: string; description: string; label: string }>(() => {
if (!hasStyle.value)
return {
action: 'style',
title: '先设置视觉风格',
description: '身份生成需要项目视觉风格。',
label: '设置视觉风格'
}
if (!hasCreativeProfile.value)
return {
action: 'profile',
title: '先配置生成模型',
description: '选择项目图片与视频模型后才能生图。',
label: '配置生成模型'
}
if (!identityTextReady.value)
return {
action: 'identity',
title: '第 1 步:生成身份文本',
description: 'AI 填写下方身份描述和核心提示词,生成后会保存到项目。',
label: 'AI 生成主体身份'
}
if (!candidateReady.value)
return subject.value?.module === 'character'
? {
action: 'candidate',
title: '第 2 步:生成角色候选图',
description: 'AI 根据身份文本生成角色外观图片,选定一张作为角色母版,用于后续图片生成。',
label: 'AI 生成角色候选图'
}
: {
action: 'candidate',
title: '第 2 步:生成身份参考图',
description: '生成一张可选为母版的参考图。',
label: '生成身份参考图'
}
if (anchor.value && !identity.value?.isLocked)
return {
action: 'lock',
title: '第 3 步:锁定身份',
description: '勾选锁定并保存,后续生成才会稳定引用当前母版。',
label: '前往锁定'
}
if (!identityReady.value)
return {
action: 'confirm',
title: '第 3 步:确认并锁定',
description: '在“管理候选”弹窗中确认母版;人物会同时锁定,场景和道具还需保存锁定状态。',
label: '管理候选并确认'
}
return {
action: 'forms',
title: '主体身份已完成',
description: subjectImagesAccess.value.enabled
? '可以继续生成此主体的形态图片。'
: `${subjectImagesAccess.value.reason},完成项目准备后可进入形态图片。`,
label: '查看形态图片'
}
})
/** 原配置恢复入口打开标题栏共用的全局配置弹窗。 */
function openProfileSettings() {
if (route.query.configure !== 'profile') void router.replace({ query: { ...route.query, configure: 'profile' } })
}
/** 根据当前主体的下一步引导执行操作,形态图片跳转仍遵守项目统一准入规则。 */
function runNextAction() {
if (nextAction.value.action === 'style') void router.push(`/projects/${projectId.value}/visual-style`)
else if (nextAction.value.action === 'profile') openProfileSettings()
else if (nextAction.value.action === 'candidate') {
if (subject.value?.module === 'character') castingOpen.value = true
else imageOpen.value = true
} else if (nextAction.value.action === 'confirm') {
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) {
void router.push({
path: `/projects/${projectId.value}/subject-images`,
query: { subjectRef: subject.value?.ref }
})
}
}
</script>
<template>
<!-- 以下是项目已读取但正式主体目录尚未返回时的完整骨架屏模块 -->
<SubjectIdentitySkeleton v-if="initialLoading" />
<WorkspacePage v-else split compact mobile-scroll class="identity-workspace-page">
<template #notice>
<NAlert v-if="subjectImagesAccess.enabled" type="success" :show-icon="false">
所有需要确认的角色身份已经准备好,可以继续制作主体形态图片。
<RouterLink :to="`/projects/${projectId}/subject-images`" class="text-button ml-2"
>继续形态图片 →</RouterLink
>
</NAlert>
</template>
<template #header>
<!-- 以下是类型筛选、主体数量与操作入口 -->
<div class="workspace-toolbar">
<div class="toolbar-type-filter">
<NSelect
aria-label="身份主体类型"
v-model:value="module"
:options="[
{ label: String('全部类型'), value: 'all' },
{ label: String('人物'), value: 'character' },
{ label: String('场景'), value: 'scene' },
{ label: String('道具'), value: 'prop' }
]"
></NSelect>
</div>
<span class="toolbar-summary">共 {{ subjects.length }} 个主体</span>
<div class="toolbar-actions">
<WorkspaceTools
v-model:open="toolsOpen"
title="角色选角总览与批量操作"
:has-receipt="!!session.receipt"
>
<!-- 以下是主体身份说明与选角批量操作模块 -->
<div class="identity-tools-intro flex flex-wrap items-end justify-between gap-4">
<div>
<h2 class="text-lg font-semibold">主体身份</h2>
<p class="mt-2 text-sm text-muted">
为同一个人物、场景或道具固定稳定特征,再生成不同造型。
</p>
</div>
</div>
<div class="workspace-overview-panel">
<div class="overview-content workspace-section-stack dialog-flat-stack">
<h3 class="text-sm font-semibold">角色选角总览与批量操作</h3>
<NAlert type="info" :show-icon="false" class="text-xs">
人物需要依次完成身份描述、选角候选、确认角色母版并锁定,之后才能用于镜头制作。未明确人物背景时,AI
默认以中国人物作为选角基线;项目和角色的明确事实始终优先。场景和道具使用稳定身份母版流程。
</NAlert>
<NAlert v-if="styleQuery.data.value && !hasStyle" type="info" :show-icon="false">
先创建项目视觉风格,才能 AI 生成身份或身份图片。<RouterLink
:to="`/projects/${projectId}/visual-style`"
class="text-button ml-2"
>设置视觉风格 →</RouterLink
></NAlert
>
<section v-if="casting" class="workspace-panel" aria-label="角色选角流程">
<div class="flex flex-wrap items-start justify-between gap-4">
<div class="flex items-start gap-3">
<span class="production-step"><UserCheck :size="17" /></span>
<div>
<h3 class="text-sm font-semibold">角色选角</h3>
<p class="mt-2 text-xs leading-6 text-muted">
只处理
Character。每张候选都根据当前身份描述独立生成,不复用旧母版;确认选择后才会设为角色母版并锁定身份。
</p>
</div>
</div>
<span class="font-mono text-xs text-muted"
>{{ casting.ready }} / {{ casting.total }} 已完成</span
>
</div>
<dl class="casting-stats mt-4">
<div>
<dt>缺身份文本</dt>
<dd>{{ casting.missingIdentity }}</dd>
</div>
<div>
<dt>缺候选图</dt>
<dd>{{ casting.missingAnchor }}</dd>
</div>
<div>
<dt>待确认演员</dt>
<dd>{{ casting.candidatePending }}</dd>
</div>
<div>
<dt>母版未锁定</dt>
<dd>{{ casting.unlocked }}</dd>
</div>
<div>
<dt>选角完成</dt>
<dd>{{ casting.ready }}</dd>
</div>
</dl>
<AppForm
:model="formModel"
:rules="rules"
:disabled="operation.pending"
validate-on-change
>
<div class="form-controls mt-5 flex flex-wrap gap-4 pt-4">
<NFormItem class="w-28" path="concurrency" label="并发数">
<NInputNumber
:input-props="{ 'aria-label': '并发数' }"
:disabled="operation.pending"
:value="typeof concurrency === 'number' ? concurrency : null"
@update:value="concurrency = $event ?? 0"
:min="1"
:step="1"
></NInputNumber>
</NFormItem>
<NFormItem class="w-28" path="candidateLimit" label="本批上限">
<NInputNumber
:input-props="{ 'aria-label': '本批上限' }"
:disabled="operation.pending"
:value="typeof candidateLimit === 'number' ? candidateLimit : null"
@update:value="candidateLimit = $event ?? 0"
:min="1"
:step="1"
></NInputNumber>
</NFormItem>
<NCheckbox
v-model:checked="force"
:disabled="operation.pending"
class="control-row-checkbox text-xs"
>覆盖未锁定身份文本
</NCheckbox>
<ConfirmAction
:label="force ? '重生成角色身份文本' : '补齐角色身份文本'"
:disabled="
blocked ||
!hasStyle ||
!batchValid ||
!candidateLimitValid ||
dirty ||
!casting.total
"
acknowledgement
description="只生成 Character Identity 文本,不生成图片。已锁定角色始终跳过;覆盖文本不会自动更新已有候选图。"
@confirm="generateProject(true)"
/>
<ConfirmAction
label="AI 批量生成角色候选图"
:disabled="
castingBlocked ||
!hasStyle ||
!batchValid ||
!candidateLimitValid ||
!casting.missingAnchor
"
acknowledgement
description="最多按本批上限为缺少 Anchor 的 Character 调用 图片模型,各自独立生成一张停用的 primary 候选,不复用旧身份母版。已有候选、已有母版或已完成选角的角色不会重复处理。"
@confirm="generateCastingCandidates"
/>
</div>
</AppForm>
<div class="casting-list" role="group" aria-label="角色选角进度">
<NButton
v-for="item in casting.items"
:key="item.subjectId"
@click="select(item.subjectId)"
class="casting-item"
:class="{ selected: selectedId === item.subjectId }"
:aria-pressed="selectedId === item.subjectId"
><span class="casting-item-identity">
<span class="casting-item-name">{{ item.subjectName }}</span>
<span class="casting-item-ref">{{ item.subjectRef }}</span> </span
><StatusBadge
class="casting-item-status"
:status="item.status"
:label="castingStatusLabel(item.status)"
/></NButton>
</div>
</section>
<section class="workspace-panel" aria-label="场景与道具身份母版">
<div class="flex flex-wrap items-start justify-between gap-4">
<div>
<h3 class="text-sm font-semibold">场景与道具稳定母版</h3>
<p class="mt-2 text-xs leading-6 text-muted">
为已有身份描述但缺少有效母版的场景或道具小批量生图。成功后会自动设为身份母版并锁定。
</p>
</div>
<div class="flex flex-wrap gap-3">
<ConfirmAction
label="生成场景母版"
:disabled="
blocked ||
!hasStyle ||
!batchValid ||
!candidateLimitValid ||
dirty ||
!subjects.length
"
acknowledgement
:description="`最多处理 ${candidateLimit} 个场景,生成成功后自动设为身份母版并锁定。可能产生图片模型费用。`"
@confirm="generateStableAnchors('scene')"
/>
<ConfirmAction
label="生成道具母版"
:disabled="
blocked || !hasStyle || !batchValid || dirty || !subjects.length
"
acknowledgement
:description="`最多处理 ${candidateLimit} 个道具,生成成功后自动设为身份母版并锁定。可能产生图片模型费用。`"
@confirm="generateStableAnchors('prop')"
/>
</div>
</div>
</section>
<NCollapse class="workspace-panel" :default-expanded-names="['details']"
><NCollapseItem name="details"
><template #header>高级:全部主体身份文本</template>
<p class="mt-3 text-xs leading-6 text-muted">
同时处理 Character、Scene 和
Prop;角色选角建议优先使用上方专用入口。已锁定身份始终跳过。
</p>
<NSelect
v-model:value="identityBatchModule"
class="mt-4 w-48"
aria-label="身份文本批处理范围"
:options="[
{ label: String('全部类型'), value: 'all' },
{ label: String('仅人物'), value: 'character' },
{ label: String('仅场景'), value: 'scene' },
{ label: String('仅道具'), value: 'prop' }
]" />
<ConfirmAction
class="mt-4"
:label="force ? '重生成全部未锁定身份' : '补齐全部主体身份文本'"
:disabled="blocked || !hasStyle || !batchValid || dirty || !subjects.length"
acknowledgement
description="生成全项目主体身份描述与提示词,不生成图片。覆盖不会自动更新旧身份图、形态图、首帧或视频。"
@confirm="
identityBatchModule === 'character'
? generateProject(true)
: generateProject(
false,
identityBatchModule === 'scene' ||
identityBatchModule === 'prop'
? identityBatchModule
: undefined
)
" /></NCollapseItem
></NCollapse>
<section v-if="session.receipt" class="workspace-panel" aria-label="身份文本批量回执">
<div class="flex justify-between gap-3">
<h3 class="text-sm font-medium">{{ session.receipt.title }} · 本次回执</h3>
<NButton @click="exportReceipt" text size="small">导出诊断</NButton>
</div>
<p v-if="session.receipt.kind === 'identities'" class="mt-3 text-xs text-muted">
共 {{ session.receipt.result.total }} 个主体 · 目标
{{ session.receipt.result.targetCount }} · 生成
{{ session.receipt.result.generated }} · 跳过
{{ session.receipt.result.skipped }}(含锁定
{{ session.receipt.result.skippedLocked }})· 失败
{{ session.receipt.result.failed }}
</p>
<p v-else-if="session.receipt.kind === 'casting'" class="mt-3 text-xs text-muted">
共 {{ session.receipt.result.totalCharacters }} 个角色 · 缺候选
{{ session.receipt.result.missingAnchor }} · 本批目标
{{ session.receipt.result.targetCount }} · 已生成
{{ session.receipt.result.generated }} · 失败
{{ session.receipt.result.failed }}
</p>
<p v-else class="mt-3 text-xs text-muted">
共 {{ session.receipt.result.total }} 个{{
session.receipt.result.module === 'scene' ? '场景' : '道具'
}}
· 符合条件 {{ session.receipt.result.eligibleCount }} · 本批目标
{{ session.receipt.result.targetCount }} · 已生成并锁定
{{ session.receipt.result.generated }} · 失败
{{ session.receipt.result.failed }}
</p>
<NAlert
v-if="session.receipt.result.failed"
role="alert"
type="error"
:show-icon="false"
class="mt-3"
>
本次存在部分失败,成功结果不会回滚。请检查逐角色原因后再重试。
</NAlert>
<ul class="mt-3 space-y-2 text-xs text-danger">
<li v-for="failure in session.receipt.result.failures" :key="failure.subjectId">
{{ failure.subjectRef }} · {{ failure.subjectId }}:{{ failure.error }}
</li>
</ul>
<p class="mt-3 text-[11px] text-muted">
回执仅保留于当前浏览器会话;最终状态以刷新后的正式记录为准。
</p>
</section>
</div>
</div>
</WorkspaceTools>
</div>
</div></template
>
<NScrollbar
class="workspace-feedback"
v-if="catalog.error.value || styleQuery.error.value || castingQuery.error.value"
><NAlert role="alert" type="error" :show-icon="false"
>{{ catalog.error.value || styleQuery.error.value || castingQuery.error.value }}
当前相关操作已暂停,请刷新核对后端。
<NButton
v-if="catalog.error.value"
text
class="ml-3"
:loading="catalog.loading.value"
@click="catalog.refresh"
>重试读取目录</NButton
>
</NAlert></NScrollbar
>
<NAlert
v-if="profileQuery.data.value && !hasCreativeProfile"
type="warning"
:show-icon="false"
class="identity-prerequisite"
>
<div class="flex flex-wrap items-center justify-between gap-3">
<span><strong>需要先配置项目生成模型</strong>,否则身份图和选角候选无法生成。</span>
<NButton type="primary" @click="openProfileSettings">立即配置</NButton>
</div>
</NAlert>
<div v-if="subjects.length" class="identity-workspace-region">
<!-- 以下是目录与详情上方的全栏生成提示模块,显示和隐藏时平滑收放高度 -->
<Transition name="identity-feedback" appear>
<div v-if="generationFeedback" class="identity-feedback-motion">
<div class="identity-feedback-body workspace-feedback">
<NAlert
:type="generationFeedback.type"
:show-icon="false"
class="identity-generation-feedback text-xs"
>{{ generationFeedback.message }}</NAlert
>
</div>
</div>
</Transition>
<!-- 以下是与分镜一致的融合工作区模块,目录与详情共用外层背景。 -->
<div class="panel workspace-surface directory-workspace identity-workspace">
<!-- 以下是主体目录模块,标题和搜索固定,条目通过独立滚动容器浏览。 -->
<nav class="directory-panel identity-directory" aria-label="主体目录">
<div class="directory-heading">
<h3>
主体目录 <span>{{ filtered.length }} / {{ subjects.length }}</span>
</h3>
</div>
<div class="directory-filters">
<NInput
placeholder="搜索主体或引用"
aria-label="搜索主体身份"
:input-props="{ 'aria-label': '搜索主体身份' }"
v-model:value="search"
clearable
></NInput>
</div>
<NScrollbar
class="identity-subject-list panel-scroll directory-scroll"
content-class="directory-list-content identity-subject-list-content"
x-scrollable
>
<!-- 以下是主体选中项自动定位模块,不增加目录布局占位 -->
<div ref="subjectDirectoryRoot" class="identity-directory-items">
<DirectoryItem
v-for="item in filtered"
:key="item.id"
:aria-pressed="selectedId === item.id"
:active="selectedId === item.id"
@click="select(item.id)"
class="identity-subject-item"
>{{ item.name }}
<template #leading>
<IdentityThumbnail
:project-id="projectId"
:subject-id="item.id"
:name="item.name"
:module="item.module"
:identity-id="item.identity === null ? null : item.identity?.id"
:source="thumbnailSource(item)"
:refresh-key="thumbnailRefreshKey"
/>
</template>
<template #eyebrow>{{ item.ref }}</template>
<template #meta>
<span>{{ item.forms.length }} 个形态</span
><span v-if="castingBySubject.has(item.id)" class="directory-status">
{{ castingStatusLabel(castingBySubject.get(item.id)!.status) }}</span
>
</template></DirectoryItem
>
<p v-if="!filtered.length" class="py-6 text-xs text-muted">没有匹配主体,请调整筛选。</p>
</div>
</NScrollbar>
</nav>
<!-- 以下是主体详情模块,滚动和内边距由公共工作区布局统一管理。 -->
<article class="directory-workspace-detail identity-detail" aria-label="主体身份详情">
<NScrollbar
ref="identityDetailScrollbar"
class="panel-scroll"
content-class="directory-workspace-content identity-detail-content"
>
<NAlert v-if="pendingSelection" type="info" :show-icon="false" class="mb-4"
><p class="text-xs">当前主体有未保存修改,切换会丢弃草稿。</p>
<div class="mt-3 flex gap-3">
<NButton @click="discardAndSelect">放弃草稿并切换</NButton
><NButton @click="pendingSelection = ''" text size="small">继续编辑</NButton>
</div></NAlert
>
<section v-if="subject" ref="identityContentRoot" class="identity-subject-content">
<div class="flex flex-wrap items-start justify-between gap-3">
<div>
<h3 class="font-semibold">
{{ subject.name }} <code class="subject-ref ml-2">{{ subject.ref }}</code>
</h3>
</div>
<NButton :disabled="detail.loading.value" @click="detail.refresh" text size="small">
刷新身份
</NButton>
</div>
<NAlert v-if="detail.error.value" role="alert" type="error" :show-icon="false" class="mt-4"
>{{ detail.error.value }} 查询失败时不允许生成或覆盖。
</NAlert>
<!-- 以下是切换主体时的局部骨架模块,保留真实主体名称与目录 -->
<IdentityDetailSkeleton v-if="detailInitialLoading" class="mt-5" />
<template v-if="detail.data.value">
<div class="identity-flow" aria-label="主体身份操作步骤">
<ol class="identity-flow-steps">
<li
v-for="(step, index) in identityFlow"
:key="step.label"
:class="{ done: step.done, current: index === currentFlowIndex }"
>
<span class="identity-flow-marker">
<Check v-if="step.done" :size="14" />
<Circle v-else :size="12" />
</span>
<span>{{ index + 1 }}. {{ step.label }}</span>
</li>
</ol>
<div class="identity-next-action">
<div>
<strong>{{ nextAction.title }}</strong>
<p>{{ nextAction.description }}</p>
</div>
<NButton
v-if="
nextAction.action !== 'identity' &&
(nextAction.action !== 'forms' || subjectImagesAccess.enabled)
"
type="primary"
:disabled="
operation.pending ||
(nextAction.action === 'candidate' &&
(subject.module === 'character'
? !canGenerateCandidate
: !canGenerateImage))
"
@click="runNextAction"
>{{ nextAction.label }}</NButton
>
</div>
</div>
<p v-if="dirty" class="mt-3 text-xs text-muted">
请先保存身份修改,再使用 AI 或生成图片。
</p>
<IdentityEditor
:key="`${selectedId}:${editorRevision}`"
:identity="identity"
:module="subject.module"
:disabled="detailBlocked"
@save="save"
@dirty="dirty = $event"
>
<!-- 以下是唯一的单主体 AI 文本生成入口,覆盖已有文本时沿用确认弹窗 -->
<template #generate>
<ConfirmAction
v-if="identity?.description?.trim() || identity?.generationPrompt?.trim()"
label="AI 生成主体身份"
description="AI 将重新生成当前主体的身份描述和核心提示词,并覆盖已保存的文本;已有图片不会自动更新。"
:disabled="!canGenerateText"
primary
@confirm="generate"
/>
<NButton v-else type="primary" :disabled="!canGenerateText" @click="generate">
AI 生成主体身份
</NButton>
</template>
</IdentityEditor>
<IdentityGallery
id="identity-reference-gallery"
ref="identityGallery"
:key="selectedId"
:images="images"
:subject-name="subject.name"
:module="subject.module"
:identity-locked="!!identity?.isLocked"
:disabled="
detailBlocked || (subject.module === 'character' && !!castingQuery.error.value)
"
:pending-operation="pendingImageOperation"
:retry-disabled-reason="imageRetryDisabledReason"
@validate="validateImage"
@anchor="chooseAnchor"
@regenerate="retryIdentityImage"
>
<!-- 以下是母版卡片底部的生成入口模块,候选在独立弹窗中管理 -->
<template #actions>
<NButton
v-if="subject.module === 'scene' || subject.module === 'prop'"
:disabled="!canGenerateImage"
@click="qualityOpen = true"
>生成稳定母版并校验质量</NButton
>
<NButton
v-if="subject.module === 'character'"
:disabled="!canGenerateCandidate"
@click="castingOpen = true"
>{{ anchor ? '再生成一张候选' : 'AI 生成角色候选图' }}</NButton
>
<NButton :disabled="!canGenerateImage" @click="imageOpen = true">
{{
subject.module === 'character'
? '生成辅助参考图'
: anchor
? '再生成一张候选'
: '生成母版候选'
}}
</NButton>
</template>
</IdentityGallery>
</template>
<!-- 以下是当前主体形态与可用跳转入口,各行沿用统一上下间距 -->
<div v-if="!detailInitialLoading" class="identity-subject-forms">
<h4 class="text-xs font-medium">此主体的形态</h4>
<div class="flex flex-wrap gap-2">
<NTag v-for="form in subject.forms" :key="form.id" size="small" :bordered="false"
>{{ form.name }}{{ form.isDefault ? ' · 默认' : '' }}</NTag
>
</div>
<p v-if="!subject.forms.length" class="text-xs text-muted">
此角色尚无正式形态,但可以先完成 Identity 与选角。
</p>
<RouterLink
v-if="subjectImagesAccess.enabled"
:to="{
path: `/projects/${projectId}/subject-images`,
query: { subjectRef: subject.ref }
}"
class="text-button justify-self-start"
>查看此主体形态图片 →</RouterLink
>
</div>
</section>
</NScrollbar>
</article>
</div>
</div>
<EmptyState
v-else-if="catalog.data.value"
title="还没有可展示的正式主体"
description="先完成剧本拆解与主体形态持久化,再来管理稳定身份。"
><RouterLink :to="`/projects/${projectId}/breakdown`" class="button button-secondary"
>前往剧本拆解</RouterLink
></EmptyState
>
<StableAnchorQualityDialog
v-if="
subject &&
(subject.module === 'scene' || subject.module === 'prop') &&
profileQuery.data.value?.profile &&
generationModelsQuery.data.value
"
v-model:open="qualityOpen"
:subject-id="subject.id"
:subject-name="subject.name"
:catalog="generationModelsQuery.data.value"
:profile="profileQuery.data.value.profile"
:disabled="!canGenerateImage"
@generate="generateStableAnchorQuality" />
<IdentityImageDialog
v-if="subject && profileQuery.data.value?.profile && generationModelsQuery.data.value"
v-model:open="imageOpen"
:subject-id="subject.id"
:subject-name="subject.name"
:module="subject.module"
:initial-view-type="retryImageView"
:images="images"
:catalog="generationModelsQuery.data.value"
:profile="profileQuery.data.value.profile"
:disabled="!canGenerateImage"
@generate="submitIdentityImage" />
<CastingCandidateDialog
v-if="
subject?.module === 'character' && profileQuery.data.value?.profile && generationModelsQuery.data.value
"
v-model:open="castingOpen"
:subject-id="subject.id"
:subject-name="subject.name"
:catalog="generationModelsQuery.data.value"
:profile="profileQuery.data.value.profile"
:disabled="!canGenerateCandidate"
@generate="submitCastingCandidate"
/></WorkspacePage>
</template>
<style>
/* 本组件专属布局与 Naive 内部结构覆盖。 */
@reference "../../styles/styles.css";
/* 主体目录根节点只用于定位,保留桌面纵向和手机横向的自然布局。 */
.identity-directory-items {
display: contents;
}
/* 目录由可用工作区高度约束,标题与搜索之外的空间供列表独立滚动。 */
.identity-subject-list {
@apply min-h-0 flex-1 overflow-hidden;
}
.casting-stats {
@apply grid grid-cols-[repeat(5,_minmax(0,_1fr))] gap-2.5;
}
.casting-stats div {
@apply py-2.5 px-3 rounded-none bg-(--app-subtle);
}
.casting-stats dt {
@apply text-muted text-[10px];
}
.casting-stats dd {
@apply mt-[5px] font-mono text-[13px];
}
@media (max-width: 900px) {
.casting-stats {
@apply grid-cols-[repeat(2,_minmax(0,_1fr))];
}
}
.identity-workspace-page {
container: identity-header / inline-size;
}
.identity-prerequisite {
@apply shrink-0 mx-0 mb-3;
}
/* 全栏提示与双栏工作区共用外层宽度,提示的间距随自身高度一起收放。 */
.identity-workspace-region {
@apply flex flex-col flex-1 min-h-0 overflow-hidden;
}
.identity-feedback-motion {
display: grid;
grid-template-rows: 1fr;
flex-shrink: 0;
}
.identity-feedback-body {
min-height: 0;
overflow: hidden;
}
.identity-generation-feedback {
margin-bottom: var(--app-content-gap);
}
/* 使用自然内容高度适配手机长文案,避免出现和消失时直接挤动目录与详情。 */
.identity-feedback-enter-active,
.identity-feedback-leave-active {
transition:
grid-template-rows 240ms cubic-bezier(0.25, 1, 0.5, 1),
opacity 180ms ease;
}
.identity-feedback-enter-from,
.identity-feedback-leave-to {
grid-template-rows: 0fr;
opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
.identity-feedback-enter-active,
.identity-feedback-leave-active {
transition: none;
}
}
.identity-flow {
/* 步骤、下一步说明与上下方标题和字段共用面板边界,避免二次缩进。 */
@apply mt-5;
}
.identity-flow-steps {
@apply flex flex-wrap items-center gap-x-6 gap-y-2;
}
.identity-flow-steps li {
@apply flex items-center gap-2 text-xs text-muted;
}
.identity-flow-steps li.current {
@apply text-accent font-semibold;
}
.identity-flow-steps li.done {
@apply text-muted;
}
.identity-flow-marker {
@apply grid place-items-center w-5 h-5 rounded-full border border-(--app-border);
}
.identity-flow-steps li.done .identity-flow-marker,
.identity-flow-steps li.current .identity-flow-marker {
@apply border-(--app-accent) text-accent;
}
.identity-next-action {
@apply mt-4 pt-4 flex items-center justify-between gap-4;
border-top: 1px solid var(--app-border);
}
.identity-next-action p {
@apply mt-1 text-xs text-muted;
}
.identity-next-action > div {
@apply min-w-0;
}
.identity-next-action > .n-button {
@apply shrink-0;
}
/* 形态标题、标签和可用入口独立排列,避免内联链接的上边距失效。 */
.identity-subject-forms {
@apply mt-6 grid gap-4;
}
.toolbar-type-filter {
@apply w-[152px] min-w-0;
}
.toolbar-type-filter .n-select {
@apply w-full min-w-0;
}
.identity-tools-intro {
@apply mb-6;
}
.directory-filters {
@apply grid gap-3 p-3 shrink-0;
}
.directory-filters > * {
@apply min-w-0;
}
.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;
}
.identity-subject-item .directory-item-body {
@apply gap-[3px];
}
.identity-subject-item .directory-item-title {
@apply order-0 text-sm font-semibold;
}
.identity-subject-item .directory-item-eyebrow {
@apply order-1 text-[10px];
}
.identity-subject-item .directory-item-meta {
@apply order-2 gap-y-1 gap-x-1.5 text-[10px];
}
.casting-list {
@apply grid grid-cols-[repeat(auto-fit,_minmax(min(100%,_260px),_1fr))] gap-3 mt-6 pt-5;
}
.n-button.casting-item {
@apply w-full min-w-0 h-auto min-h-[76px] py-3 px-3.5 whitespace-normal text-left bg-(--app-subtle);
}
.n-button.casting-item.selected {
@apply bg-(--app-selected) shadow-[inset_3px_0_0_var(--app-accent)];
}
.n-button.casting-item .n-button__content {
@apply flex w-full min-w-0 items-center justify-between gap-4 text-left;
}
.casting-item-identity {
@apply flex flex-col gap-[5px] min-w-0;
}
.casting-item-name {
@apply text-sm font-medium leading-normal wrap-anywhere;
}
.casting-item-ref {
@apply text-muted font-mono text-[11px] leading-normal wrap-anywhere;
}
.casting-item-status {
@apply shrink-0;
}
@media (max-width: 760px) {
/* 主体详情自然撑高,提示与主体导航随正文滚走;顶部两行保留固定。 */
.identity-workspace-page .identity-workspace-region {
height: auto;
flex: none;
overflow: visible;
}
.identity-next-action {
@apply items-start flex-col;
}
.identity-next-action > .n-button {
@apply w-full;
}
.identity-directory {
@apply h-auto;
}
.identity-subject-list {
@apply flex-none h-auto max-h-none;
}
.identity-directory .identity-subject-list.n-scrollbar,
.identity-directory .identity-subject-list .n-scrollbar-container,
.identity-directory .identity-subject-list .n-scrollbar-content {
@apply h-auto;
}
.directory-filters {
@apply grid-cols-[minmax(0,_1fr)];
}
}
/* 窄内容区去掉数量文案,操作入口收成图标与类型筛选同一行。 */
@container identity-header (max-width: 760px) {
.identity-workspace-page .workspace-toolbar {
@apply flex-nowrap gap-2;
}
.toolbar-type-filter {
@apply w-auto min-w-[120px] flex-1;
}
.identity-workspace-page .toolbar-summary {
@apply hidden;
}
.identity-workspace-page .toolbar-actions {
@apply ml-0 shrink-0;
}
.identity-workspace-page .workspace-tools-label,
.identity-workspace-page .workspace-tools-trigger .text-muted {
@apply hidden;
}
.identity-workspace-page .workspace-tools-trigger {
@apply h-[34px] w-[34px] p-0;
min-width: 34px;
}
.identity-workspace-page .workspace-tools-trigger .n-button__icon {
@apply m-0;
}
}
</style>