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

@@ -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} 的角色选角已确认,身份已锁定。` }