feat(short-drama-agent-front): 支持母版复用并优化生成交互
This commit is contained in:
1 parent
49fb9c7a27
commit
ee5e49957a
28 files changed
+634
-326
No files matched your search
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user