feat(short-drama-agent-front): 支持母版复用并优化生成交互

This commit is contained in:
GJ committed 2026-10-12 15:22:03 +08:00
1 parent 49fb9c7a27
commit ee5e49957a
28 files changed
+634 -326

No files matched your search

@@ -90,16 +90,6 @@ 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)
return {
type: 'info' as const,
message: `${subject.value.name} 的身份图片正在生成,刷新页面不会重复提交,请等待当前任务完成。`
}
return null
})
/** 首次读取目录才替换整页,刷新已有主体时保留选择与阅读位置。 */
const initialLoading = computed(() => catalog.loading.value && !catalog.data.value)
/** 切换主体时只替换尚未返回的详情,不遮挡已读取的主体目录。 */
@@ -220,21 +210,42 @@ function exportReceipt() {
downloadText('subject-identities-receipt.json', JSON.stringify(session.value.receipt, null, 2), 'application/json')
}
/** Character 使用确认选角事务;Scene / Prop 保留普通母版切换。 */
/**
* 前置校验通过并开始提交时关闭原主体弹窗,后续状态通过消息反馈。
* @param input 已确认的身份图生成参数
* @returns 提交与详情刷新完成
*/
async function submitIdentityImage(input: Parameters<typeof generateImage>[0]) {
await generateImage(input)
if (!operation.value.error) imageOpen.value = false
const targetId = selectedId.value
await generateImage(input, () => {
if (selectedId.value === targetId) imageOpen.value = false
})
}
/**
* 前置校验通过并开始提交时关闭原主体选角弹窗,不等待接口返回。
* @param input 已确认的选角生成参数
* @returns 提交与列表刷新完成
*/
async function submitCastingCandidate(input: Parameters<typeof generateCastingCandidate>[0]) {
await generateCastingCandidate(input)
if (!operation.value.error) castingOpen.value = false
const targetId = selectedId.value
await generateCastingCandidate(input, () => {
if (selectedId.value === targetId) castingOpen.value = false
})
}
/** Character 使用确认选角事务;Scene / Prop 保留普通母版切换。 */
/**
* 按主体类型确认母版,成功后关闭原主体的管理弹窗。
* @param imageId 用户明确选择的图片编号
*/
function chooseAnchor(imageId: string) {
if (subject.value?.module === 'character') void confirmCasting(imageId)
else void confirmStableAnchor(imageId)
const targetId = selectedId.value
/** 迟到响应不能关闭另一个主体的弹窗。 */
const closeConfirmedDialog = () => {
if (selectedId.value === targetId) identityGallery.value?.closeCandidates()
}
if (subject.value?.module === 'character') void confirmCasting(imageId, closeConfirmedDialog)
else void confirmStableAnchor(imageId, closeConfirmedDialog)
}
/** 当前主体生图暂不可用时,在失败记录旁说明具体恢复步骤。 */
const imageRetryDisabledReason = computed(() => {
@@ -356,8 +367,9 @@ const nextAction = computed<{ action: IdentityFlowAction; title: string; descrip
return {
action: 'confirm',
title: '第 3 步:确认并锁定',
description: '在“管理候选”弹窗中确认母版;人物会同时锁定,场景和道具还需保存锁定状态。',
label: '管理候选并确认'
description:
'在下方图片卡片中确认母版;其他图片可通过“管理候选”查看。人物会同时锁定,场景和道具还需保存锁定状态。',
label: '查看候选并确认'
}
return {
action: 'forms',
@@ -374,7 +386,7 @@ 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()
@@ -382,7 +394,7 @@ function runNextAction() {
if (subject.value?.module === 'character') castingOpen.value = true
else imageOpen.value = true
} else if (nextAction.value.action === 'confirm') {
identityGallery.value?.openCandidates()
document.querySelector('#identity-reference-gallery')?.scrollIntoView({ behavior: 'smooth', block: 'center' })
} else if (nextAction.value.action === 'lock') {
document.querySelector('#identity-lock')?.scrollIntoView({ behavior: 'smooth', block: 'center' })
} else if (nextAction.value.action === 'forms' && subjectImagesAccess.value.enabled) {
@@ -720,19 +732,6 @@ function runNextAction() {
</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">
<!-- 以下是主体目录模块,标题和搜索固定,条目通过独立滚动容器浏览。 -->
@@ -900,7 +899,7 @@ function runNextAction() {
@anchor="chooseAnchor"
@regenerate="retryIdentityImage"
>
<!-- 以下是母版卡片底部的生成入口模块,候选在独立弹窗中管理 -->
<!-- 以下是母版卡片底部的生成入口模块,单张候选直接展示,多张候选在弹窗中管理 -->
<template #actions>
<NButton
v-if="subject.module === 'scene' || subject.module === 'prop'"
@@ -1034,40 +1033,10 @@ function runNextAction() {
.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;
+6 -1
View File
@@ -1,6 +1,7 @@
import { request } from '../../lib/http'
import type {
IdentityImagePreview,
IdentityImageGenerationStart,
IdentityValidationResult,
StableAnchorQualityInput,
StableAnchorQualityResult,
@@ -74,7 +75,11 @@ export const subjectIdentityApi = {
listImages: (subjectId: string, signal?: AbortSignal) =>
request<IdentityImage[]>(`${identityPath(subjectId)}/images`, { signal }),
generateImage: (subjectId: string, input: GenerateIdentityImageInput) =>
request<IdentityImage>(`${identityPath(subjectId)}/images`, { method: 'POST', body: input, timeoutMs: 0 }),
request<IdentityImageGenerationStart>(`${identityPath(subjectId)}/images`, {
method: 'POST',
body: input,
timeoutMs: 0
}),
/**
* 读取与实际生图同源的输入预览,道具可能执行已确认的结构模型编译。
* @param subjectId 正式主体 ID
@@ -1,13 +1,14 @@
<script setup lang="ts">
import { NButton, NTag } from 'naive-ui'
import { LoaderCircle } from '@lucide/vue'
import { computed, ref, watch } from 'vue'
import { AppDialog } from '../../../components/ui'
import { candidateDialogWidth } from '../../../lib/candidate-layout'
import { canBeAnchor, currentAnchor } from '../model'
import { currentAnchor } from '../model'
import type { IdentityImage, IdentityImageOperation } from '../types'
import IdentityImageCard from './IdentityImageCard.vue'
/** 身份图片主区域只展示正式母版,候选与辅助图在弹窗中管理。 */
/** 身份图片主区域展示正式母版与单张候选,多张候选和辅助图使用管理弹窗。 */
const props = defineProps<{
/** 后端正式身份图片列表。 */
images: IdentityImage[]
@@ -35,14 +36,27 @@ const emit = defineEmits<{
}>()
/** 母版仅认后端正式标记,不用首张候选填补空状态。 */
const anchor = computed(() => currentAnchor(props.images))
/** 其余 primary、辅助视图与未完成记录集中在管理弹窗。 */
/** 除正式母版外的候选、辅助视图与未完成记录。 */
const candidates = computed(() => props.images.filter(image => image.id !== anchor.value?.id))
/** 只有已完成的 primary 候选才可引导用户确认母版。 */
const hasPrimaryCandidate = computed(() => candidates.value.some(canBeAnchor))
/** 当前主体正在排队或生成的图片数量,候选数量不影响进度展示。 */
const generatingCount = computed(
() => props.images.filter(image => image.status === 'pending' || image.status === 'generating').length
)
/** 主内容优先展示正式母版、成功候选、生成中记录,最后回退到失败记录。 */
const displayImage = computed(
() =>
anchor.value ??
candidates.value.find(image => image.status === 'completed' && !!image.imageUrl) ??
candidates.value.find(image => image.status === 'pending' || image.status === 'generating') ??
candidates.value[0] ??
null
)
/** 弹窗仅展示主内容之外的记录,避免同一图片和操作重复出现。 */
const managedCandidates = computed(() => props.images.filter(image => image.id !== displayImage.value?.id))
/** 候选管理弹窗开关。 */
const candidatesOpen = ref(false)
/** 候选弹窗按固定卡片宽度适配列数,并由公共弹窗限制视口宽度。 */
const candidatesWidth = computed(() => candidateDialogWidth(candidates.value.length))
const candidatesWidth = computed(() => candidateDialogWidth(managedCandidates.value.length))
/** 母版卡片说明与身份锁定状态一致。 */
const anchorDescription = computed(() =>
props.identityLocked ? '后续形态图片会使用此母版。' : '请先锁定身份,后续形态图片才会稳定引用此母版。'
@@ -54,9 +68,16 @@ watch(
candidatesOpen.value = false
}
)
/** 为步骤引导提供候选入口,打开弹窗只读取已有图片。 */
/** 没有剩余候选时关闭管理弹窗,主内容始终保留当前卡片。 */
watch(
() => managedCandidates.value.length,
count => {
if (count === 0) candidatesOpen.value = false
}
)
/** 为步骤引导提供多候选管理入口,单张候选直接在页面内操作。 */
function openCandidates() {
if (candidates.value.length) candidatesOpen.value = true
if (managedCandidates.value.length) candidatesOpen.value = true
}
/**
* 关闭候选弹窗后打开原图片类型的参数设置,避免多个生成弹窗重叠。
@@ -66,54 +87,70 @@ function regenerate(imageId: string) {
candidatesOpen.value = false
emit('regenerate', imageId)
}
/** 暴露只读管理入口供主体身份步骤引导复用。 */
defineExpose({ openCandidates })
/** 后端确认母版成功后立即收起管理弹窗,不等待列表刷新。 */
function closeCandidates() {
candidatesOpen.value = false
}
/** 暴露候选浏览与提交成功关闭入口。 */
defineExpose({ openCandidates, closeCandidates })
</script>
<template>
<section class="identity-gallery mt-5 pt-5" aria-label="身份参考图库">
<!-- 以下是正式身份母版模块,主页面不展示候选与重复预览 -->
<!-- 以下是正式身份母版模块,仅展示后端正式确认的母版 -->
<div class="identity-gallery-toolbar">
<h3 class="text-sm font-medium">身份母版</h3>
<NTag v-if="!anchor" size="small" :bordered="false">尚无母版</NTag>
</div>
<div v-if="anchor" class="identity-anchor-grid mt-4">
<p v-if="!displayImage" class="mt-4 text-xs leading-6 text-muted">
尚无身份图片。先保存身份文本,再生成母版候选。
</p>
<!-- 以下是图库内持续展示的生成状态,完成或失败后随真实任务状态移除 -->
<p
v-if="generatingCount"
role="status"
aria-live="polite"
class="mt-4 flex items-center gap-2 text-xs leading-6 text-muted"
>
<LoaderCircle :size="16" class="animate-spin motion-reduce:animate-none" aria-hidden="true" />
正在生成中<span v-if="generatingCount > 1">({{ generatingCount }} 张)</span>,完成后会自动更新图片。
</p>
<!-- 以下是当前图片与生成、确认或失败状态模块,不经过候选管理弹窗 -->
<div v-if="displayImage" class="identity-anchor-grid mt-4">
<IdentityImageCard
:image="anchor"
:key="displayImage.id"
:image="displayImage"
:subject-name="subjectName"
:module="module"
:identity-locked="identityLocked"
:disabled="disabled"
:pending-operation="pendingOperation"
:description="anchorDescription"
:retry-disabled-reason="retryDisabledReason"
:active="true"
:description="displayImage.isAnchor ? anchorDescription : undefined"
@anchor="emit('anchor', $event)"
@validate="emit('validate', $event)"
@regenerate="regenerate"
/>
</div>
<p v-else class="mt-4 text-xs leading-6 text-muted">
{{
hasPrimaryCandidate
? '尚未确认身份母版。请在“管理候选”中选择已完成的母版候选并确认。'
: candidates.length
? '尚无可确认的母版候选。请生成母版候选,已有图片可在“管理候选”中查看。'
: '尚无身份母版。先保存身份文本,再生成母版候选。'
}}
</p>
<!-- 以下是与镜头生产一致的底部图片操作模块 -->
<div class="identity-gallery-actions">
<NButton v-if="candidates.length" @click="openCandidates">管理候选({{ candidates.length }})</NButton>
<NButton v-if="managedCandidates.length" @click="openCandidates"
>管理候选({{ managedCandidates.length }})</NButton
>
<slot name="actions" />
</div>
<!-- 以下是候选与辅助图片管理弹窗模块,确认和校验始终针对具体图片 -->
<AppDialog
v-if="managedCandidates.length"
v-model:open="candidatesOpen"
title="身份候选管理"
:description="`${subjectName} 的候选与辅助参考图;确认母版后,主页面会展示新母版。辅助参考图不能设为母版。`"
:description="`${subjectName} 的其他候选与辅助参考图;已在主页面展示的图片不重复列出。辅助参考图不能设为母版。`"
:width="candidatesWidth"
>
<div class="identity-candidate-grid">
<IdentityImageCard
v-for="image in candidates"
v-for="image in managedCandidates"
:key="image.id"
:image="image"
:subject-name="subjectName"
@@ -62,9 +62,11 @@ const canSelect = computed(
/** 卡片标识区分身份母版、母版候选和辅助视角,不重复强调当前状态。 */
const imageLabel = computed(() =>
props.image.isAnchor
? '身份母版'
? '已确认母版'
: props.image.viewType === 'primary'
? '母版候选'
? props.image.status === 'completed'
? '母版候选 · 未确认'
: '母版候选'
: identityViewLabels[props.image.viewType]
)
/** 后台重启表示原请求结果未知,不能误导用户直接调整模型参数。 */
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { referenceGenerationCatalog, referenceGenerationOptions } from '../reference-generation'
import ConfirmAction from '../../workflows/ConfirmAction.vue'
import { getOperation, runOperation } from '../../workflows/operations'
import AppForm from '../../../components/ui/AppForm.vue'
@@ -96,13 +97,21 @@ watch(
{ immediate: true }
)
/** 道具由后端加入结构参考图;其它主体显式或自动引用母版时也按图生图约束。 */
const usesReferenceImages = computed(() => props.module === 'prop' || !!referenceImageId.value || !!anchor.value)
/** 当前流程可用的模型参数,避免选择 Qwen 不支持的扩写模式。 */
const compatibleCatalog = computed(() => referenceGenerationCatalog(props.catalog, usesReferenceImages.value))
/** 控件、预览与提交共享同一份兼容参数。 */
const compatibleOptions = computed(() =>
referenceGenerationOptions(provider.value, generationOptions.value, usesReferenceImages.value)
)
/** 预览与正式生图共享的最终请求参数。 */
const generationInput = computed<GenerateIdentityImageInput>(() => ({
viewType: props.module === 'character' ? viewType.value : 'primary',
...(referenceImageId.value ? { referenceImageId: referenceImageId.value } : {}),
...(prompt.value.trim() ? { prompt: prompt.value.trim() } : {}),
provider: provider.value,
generationOptions: { ...generationOptions.value }
generationOptions: { ...compatibleOptions.value }
}))
/** 当前参数的预览结果。 */
const preview = ref<IdentityImagePreview | null>(null)
@@ -198,7 +207,13 @@ const rules = {
调用 图片模型,每次新增一张图片,可能产生费用。第一张成功的 primary 图自动成为母版;已有母版时,新
primary 图仅作为停用候选保留。
</NAlert>
<NFormItem class="block" path="viewType" label="参考视角" :label-props="{ for: 'identity-view' }"
<!-- 以下是多视角与已有身份图选择模块,单一选项不显示选择器 -->
<NFormItem
v-if="allowedViews.length > 1"
class="block"
path="viewType"
label="参考视角"
:label-props="{ for: 'identity-view' }"
><NSelect
id="identity-view"
v-model:value="viewType"
@@ -207,6 +222,7 @@ const rules = {
></NSelect
></NFormItem>
<NFormItem
v-if="references.length"
class="block"
path="referenceImageId"
label="身份锚定来源"
@@ -223,7 +239,7 @@ const rules = {
v-model:value="referenceImageId"
:options="[
{
label: String(anchor ? '自动引用当前身份母版' : '自动选择(当前无母版,将按文本生成)'),
label: String(anchor ? '自动引用当前身份母版' : '自动选择(由后端解析参考图)'),
value: ''
},
...references.map(image => ({
@@ -253,9 +269,9 @@ const rules = {
</p>
<GenerationModelControls
type="image"
:catalog="catalog"
:catalog="compatibleCatalog"
:provider="provider"
:options="generationOptions"
:options="compatibleOptions"
:aspect-ratio="profile.aspectRatio"
:disabled="disabled"
@update:provider="provider = $event"
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { referenceGenerationCatalog, referenceGenerationOptions } from '../reference-generation'
import { computed, ref, watch } from 'vue'
import { NAlert, NButton, NCheckbox, NInputNumber } from 'naive-ui'
import { AppDialog } from '../../../components/ui'
@@ -27,6 +28,10 @@ const emit = defineEmits<{ generate: [input: StableAnchorQualityInput] }>()
const provider = ref('')
/** 本次图片参数。 */
const options = ref<GenerationOptions>({})
/** 稳定母版质量流程可能使用结构图或修复参考图,统一使用兼容模式。 */
const compatibleCatalog = computed(() => referenceGenerationCatalog(props.catalog, true))
/** 展示和提交的参数一致,不继承项目中不兼容的 agent 模式。 */
const compatibleOptions = computed(() => referenceGenerationOptions(provider.value, options.value, true))
/** 最多修复次数。 */
const maxRepairAttempts = ref(0)
/** 明确费用确认。 */
@@ -68,7 +73,7 @@ function submit() {
if (props.disabled || !valid.value || !acknowledged.value) return
emit('generate', {
provider: provider.value,
generationOptions: { ...options.value },
generationOptions: { ...compatibleOptions.value },
maxRepairAttempts: maxRepairAttempts.value
})
open.value = false
@@ -86,9 +91,9 @@ function submit() {
>
<GenerationModelControls
type="image"
:catalog="catalog"
:catalog="compatibleCatalog"
:provider="provider"
:options="options"
:options="compatibleOptions"
:aspect-ratio="profile.aspectRatio"
:disabled="disabled"
@update:provider="provider = $event"
@@ -0,0 +1,47 @@
import type { GenerationModelCatalog, GenerationOptions } from '../generation-config/types'
/**
* 按参考图链路约束 Qwen 参数,不修改项目默认配置。
* @param provider 当前图片供应方
* @param options 本次生成参数
* @param hasReference 是否可能使用结构、身份或修复参考图
* @returns 与参考图兼容的独立参数
*/
export function referenceGenerationOptions(provider: string, options: GenerationOptions, hasReference: boolean) {
return provider === 'qwen-image' && hasReference ? { ...options, promptExtendMode: 'direct' } : { ...options }
}
/**
* 参考图流程只提供 Qwen 支持的扩写模式,切换模型时也使用兼容默认值。
* @param catalog 后端模型目录
* @param hasReference 当前流程是否可能携带参考图
* @returns 当前流程专用目录
*/
export function referenceGenerationCatalog(
catalog: GenerationModelCatalog,
hasReference: boolean
): GenerationModelCatalog {
if (!hasReference) return catalog
return {
...catalog,
images: catalog.images.map(model =>
model.provider !== 'qwen-image'
? model
: {
...model,
defaults: referenceGenerationOptions(model.provider, model.defaults, true),
generationOptions: model.generationOptions.map(option =>
option.key !== 'promptExtendMode'
? option
: {
...option,
options: option.options?.filter(choice => choice.value === 'direct'),
providerDefault: 'direct',
userEditable: false,
description: '此流程可能使用结构或身份参考图,Qwen 图生图仅支持直接增强。'
}
)
}
)
}
}
+8
View File
@@ -33,6 +33,14 @@ export interface IdentityImage {
updatedAt: string
}
/** 普通身份生图接口的异步提交回执,图片记录位于 image 字段。 */
export interface IdentityImageGenerationStart {
/** 已持久化的后台任务编号。 */
executionId: string
/** 本次创建的图片记录,用于立即显示生成状态。 */
image: IdentityImage
}
/** 稳定身份描述及生图提示词,不混入具体形态的临时状态。 */
export interface SubjectIdentity {
id: string
@@ -1,4 +1,4 @@
import { computed, ref, watch } from 'vue'
import { computed, ref, shallowRef, watch } from 'vue'
import { usePolling } from '../../composables/usePolling'
import { visualStyleApi } from '../visual-style'
import { useProjectGenerationRevision } from '../generation-config/context'
@@ -95,11 +95,13 @@ export function useSubjectIdentity() {
)
const subject = computed(() => subjects.value.find(item => item.id === selectedId.value))
const selectionKey = computed(() => subject.value?.id ?? '')
const detailRef = {} as {
current?: ReturnType<typeof usePolling<{ identity: SubjectIdentity | null; images: IdentityImage[] }>>
}
/** 延后关联详情查询,使用响应式引用让任务轮询在查询建立后重新计算。 */
const detailRef = shallowRef<ReturnType<
typeof usePolling<{ identity: SubjectIdentity | null; images: IdentityImage[] }>
> | null>(null)
/** 仅当前主体存在未结束图片时轮询,终态后停止。 */
const detailPollInterval = computed(() =>
detailRef.current?.data.value?.images.some(image => image.status === 'pending' || image.status === 'generating')
detailRef.value?.data.value?.images.some(image => image.status === 'pending' || image.status === 'generating')
? 4000
: false
)
@@ -116,7 +118,23 @@ export function useSubjectIdentity() {
},
detailPollInterval
)
detailRef.current = detail
detailRef.value = detail
/** 图片从生成中进入终态后同步母版、目录、选角和阶段准入,切换主体不消费旧结果。 */
watch(detail.data, (current, previous) => {
if (!current?.identity || !previous?.identity || current.identity.id !== previous.identity.id) return
if (current.identity.subjectId !== selectedId.value) return
const runningIds = new Set(
previous.images
.filter(image => image.status === 'pending' || image.status === 'generating')
.map(image => image.id)
)
if (
current.images.some(
image => runningIds.has(image.id) && (image.status === 'completed' || image.status === 'failed')
)
)
void refreshImageConfirmation(projectId.value, selectedId.value)
})
const identity = computed(() => detail.data.value?.identity ?? null)
const images = computed(() => detail.data.value?.images ?? [])
const castingItem = computed(() =>
@@ -433,8 +451,9 @@ export function useSubjectIdentity() {
/**
* 生图不修改文字锁定;即使有自定义提示词,也需已有身份提示词与项目风格。
* @param input 已确认的视图、模型与参考图片参数
* @param onSubmitStarted 通过前置检查并开始提交时的回调
*/
async function generateImage(input: GenerateIdentityImageInput) {
async function generateImage(input: GenerateIdentityImageInput, onSubmitStarted?: () => void) {
if (!canGenerateImage.value || !subject.value || !identity.value) return
if (
input.referenceImageId &&
@@ -451,11 +470,27 @@ export function useSubjectIdentity() {
project,
`提交 ${name} 身份参考图生成`,
async () => {
const image = await subjectIdentityApi.generateImage(id, input)
if (!image || image.identityId !== identityId || !['pending', 'generating'].includes(image.status)) {
onSubmitStarted?.()
const started = await subjectIdentityApi.generateImage(id, input)
const image = started?.image
if (
!started?.executionId ||
!image ||
image.identityId !== identityId ||
!['pending', 'generating'].includes(image.status)
) {
throw new Error(image?.error || '身份参考图任务未成功创建,请刷新后重试。')
}
if (projectId.value === project && selectedId.value === id) await detail.refresh()
if (projectId.value === project && selectedId.value === id) {
// 先展示真实回执中的生成记录,后续读取失败也能保留状态并继续轮询。
const current = detail.data.value
if (current?.identity?.id === identityId)
detail.data.value = {
...current,
images: [image, ...current.images.filter(item => item.id !== image.id)]
}
await detail.refresh()
}
},
{ type: 'info', content: `${name} 的身份参考图已提交生成,完成后会显示结果。` }
)
@@ -464,8 +499,9 @@ export function useSubjectIdentity() {
/**
* 单角色候选图固定独立生成,不复用旧母版,生成成功后仍需人工确认选角。
* @param input 已确认的候选图模型与生成参数
* @param onSubmitStarted 通过前置检查并开始提交时的回调
*/
async function generateCastingCandidate(input: GenerateCastingCandidateInput) {
async function generateCastingCandidate(input: GenerateCastingCandidateInput, onSubmitStarted?: () => void) {
if (!canGenerateCandidate.value || !subject.value || !identity.value) return
const id = subject.value.id
const identityId = identity.value.id
@@ -475,6 +511,7 @@ export function useSubjectIdentity() {
project,
`提交 ${name} 角色候选图生成`,
async () => {
onSubmitStarted?.()
const image = await subjectIdentityApi.generateCastingCandidate(id, input)
if (!image || image.identityId !== identityId || !['pending', 'generating'].includes(image.status)) {
throw new Error(image?.error || '选角候选任务未成功创建,请刷新后重试。')
@@ -524,8 +561,9 @@ export function useSubjectIdentity() {
/**
* 场景或道具人工确认母版时原子完成母版切换与身份锁定。
* @param imageId 要确认的正式身份图片编号
* @param onConfirmed 后端确认成功后的回调,不等待关联数据刷新
*/
async function confirmStableAnchor(imageId: string) {
async function confirmStableAnchor(imageId: string, onConfirmed?: () => void) {
const image = images.value.find(item => item.id === imageId)
if (
detailBlocked.value ||
@@ -556,6 +594,7 @@ export function useSubjectIdentity() {
!canBeAnchor(result.anchor)
)
throw new Error('身份母版确认结果未保存,请刷新后核对。')
onConfirmed?.()
await refreshImageConfirmation(project, subjectId)
},
{ type: 'success', content: `${name} 的身份母版已确认并锁定。` }
@@ -565,8 +604,9 @@ export function useSubjectIdentity() {
/**
* 角色确认选角必须原子切换身份母版并锁定身份。
* @param imageId 要确认的正式角色图片编号
* @param onConfirmed 后端确认成功后的回调,不等待关联数据刷新
*/
async function confirmCasting(imageId: string) {
async function confirmCasting(imageId: string, onConfirmed?: () => void) {
const image = images.value.find(item => item.id === imageId)
if (
detailBlocked.value ||
@@ -598,6 +638,7 @@ export function useSubjectIdentity() {
!canBeAnchor(result.anchor)
)
throw new Error('角色选角确认结果未保存,请刷新后核对。')
onConfirmed?.()
await refreshImageConfirmation(project, subjectId)
},
{ type: 'success', content: `${name} 的角色选角已确认,身份已锁定。` }