feat(short-drama-agent-front): 优化身份管理与镜头素材布局

This commit is contained in:
GJ committed 2026-10-11 21:41:56 +08:00
1 parent dd0bd79a35
commit 3d2c198e52
14 files changed
+1060 -629

No files matched your search

@@ -0,0 +1,308 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { NButton, NPopover, NScrollbar, NTag } from 'naive-ui'
import { AppDialog, AssetImage, AssetOpenLink, StatusBadge } from '../../../components/ui'
import { formatDate } from '../../../lib/format'
import ConfirmAction from '../../workflows/ConfirmAction.vue'
import { canBeAnchor, identityViewLabels } from '../model'
import type { IdentityImage, IdentityImageOperation } from '../types'
/** 母版与候选共用图片卡片,操作始终绑定卡片的正式图片编号。 */
const props = defineProps<{
/** 此卡片对应的正式图片。 */
image: IdentityImage
/** 当前主体名称。 */
subjectName: string
/** 主体类型,决定确认选角或切换普通母版。 */
module: string
/** 身份是否已经锁定。 */
identityLocked: boolean
/** 当前项目或主体是否禁止写入。 */
disabled: boolean
/** 当前固定目标的图片操作。 */
pendingOperation?: IdentityImageOperation | null
/** 重新生成暂不可用的具体恢复步骤。 */
retryDisabledReason?: string
/** 当前母版的使用说明,候选卡片不展示。 */
description?: string
/** 候选管理是否可见,关闭管理弹窗时同步收起错误浮层。 */
active?: boolean
}>()
/** 卡片只请求父页面执行操作,不直接调用模型或修改母版。 */
const emit = defineEmits<{
/** 确认指定图片作为母版。 */
anchor: [imageId: string]
/** 校验指定图片。 */
validate: [imageId: string]
/** 打开失败图片对应的生成参数弹窗。 */
regenerate: [imageId: string]
}>()
/** 当前卡片的母版确认弹窗开关。 */
const confirming = ref(false)
/** 失败详情按需展示在浮层中,避免长错误文本撑高候选卡片。 */
const failureDetailsOpen = ref(false)
/** 角色使用选角确认事务,场景和道具使用稳定母版事务。 */
const character = computed(() => props.module === 'character')
/** 只为当前图片的确认请求显示加载。 */
const confirmLoading = computed(
() => props.pendingOperation?.imageId === props.image.id && props.pendingOperation.kind === 'confirm'
)
/** 只为当前图片的校验请求显示加载。 */
const validateLoading = computed(
() => props.pendingOperation?.imageId === props.image.id && props.pendingOperation.kind === 'validate'
)
/** 只有完成的 primary 可以确认,已锁定的当前母版不提供重复确认。 */
const canSelect = computed(
() =>
!props.disabled &&
!props.pendingOperation &&
canBeAnchor(props.image) &&
(!props.image.isAnchor || (character.value && !props.identityLocked))
)
/** 卡片标识区分身份母版、母版候选和辅助视角,不重复强调当前状态。 */
const imageLabel = computed(() =>
props.image.isAnchor
? '身份母版'
: props.image.viewType === 'primary'
? '母版候选'
: identityViewLabels[props.image.viewType]
)
/** 后台重启表示原请求结果未知,不能误导用户直接调整模型参数。 */
const failureNotice = computed(() => {
if (props.image.status !== 'failed') return null
const error = props.image.error?.trim() ?? ''
if (error.includes('服务重启时图片 Provider 请求状态不可恢复'))
return {
title: '图片生成中断,结果未确认',
description:
'后台服务重启,无法确认图片服务是否已完成原请求。系统未自动重试,以免重复生成和计费。请先到图片服务平台核对原任务结果,再决定是否重新生成。'
}
return { title: '本次图片生成失败', description: error || '图片服务未返回具体原因,请核对服务状态与生成参数。' }
})
/** 失败记录按原图片类型提供明确的重新生成入口。 */
const regenerateLabel = computed(() =>
props.image.viewType !== 'primary'
? '重新生成辅助参考图'
: character.value
? '重新生成角色候选图'
: '重新生成母版候选'
)
/** 已有请求、草稿或缺少前置配置时禁止重复生成。 */
const regenerateDisabled = computed(() => props.disabled || !!props.pendingOperation || !!props.retryDisabledReason)
/** 卡片被复用为其它图片或已确认为母版时,关闭旧目标的确认弹窗。 */
watch([() => props.image.id, () => props.image.isAnchor, () => props.identityLocked], () => {
confirming.value = false
})
/** 切换图片、任务状态变化或关闭候选弹窗时清理旧记录的错误浮层。 */
watch([() => props.image.id, () => props.image.status, () => props.active], () => {
failureDetailsOpen.value = false
})
/** 母版影响已由用户明确确认后,提交此卡片固定的图片编号。 */
function chooseAnchor() {
if (!canSelect.value || !confirming.value) return
emit('anchor', props.image.id)
confirming.value = false
}
/** 重新生成仅打开参数设置,失败记录自身不会被覆盖。 */
function regenerate() {
if (regenerateDisabled.value || props.image.status !== 'failed') return
failureDetailsOpen.value = false
emit('regenerate', props.image.id)
}
</script>
<template>
<article class="identity-image-card" :aria-label="`身份图片 ${image.id}`">
<!-- 以下是方形身份图片与原图预览入口模块 -->
<div class="relative">
<AssetImage
:src="image.status === 'completed' ? image.imageUrl : null"
:alt="`${subjectName} · ${imageLabel}`"
object-fit="cover"
preview
:empty-text="
{ pending: '排队中', generating: '生成中', failed: '生成失败', completed: '图片缺失' }[image.status]
"
/>
<AssetOpenLink :src="image.status === 'completed' ? image.imageUrl : null" label="打开身份图片" />
</div>
<!-- 以下是图片标识、尺寸和时间模块,母版锁定状态与身份标识同一行显示 -->
<div class="identity-image-card-body">
<div class="flex flex-wrap items-center gap-2">
<!-- 母版已是完成图,仅保留身份标识;候选继续显示生成状态。 -->
<StatusBadge
v-if="!image.isAnchor && !failureNotice"
:status="image.status"
:label="image.status === 'pending' ? '排队中' : undefined"
/>
<!-- 以下是失败标签的详情浮层模块,点击或键盘激活标签即可查看原因。 -->
<NPopover
v-if="failureNotice"
v-model:show="failureDetailsOpen"
trigger="click"
placement="top-start"
:to="true"
:flip="true"
:disabled="active === false"
class="identity-failure-popover"
@keydown.esc.stop="failureDetailsOpen = false"
>
<template #trigger>
<button
type="button"
class="identity-failure-trigger"
aria-label="生成失败,查看失败原因"
:aria-expanded="failureDetailsOpen"
:disabled="active === false"
@keydown.esc.stop="failureDetailsOpen = false"
>
<StatusBadge :status="image.status" />
</button>
</template>
<!-- 浮层挂到视口层避免裁剪,详情超出可用高度时由 NScrollbar 滚动。 -->
<NScrollbar class="identity-failure-scroll">
<div class="identity-image-failure text-xs leading-6">
<p class="font-semibold text-danger">{{ failureNotice.title }}</p>
<p class="mt-2">{{ failureNotice.description }}</p>
<p v-if="retryDisabledReason" class="mt-2 text-muted">{{ retryDisabledReason }}</p>
</div>
</NScrollbar>
</NPopover>
<NTag size="small" :bordered="false">{{ imageLabel }}</NTag>
<!-- 以下是母版身份锁定状态模块,紧邻图片下方的身份母版标签。 -->
<NTag
v-if="image.isAnchor"
size="small"
:bordered="false"
:type="identityLocked ? 'success' : 'default'"
>
{{ identityLocked ? '已确认并锁定' : '待锁定' }}
</NTag>
</div>
<!-- 以下是同一行的尺寸与时间模块,尺寸缺失时仍保持时间靠右对齐。 -->
<div class="identity-image-meta">
<span v-if="image.width && image.height">{{ image.width }} × {{ image.height }}</span>
<time :datetime="image.createdAt">{{ formatDate(image.createdAt) }}</time>
</div>
<p v-if="description" class="text-xs leading-6 text-muted">{{ description }}</p>
<p v-if="image.viewType !== 'primary'" class="text-xs leading-6 text-muted">
辅助参考图继承当前母版,不能直接设为身份母版。
</p>
<!-- 以下是失败记录的重试模块,具体原因通过上方失败标签查看。 -->
<div v-if="failureNotice" class="identity-image-actions" role="group" aria-label="失败图片恢复操作">
<NButton size="small" :disabled="regenerateDisabled" type="primary" @click="regenerate">{{
regenerateLabel
}}</NButton>
</div>
<!-- 以下是固定图片目标的母版确认与校验模块,结果沿用 NMessage -->
<div
v-if="image.status === 'completed' && image.imageUrl"
class="identity-image-actions"
role="group"
aria-label="当前身份图片操作"
>
<NButton
v-if="image.viewType === 'primary' && (!image.isAnchor || (character && !identityLocked))"
:disabled="!canSelect"
:loading="confirmLoading"
:aria-label="character ? '确认选角并锁定' : '设为身份母版'"
:aria-busy="confirmLoading"
type="primary"
size="small"
@click="confirming = true"
>
{{ character ? '确认选角并锁定' : '设为身份母版' }}
</NButton>
<ConfirmAction
:key="image.id"
label="校验此身份图片"
:description="`将校验图片 ${image.id},会调用视觉模型并可能产生费用,不会切换母版。`"
:disabled="disabled || !!pendingOperation"
:loading="validateLoading"
acknowledgement
@confirm="emit('validate', image.id)"
/>
</div>
</div>
<!-- 以下是明确母版影响的人工确认弹窗模块 -->
<AppDialog
v-model:open="confirming"
:title="character ? '确认选角并锁定' : '确认切换身份母版'"
:description="
character
? `确认将这张图片作为 ${subjectName} 的角色母版并锁定身份?后续图片生成会使用这张母版。`
: `确认切换 ${subjectName} 的身份母版?旧母版会保留在候选记录中,后续形态图片生成会使用新母版。`
"
>
<template #footer>
<NButton @click="confirming = false">取消</NButton>
<NButton :disabled="!canSelect" type="primary" @click="chooseAnchor">{{
character ? '确认演员选择' : '确认切换身份母版'
}}</NButton>
</template>
</AppDialog>
</article>
</template>
<style>
@reference "../../../styles/styles.css";
/* 候选卡片与弹窗底色区分,方形画面保留顶部裁切与完整原图预览。 */
.identity-image-card {
@apply min-w-0 max-w-full overflow-hidden bg-(--app-subtle);
}
.identity-image-card .asset-image {
@apply aspect-square;
}
.identity-image-card-body {
@apply p-3 grid min-w-0 gap-2 wrap-anywhere;
}
.identity-image-meta {
@apply flex min-h-4 min-w-0 items-center justify-between gap-2 text-[10px] text-muted;
}
.identity-image-meta > time {
@apply ml-auto shrink-0 whitespace-nowrap;
}
.identity-failure-trigger {
@apply inline-flex items-center border-0 bg-transparent p-0;
}
.identity-image-actions {
@apply mt-2 grid min-w-0 grid-flow-col auto-cols-fr items-stretch gap-2;
}
.identity-image-actions > .confirm-action {
@apply min-w-0 max-w-full;
}
.identity-image-card .identity-image-actions > .n-button,
.identity-image-card .identity-image-actions > .confirm-action {
@apply w-full;
}
.identity-image-card .identity-image-actions > .confirm-action > .n-button {
@apply w-full;
height: 100%;
}
/* 操作最多两项并等分一行,窄屏长文案自然换行,单项占满整行。 */
.identity-image-card .identity-image-actions .n-button {
height: auto;
min-height: 28px;
font-size: 12px;
padding-inline: 8px;
padding-block: 4px;
}
.identity-image-card .identity-image-actions .n-button__content {
@apply whitespace-normal text-center leading-5;
}
/* 错误浮层独立于卡片布局,保留浮层箭头,滚动交由 NScrollbar。 */
.identity-failure-popover.n-popover {
box-sizing: border-box;
width: min(360px, calc(100vw - 48px));
}
/* 为浮层内边距预留空间,短内容保持自然高度,长内容不撑出视口。 */
.identity-failure-scroll.n-scrollbar {
max-height: min(388px, calc(100dvh - 80px));
}
.identity-failure-scroll > .n-scrollbar-container {
overscroll-behavior: contain;
}
.identity-image-failure {
@apply whitespace-pre-wrap wrap-anywhere;
}
</style>