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

247 lines
11 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 ImageValidationPanel from '../../subject-images/components/ImageValidationPanel.vue'
import type { IdentityValidationResult } from '../types'
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 { currentAnchor } from '../model'
import type { IdentityImage, IdentityImageOperation } from '../types'
import IdentityImageCard from './IdentityImageCard.vue'
/** 身份图片主区域展示正式母版与单张候选,多张候选和辅助图使用管理弹窗。 */
const props = defineProps<{
/** 后端正式身份图片列表。 */
images: IdentityImage[]
/** 当前主体名称。 */
subjectName: string
/** 当前主体类型。 */
module: string
/** 当前主体身份是否已经锁定。 */
identityLocked: boolean
/** 当前项目或主体是否禁止写入。 */
disabled: boolean
/** 当前固定图片目标的确认或校验操作。 */
pendingOperation?: IdentityImageOperation | null
/** 当前正在读取历史审核的候选编号。 */
readingSavedReviewId?: string
/** 重新生成暂不可用的具体恢复步骤。 */
retryDisabledReason?: string
/** 本主体最近一次显式图片审核结果。 */
validationResult?: IdentityValidationResult | null
}>()
/** 图片操作交给父页面核验并执行,浏览候选不会修改母版。 */
const emit = defineEmits<{
/** 确认指定图片作为母版。 */
anchor: [imageId: string]
/** 校验指定图片。 */
validate: [imageId: string]
/** 只读查看已保存的审核。 */
readReview: [imageId: string]
/** 打开失败图片对应类型的生成参数弹窗。 */
regenerate: [imageId: string]
}>()
/** 母版仅认后端正式标记,不用首张候选填补空状态。 */
const anchor = computed(() => currentAnchor(props.images))
/** 除正式母版外的候选、辅助视图与未完成记录。 */
const candidates = computed(() => props.images.filter(image => image.id !== anchor.value?.id))
/** 当前主体正在排队或生成的图片数量,候选数量不影响进度展示。 */
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(managedCandidates.value.length))
/** 母版卡片说明与身份锁定状态一致。 */
const anchorDescription = computed(() =>
props.identityLocked ? '后续形态图片会使用此母版。' : '请先锁定身份,后续形态图片才会稳定引用此母版。'
)
/** 后端确认新母版后收起候选,直接展示更新后的母版;请求失败则保留弹窗。 */
watch(
() => anchor.value?.id,
() => {
candidatesOpen.value = false
}
)
/** 没有剩余候选时关闭管理弹窗,主内容始终保留当前卡片。 */
watch(
() => managedCandidates.value.length,
count => {
if (count === 0) candidatesOpen.value = false
}
)
/** 为步骤引导提供多候选管理入口,单张候选直接在页面内操作。 */
function openCandidates() {
if (managedCandidates.value.length) candidatesOpen.value = true
}
/**
* 关闭候选弹窗后打开原图片类型的参数设置,避免多个生成弹窗重叠。
* @param imageId 用户选择重新生成的失败图片编号
*/
function regenerate(imageId: string) {
candidatesOpen.value = false
emit('regenerate', imageId)
}
/** 后端确认母版成功后立即收起管理弹窗,不等待列表刷新。 */
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>
<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
:key="displayImage.id"
:image="displayImage"
:subject-name="subjectName"
:module="module"
:identity-locked="identityLocked"
:disabled="disabled"
:pending-operation="pendingOperation"
:reading-saved-review-id="readingSavedReviewId"
:validation-result="validationResult"
:retry-disabled-reason="retryDisabledReason"
:active="true"
:description="displayImage.isAnchor ? anchorDescription : undefined"
@anchor="emit('anchor', $event)"
@validate="emit('validate', $event)"
@read-review="emit('readReview', $event)"
@regenerate="regenerate"
/>
</div>
<!-- 以下是主页面图片本次审核证据模块 -->
<ImageValidationPanel
v-if="validationResult && images.some(image => image.id === validationResult?.imageId) && !candidatesOpen"
class="mt-5"
:result="validationResult"
:module="module"
/>
<!-- 以下是与镜头生产一致的底部图片操作模块 -->
<div class="identity-gallery-actions">
<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} 的其他候选与辅助参考图;已在主页面展示的图片不重复列出。辅助参考图不能设为母版。`"
:width="candidatesWidth"
:busy="!!pendingOperation"
>
<div class="identity-candidate-grid">
<IdentityImageCard
v-for="image in managedCandidates"
:key="image.id"
:image="image"
:subject-name="subjectName"
:module="module"
:identity-locked="identityLocked"
:disabled="disabled"
:pending-operation="pendingOperation"
:reading-saved-review-id="readingSavedReviewId"
:validation-result="validationResult"
:retry-disabled-reason="retryDisabledReason"
:active="candidatesOpen"
@anchor="emit('anchor', $event)"
@validate="emit('validate', $event)"
@read-review="emit('readReview', $event)"
@regenerate="regenerate"
/>
</div>
<!-- 以下是候选管理中的审核证据模块 -->
<ImageValidationPanel
v-if="validationResult && managedCandidates.some(image => image.id === validationResult?.imageId)"
class="mt-5"
:result="validationResult"
:module="module"
/>
</AppDialog>
</section>
</template>
<style>
@reference "../../../styles/styles.css";
.identity-gallery-toolbar {
@apply flex min-w-0 flex-wrap items-center justify-between gap-3;
}
/* 桌面母版与镜头首帧沿用 260px 卡片,画面宽高一致。 */
.identity-anchor-grid {
@apply grid w-full max-w-[260px] grid-cols-1;
}
/* 母版卡片采用 subtle 底色,与融合工作区的 surface 底色区分。 */
.identity-anchor-grid .identity-image-card {
@apply bg-(--app-subtle);
}
.identity-gallery-actions {
@apply mt-4 flex min-w-0 flex-wrap items-center gap-3;
}
/* 候选固定列宽并统一各行高度,弹窗正文负责纵向滚动。 */
.identity-candidate-grid {
@apply grid w-full max-w-[1348px] items-stretch gap-3;
grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 260px));
grid-auto-rows: 1fr;
justify-content: space-between;
}
/* 图片保持正方形,信息区填满剩余高度,操作固定在卡片底部。 */
.identity-candidate-grid > .identity-image-card {
@apply flex flex-col;
}
.identity-candidate-grid .identity-image-card-body {
@apply flex flex-1 flex-col;
}
.identity-candidate-grid .identity-image-actions {
margin-top: auto;
padding-top: 8px;
}
@media (max-width: 760px) {
.identity-anchor-grid {
@apply max-w-none;
}
.identity-candidate-grid {
@apply max-w-none grid-cols-[minmax(0,_1fr)];
}
.identity-gallery-actions > .n-button {
@apply w-full;
}
}
</style>