feat(short-drama-agent-front): 完善主体身份骨架屏与交互反馈

This commit is contained in:
GJ committed 2026-10-11 17:23:14 +08:00
1 parent 5fa1c251a9
commit dd0bd79a35
19 files changed
+1552 -419

No files matched your search

@@ -5,12 +5,13 @@ import { useProjectGenerationRevision } from '../generation-config/context'
import { generationConfigApi } from '../generation-config/api'
import { subjectImagesApi } from '../subject-images/api'
import { hasRunningImages } from '../subject-images/model'
import { runOperation } from '../workflows/operations'
import { runOperation, type OperationNotice } from '../workflows/operations'
import { useProjectMutationGuard } from '../workflows/useProjectMutationGuard'
import { useProjectContext } from '../projects/context'
import { subjectIdentityApi } from './api'
import { canBeAnchor, getIdentitySession, groupIdentitySubjects, mergeCastingSubjects } from './model'
import type {
IdentityImageOperation,
IdentityValidationResult,
StableAnchorQualityInput,
StableAnchorQualityResult,
@@ -185,6 +186,46 @@ export function useSubjectIdentity() {
const validationResult = computed(() => validationResults.value[selectedId.value] ?? null)
/** 当前主体的质量闭环回执。 */
const qualityResult = computed(() => qualityResults.value[selectedId.value] ?? null)
/** 固定图片请求目标,切换主体后不把旧请求的加载状态附在新图片上。 */
const pendingImageOperation = ref<IdentityImageOperation | null>(null)
/**
* 执行已确认的图片操作,并让加载状态持续到响应核对及刷新完成。
* @param kind 图片操作类型
* @param imageId 提交时固定的正式图片编号
* @param label 包含主体名称的操作提示
* @param action 提交请求并核验结果
* @param feedback 按实际结果显示的临时消息
* @returns 请求及结果核验是否成功
*/
async function runImageOperation<T>(
kind: IdentityImageOperation['kind'],
imageId: string,
label: string,
action: () => Promise<T>,
feedback: OperationNotice | ((result: T) => OperationNotice)
) {
if (operation.value.pending || !subject.value) return false
pendingImageOperation.value = { kind, imageId, subjectId: subject.value.id, projectId: projectId.value }
try {
return await runOperation(projectId.value, label, action, feedback)
} finally {
pendingImageOperation.value = null
}
}
/**
* 图片确认后刷新目录、选角与准入状态,仅更新仍在原主体的详情。
* @param project 请求提交时的项目编号
* @param subjectId 请求提交时的主体编号
*/
async function refreshImageConfirmation(project: string, subjectId: string) {
if (projectId.value !== project) return
await Promise.all([
catalog.refresh(),
castingQuery.refresh(),
projectContext.refreshStageReadiness(),
...(selectedId.value === subjectId ? [detail.refresh()] : [])
])
}
/**
* 校验当前主体的正式图片,费用确认由图库负责。
* @param imageId 指定正式身份图片 ID
@@ -193,13 +234,24 @@ export function useSubjectIdentity() {
const image = images.value.find(item => item.id === imageId)
if (detailBlocked.value || !subject.value || image?.status !== 'completed' || !image.imageUrl) return
const id = subject.value.id
const project = projectId.value
const name = subject.value.name
delete validationResults.value[id]
await runOperation(project, '校验身份参考图质量', async () => {
const result = await subjectIdentityApi.validateImage(id, imageId)
if (result.subjectId !== id || result.imageId !== imageId) throw new Error('身份校验回执与提交目标不匹配')
validationResults.value[id] = result
})
await runImageOperation(
'validate',
imageId,
`校验 ${name} 身份图片`,
async () => {
const result = await subjectIdentityApi.validateImage(id, imageId)
if (result.subjectId !== id || result.imageId !== imageId)
throw new Error('身份校验回执与提交目标不匹配')
validationResults.value[id] = result
return result
},
result => ({
type: result.passed ? 'success' : 'warning',
content: `${name} 的身份图片校验${result.passed ? '通过' : '未通过'}:${result.summary}`
})
)
}
/**
* 为场景或道具执行有限预算质量闭环,仅按真实回执确认锁定。
@@ -218,32 +270,42 @@ export function useSubjectIdentity() {
const id = subject.value.id
const identityId = identity.value.id
const project = projectId.value
const name = subject.value.name
delete qualityResults.value[id]
await runOperation(project, '生成稳定身份母版并校验质量', async () => {
const result = await subjectIdentityApi.generateStableAnchorQuality(id, input)
if (
result.passed &&
(!result.confirmed ||
result.confirmed.subjectId !== id ||
result.confirmed.identityId !== identityId ||
!result.confirmed.isLocked ||
!result.confirmed.anchor.isAnchor ||
result.confirmed.anchor.id !== result.imageId)
)
throw new Error('质量生成的母版与锁定回执未确认,请刷新核对')
qualityResults.value[id] = result
})
if (projectId.value === project) {
await Promise.all([
catalog.refresh(),
castingQuery.refresh(),
projectContext.refreshStageReadiness(),
...(selectedId.value === id ? [detail.refresh()] : [])
])
}
await runOperation(
project,
`生成 ${name} 稳定身份母版并校验质量`,
async () => {
const result = await subjectIdentityApi.generateStableAnchorQuality(id, input)
if (
result.passed &&
(!result.confirmed ||
result.confirmed.subjectId !== id ||
result.confirmed.identityId !== identityId ||
!result.confirmed.isLocked ||
!result.confirmed.anchor.isAnchor ||
result.confirmed.anchor.id !== result.imageId)
)
throw new Error('质量生成的母版与锁定回执未确认,请刷新核对')
qualityResults.value[id] = result
await refreshImageConfirmation(project, id)
return result
},
result => ({
type: result.passed ? 'success' : 'warning',
content: result.passed
? `${name} 的身份母版校验通过,已确认并锁定。`
: `${name} 的身份母版校验未通过,候选仍保留在图库。${result.stopReason || ''}`
})
)
}
/** 长请求跨主体切换后只更新原项目的操作回执,不用旧响应覆盖新主体。 */
/**
* 保存或生成身份后刷新项目准入状态,跨主体响应不覆盖新主体详情。
* @param label 操作反馈名称
* @param action 对指定主体执行的身份写入请求
* @returns 身份写入与当前项目状态刷新完成的异步结果
*/
async function writeIdentity(label: string, action: (id: string) => Promise<SubjectIdentity>) {
if (detailBlocked.value || !subject.value) return
const id = subject.value.id
@@ -258,7 +320,13 @@ export function useSubjectIdentity() {
dirty.value = false
}
})
if (ok) await Promise.all([detail.refresh(), castingQuery.refresh()])
if (ok && projectId.value === project) {
await Promise.all([
castingQuery.refresh(),
projectContext.refreshStageReadiness(),
...(selectedId.value === id ? [detail.refresh()] : [])
])
}
}
/** 人工保存可修改已锁定身份;锁定只阻止自动重生成。 */
@@ -363,7 +431,10 @@ export function useSubjectIdentity() {
await Promise.all([detail.refresh(), castingQuery.refresh()])
}
/** 生图不修改文字锁定;即使有自定义 Prompt,也需已有身份 Prompt 与项目风格。 */
/**
* 生图不修改文字锁定;即使有自定义提示词,也需已有身份提示词与项目风格。
* @param input 已确认的视图、模型与参考图片参数
*/
async function generateImage(input: GenerateIdentityImageInput) {
if (!canGenerateImage.value || !subject.value || !identity.value) return
if (
@@ -375,56 +446,86 @@ export function useSubjectIdentity() {
return
const id = subject.value.id
const identityId = identity.value.id
const ok = await runOperation(projectId.value, `提交 ${subject.value.name} 身份参考图生成`, async () => {
const image = await subjectIdentityApi.generateImage(id, input)
if (!image || image.identityId !== identityId || !['pending', 'generating'].includes(image.status)) {
throw new Error(image?.error || '身份参考图任务未成功创建,请刷新后重试。')
}
})
if (ok) {
await detail.refresh()
operation.value.notice = `${subject.value.name} 身份参考图已提交生成,可稍后刷新查看结果。`
}
const project = projectId.value
const name = subject.value.name
await runOperation(
project,
`提交 ${name} 身份参考图生成`,
async () => {
const image = await subjectIdentityApi.generateImage(id, input)
if (!image || image.identityId !== identityId || !['pending', 'generating'].includes(image.status)) {
throw new Error(image?.error || '身份参考图任务未成功创建,请刷新后重试。')
}
if (projectId.value === project && selectedId.value === id) await detail.refresh()
},
{ type: 'info', content: `${name} 的身份参考图已提交生成,完成后会显示结果。` }
)
}
/** 单角色候选图固定为独立 primary,不复用旧 Anchor,生成成功后仍需人工确认选角。 */
/**
* 单角色候选图固定独立生成,不复用旧母版,生成成功后仍需人工确认选角。
* @param input 已确认的候选图模型与生成参数
*/
async function generateCastingCandidate(input: GenerateCastingCandidateInput) {
if (!canGenerateCandidate.value || !subject.value || !identity.value) return
const id = subject.value.id
const identityId = identity.value.id
const ok = await runOperation(projectId.value, `提交 ${subject.value.name} 选角候选生成`, async () => {
const image = await subjectIdentityApi.generateCastingCandidate(id, input)
if (!image || image.identityId !== identityId || !['pending', 'generating'].includes(image.status)) {
throw new Error(image?.error || '选角候选任务未成功创建,请刷新后重试。')
}
})
if (ok) {
await Promise.all([detail.refresh(), castingQuery.refresh(), catalog.refresh()])
operation.value.notice = `${subject.value.name} 选角候选已提交生成,可稍后刷新查看结果。`
}
const project = projectId.value
const name = subject.value.name
await runOperation(
project,
`提交 ${name} 角色候选图生成`,
async () => {
const image = await subjectIdentityApi.generateCastingCandidate(id, input)
if (!image || image.identityId !== identityId || !['pending', 'generating'].includes(image.status)) {
throw new Error(image?.error || '选角候选任务未成功创建,请刷新后重试。')
}
if (projectId.value === project)
await Promise.all([
castingQuery.refresh(),
catalog.refresh(),
...(selectedId.value === id ? [detail.refresh()] : [])
])
},
{ type: 'info', content: `${name} 的角色候选图已提交生成,完成后会显示结果。` }
)
}
/** 候选切换母版只允许成功的 primary 图,不能将辅助视角直接升级为母版。 */
/**
* 候选切换母版只允许成功的 primary 图,不能将辅助视角直接升级为母版。
* @param imageId 要切换的正式身份图片编号
*/
async function setAnchor(imageId: string) {
const image = images.value.find(item => item.id === imageId)
if (detailBlocked.value || !subject.value || !image || !canBeAnchor(image) || image.isAnchor) return
const id = subject.value.id
const identityId = image.identityId
await runOperation(projectId.value, '切换主体身份母版', async () => {
const result = await subjectIdentityApi.setAnchor(id, imageId)
if (
!result ||
result.id !== imageId ||
result.identityId !== identityId ||
!result.isAnchor ||
!canBeAnchor(result)
)
throw new Error('身份母版切换结果未确认,请刷新后核对。')
})
await detail.refresh()
const project = projectId.value
const name = subject.value.name
await runImageOperation(
'confirm',
imageId,
`切换 ${name} 身份母版`,
async () => {
const result = await subjectIdentityApi.setAnchor(id, imageId)
if (
!result ||
result.id !== imageId ||
result.identityId !== identityId ||
!result.isAnchor ||
!canBeAnchor(result)
)
throw new Error('身份母版切换结果未确认,请刷新后核对。')
await refreshImageConfirmation(project, id)
},
{ type: 'success', content: `${name} 的身份母版已切换。` }
)
}
/** Scene / Prop 人工确认母版时原子完成 Anchor 切换与 Identity 锁定。 */
/**
* 场景或道具人工确认母版时原子完成母版切换与身份锁定。
* @param imageId 要确认的正式身份图片编号
*/
async function confirmStableAnchor(imageId: string) {
const image = images.value.find(item => item.id === imageId)
if (
@@ -437,24 +538,35 @@ export function useSubjectIdentity() {
return
const subjectId = subject.value.id
const identityId = identity.value.id
await runOperation(projectId.value, `确认 ${subject.value.name} 身份母版`, async () => {
const result = await subjectIdentityApi.confirmStableAnchor(subjectId, imageId)
if (
!result ||
result.identityId !== identityId ||
result.subjectId !== subjectId ||
!result.isLocked ||
result.anchor.id !== imageId ||
!result.anchor.isAnchor ||
result.anchor.identityId !== identityId ||
!canBeAnchor(result.anchor)
)
throw new Error('身份母版确认结果未保存,请刷新后核对。')
})
await Promise.all([detail.refresh(), catalog.refresh()])
const project = projectId.value
const name = subject.value.name
await runImageOperation(
'confirm',
imageId,
`确认 ${name} 身份母版`,
async () => {
const result = await subjectIdentityApi.confirmStableAnchor(subjectId, imageId)
if (
!result ||
result.identityId !== identityId ||
result.subjectId !== subjectId ||
!result.isLocked ||
result.anchor.id !== imageId ||
!result.anchor.isAnchor ||
result.anchor.identityId !== identityId ||
!canBeAnchor(result.anchor)
)
throw new Error('身份母版确认结果未保存,请刷新后核对。')
await refreshImageConfirmation(project, subjectId)
},
{ type: 'success', content: `${name} 的身份母版已确认并锁定。` }
)
}
/** Character 确认选角必须原子切换 Anchor 并锁定 Identity。 */
/**
* 角色确认选角必须原子切换身份母版并锁定身份。
* @param imageId 要确认的正式角色图片编号
*/
async function confirmCasting(imageId: string) {
const image = images.value.find(item => item.id === imageId)
if (
@@ -468,21 +580,29 @@ export function useSubjectIdentity() {
return
const subjectId = subject.value.id
const identityId = identity.value.id
await runOperation(projectId.value, `确认 ${subject.value.name} 角色选角`, async () => {
const result = await subjectIdentityApi.confirmCasting(subjectId, imageId)
if (
!result ||
result.identityId !== identityId ||
result.subjectId !== subjectId ||
!result.isLocked ||
result.anchor.id !== imageId ||
!result.anchor.isAnchor ||
result.anchor.identityId !== identityId ||
!canBeAnchor(result.anchor)
)
throw new Error('角色选角确认结果未保存,请刷新后核对。')
})
await Promise.all([detail.refresh(), castingQuery.refresh(), projectContext.refreshStageReadiness()])
const project = projectId.value
const name = subject.value.name
await runImageOperation(
'confirm',
imageId,
`确认 ${name} 角色选角`,
async () => {
const result = await subjectIdentityApi.confirmCasting(subjectId, imageId)
if (
!result ||
result.identityId !== identityId ||
result.subjectId !== subjectId ||
!result.isLocked ||
result.anchor.id !== imageId ||
!result.anchor.isAnchor ||
result.anchor.identityId !== identityId ||
!canBeAnchor(result.anchor)
)
throw new Error('角色选角确认结果未保存,请刷新后核对。')
await refreshImageConfirmation(project, subjectId)
},
{ type: 'success', content: `${name} 的角色选角已确认,身份已锁定。` }
)
}
return {
@@ -529,6 +649,7 @@ export function useSubjectIdentity() {
confirmStableAnchor,
confirmCasting,
validateImage,
pendingImageOperation,
generateStableAnchorQuality,
validationResult,
qualityResult