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

1091 lines
55 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 WorkspacePage from '../../components/ui/WorkspacePage.vue'
import WorkspaceTools from '../../components/ui/WorkspaceTools.vue'
import {
NScrollbar,
NAlert,
NButton,
NCheckbox,
NCollapse,
NCollapseItem,
NInput,
NInputNumber,
NSelect,
NTag
} from 'naive-ui'
import { computed, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { Check, Circle, RefreshCw, UserCheck } from '@lucide/vue'
import { AssetImage, 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 IdentityEditor from './components/IdentityEditor.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 CreativeProfileSettings from '../generation-config/components/CreativeProfileSettings.vue'
import type { IdentitySubject } from './types'
/** 主体身份工作区按正式主体聚合,不把同一主体的多个 Form 当成不同身份。 */
const route = useRoute()
const router = useRouter()
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,
latestIdentityFailure,
batchValid,
candidateLimitValid,
save,
generate,
generateProject,
generateStableAnchors,
generateCastingCandidates,
generateImage,
generateCastingCandidate,
setAnchor,
confirmCasting
} = useSubjectIdentity()
const search = ref('')
const module = ref('all')
const identityBatchModule = ref<'all' | 'character' | 'scene' | 'prop'>('all')
const imageOpen = ref(false)
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())
)
)
/** 深链接仅在目标 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, () => {
imageOpen.value = false
castingOpen.value = false
pendingSelection.value = ''
})
/** 切换主体前确认放弃当前草稿,避免误丢尚未保存的文本。 */
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 Casting,避免无形态角色状态滞后。 */
function refreshDirectory() {
thumbnailRefreshKey.value++
void Promise.all([catalog.refresh(), castingQuery.refresh()])
}
/** 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 setAnchor(imageId)
}
/** 新回执自动展开,避免折叠区隐藏部分失败诊断。 */
const toolsOpen = ref(false)
const overview = ref<string[]>(['casting'])
watch(
() => session.value.receipt,
receipt => {
if (receipt) {
overview.value = ['casting']
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)
)
const identityTextReady = computed(() => !!identity.value?.generationPrompt?.trim())
const candidateReady = computed(() => !!anchor.value || !!primaryCandidate.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
})
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: '生成稳定身份描述和核心提示词。',
label: '生成身份文本'
}
if (!candidateReady.value)
return subject.value?.module === 'character'
? {
action: 'candidate',
title: '第 2 步:生成选角候选',
description: '生成候选后再确认正式演员。',
label: '生成选角候选'
}
: {
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: '可以继续生成此主体的形态图片。',
label: '查看形态图片'
}
})
function openProfileSettings() {
toolsOpen.value = true
overview.value = []
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 === 'identity') void generate()
else if (nextAction.value.action === 'candidate') {
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' })
} else if (nextAction.value.action === 'lock') {
document.querySelector('#identity-lock')?.scrollIntoView({ behavior: 'smooth', block: 'center' })
} else if (nextAction.value.action === 'forms') {
void router.push({
path: `/projects/${projectId.value}/subject-images`,
query: { subjectRef: subject.value?.ref }
})
}
}
async function profileSaved() {
operation.value.error = ''
await profileQuery.refresh()
}
watch(
() => route.query.configure,
value => {
if (value === 'profile') openProfileSettings()
},
{ immediate: true }
)
</script>
<template>
<WorkspacePage split compact class="identity-workspace-page"
><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"
>
<CreativeProfileSettings :project-id="projectId" @saved="profileSaved" />
<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>
<RouterLink :to="`/projects/${projectId}/subject-images`" class="text-button"
>下一步:形态图片 →</RouterLink
>
</div>
<div class="workspace-overview-panel">
<NCollapse v-model:expanded-names="overview"
><NCollapseItem name="casting" title="角色选角总览与批量操作"
><div class="overview-content">
<NAlert type="info" :show-icon="false" class="mt-5 text-xs">
Character 现在需要依次完成身份文本、选角候选、确认演员并锁定
Identity,之后首帧才能就绪。未明确人物背景时,AI
默认以中国人物作为选角基线;项目和角色的明确事实始终优先。场景和道具仍使用普通身份母版流程。
</NAlert>
<NAlert
v-if="styleQuery.data.value && !hasStyle"
type="info"
:show-icon="false"
class="mt-4"
>
先创建项目视觉风格,才能 AI 生成身份或身份图片。<RouterLink
:to="`/projects/${projectId}/visual-style`"
class="text-button ml-2"
>设置视觉风格 →</RouterLink
></NAlert
>
<section v-if="casting" class="panel my-5 p-5" 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。每张候选都从 Identity 独立生成,不复用旧
Anchor;确认选择时才会同时切换 Anchor 并锁定 Identity。
</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="生成选角候选"
: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="panel mb-5 p-5" 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">
为已有身份提示词但缺少有效母版的场景或道具小批量生图。成功后后端会自动设为
Anchor 并锁定 Identity。
</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="panel mb-5 p-5" :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="panel mb-5 p-5"
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></NCollapseItem
></NCollapse
>
</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 }}
当前相关操作已暂停,请刷新核对后端。
</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">
<!-- 以下是主体目录 -->
<aside class="panel directory-panel identity-directory">
<div class="directory-heading">
<h3>
主体目录 <span>{{ filtered.length }} / {{ subjects.length }}</span>
</h3>
<NButton
:disabled="catalog.loading.value || castingQuery.loading.value"
@click="refreshDirectory"
quaternary
class="icon-button"
size="small"
aria-label="刷新主体目录"
title="刷新主体目录"
><template #icon><RefreshCw :size="14" /></template
></NButton>
</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
>
<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>
</NScrollbar>
</aside>
<NScrollbar class="identity-detail panel-scroll min-w-0">
<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" class="panel p-5 sm:p-6">
<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>
<p v-if="!detail.data.value && detail.loading.value" class="py-8 text-sm text-muted" role="status">
正在读取主体身份…
</p>
<template v-if="detail.data.value">
<div class="identity-flow mt-4" 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
type="primary"
:disabled="
operation.pending ||
(nextAction.action === 'identity' && !canGenerateText) ||
(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"
/>
<div v-if="anchor" class="identity-anchor mt-5 flex items-center gap-4 pt-5">
<AssetImage
:src="anchor.imageUrl"
:alt="`${subject.name}当前身份母版`"
preview
class="h-20 w-20 shrink-0"
/>
<div>
<p class="text-sm font-medium">当前身份母版</p>
<p class="mt-2 text-xs text-muted">
{{
subject.module === 'character'
? identity?.isLocked
? '演员身份已确认并锁定,可用于形态图与镜头首帧。'
: '已有演员母版但 Identity 尚未锁定,镜头首帧仍会被阻塞。'
: subject.module === 'prop'
? '锁定后,后续道具形态图会继承当前母版。'
: '后续场景形态图会继承此图的空间结构。'
}}
</p>
</div>
</div>
<IdentityGallery
id="identity-reference-gallery"
:key="selectedId"
:images="images"
:subject-name="subject.name"
:module="subject.module"
:identity-locked="!!identity?.isLocked"
:disabled="detailBlocked || (subject.module === 'character' && !!castingQuery.error.value)"
@anchor="chooseAnchor"
/>
</template>
<div class="mt-5 pt-5">
<h4 class="text-xs font-medium">此主体的形态</h4>
<div class="mt-3 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="mt-3 text-xs text-muted">
此角色尚无正式形态,但可以先完成 Identity 与选角。
</p>
<RouterLink
:to="{ path: `/projects/${projectId}/subject-images`, query: { subjectRef: subject.ref } }"
class="text-button mt-3"
>查看此主体形态图片 →</RouterLink
>
</div>
</section>
</NScrollbar>
</div>
<p v-else-if="catalog.loading.value" class="py-8 text-sm text-muted" role="status">正在读取正式主体目录…</p>
<EmptyState
v-else-if="catalog.data.value"
title="还没有可展示的正式主体"
description="先完成剧本拆解与主体形态持久化,再来管理稳定身份。"
><RouterLink :to="`/projects/${projectId}/breakdown`" class="button button-secondary"
>前往剧本拆解</RouterLink
></EmptyState
>
<NAlert
v-if="activeIdentityGeneration"
type="info"
:show-icon="false"
class="mb-4 text-xs"
>
{{ subject?.name }} 的身份图片正在生成({{ activeIdentityGeneration.provider || '图片模型' }}),刷新页面不会重复提交,请等待当前任务完成。
</NAlert>
<NAlert
v-else-if="latestIdentityFailure"
type="error"
:show-icon="false"
class="mb-4 text-xs"
>
最近一次身份图片生成失败:{{ latestIdentityFailure.error || '未返回具体错误' }}。可以调整模型参数后重新生成。
</NAlert>
<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"
: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-workspace {
@apply grid grid-cols-[240px_minmax(0,_1fr)] items-start gap-5;
}
.identity-subject-list {
@apply max-h-[560px] 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) {
.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))];
}
}
.identity-workspace-page {
container: identity-header / inline-size;
}
.identity-prerequisite {
@apply shrink-0 mx-0 mb-3;
}
.identity-flow {
@apply p-4 bg-(--app-subtle);
}
.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;
}
.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;
}
.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-2.5 pt-0 px-3 pb-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;
}
.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];
}
.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-next-action {
@apply items-start flex-col;
}
.identity-workspace {
@apply grid-cols-[minmax(0,_1fr)] grid-rows-[auto_minmax(0,_1fr)] gap-2.5;
}
.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>