feat(short-drama-agent-front): 完善视觉资产审核流程

This commit is contained in:
GJ committed 2026-11-04 14:09:21 +08:00
1 parent dc8bb17a23
commit b88ad8770f
45 files changed
+2258 -352

No files matched your search

@@ -1,6 +1,7 @@
<script setup lang="ts">
import { userFacingText } from '../../../lib/user-facing-text'
import FeedbackMessage from '../../../components/ui/FeedbackMessage.vue'
import ImageGenerationPreview from '../../subject-images/components/ImageGenerationPreview.vue'
import { useImageGenerationPreview, type ImageGenerationSubmission } from '../../subject-images/generation-preview'
import ContextNotice from '../../../components/ui/ContextNotice.vue'
@@ -17,7 +18,9 @@ import GenerationModelControls from '../../generation-config/components/Generati
import { AppDialog, FieldLabel } from '../../../components/ui'
import { errorMessage } from '../../../lib/http'
import { productionApi } from '../api'
import type { GenerateKeyframeInput, KeyframeGenerationPreview } from '../types'
import { directionLabel } from '../../storyboard/model'
import type { ShotDirection, ShotVisualState } from '../../storyboard/types'
import type { GenerateKeyframeInput } from '../types'
/** 单镜头首帧表单;所有新图先生成候选,通过质量检查后再人工晋升。 */
const props = defineProps<{
@@ -26,88 +29,89 @@ const props = defineProps<{
projectId: string
disabled: boolean
replacePrimary?: boolean
/** 当前镜头的正式摄影设计。 */
direction?: ShotDirection | null
/** 当前镜头的正式画面即时状态。 */
visualState?: ShotVisualState | null
/** 仅发送已经确认的当前快照。 */
submitGeneration: (input: GenerateKeyframeInput) => Promise<ImageGenerationSubmission>
}>()
const open = defineModel<boolean>('open', { default: false })
const emit = defineEmits<{ generate: [input: GenerateKeyframeInput] }>()
/** 生成参数表单,用于复用字段校验。 */
const formRef = ref<InstanceType<typeof AppForm> | null>(null)
const confirmed = ref(false)
const preview = ref<KeyframeGenerationPreview | null>(null)
const previewError = ref('')
const previewPending = ref(false)
/** 摄影枚举复用分镜页面的中文展示。 */
const directionSummary = computed(() =>
props.direction
? Object.entries(props.direction)
.filter(([, value]) => value)
.map(([field, value]) => directionLabel(value, field))
.join(' · ')
: ''
)
const generationCatalog = ref<GenerationModelCatalog | null>(null)
const generationCatalogError = ref('')
const imageProvider = ref('')
const imageGenerationOptions = ref<GenerationOptions>({})
const projectAspectRatio = ref<CreativeProfileAspectRatio>('9:16')
const canSubmit = computed(() => !props.disabled && confirmed.value)
/** 预览仅对应当前镜头、模型和参数;请求过期后不得覆盖新配置。 */
const previewRequestKey = computed(() =>
JSON.stringify([props.shotId, imageProvider.value, imageGenerationOptions.value])
)
watch(previewRequestKey, () => {
preview.value = null
previewError.value = ''
/** 预览和生成复用当前请求字段,生成时再附加版本及候选标记。 */
const generationInput = computed(() => ({
provider: imageProvider.value || undefined,
generationOptions: imageGenerationOptions.value
}))
/** 首帧与主体图片使用同一套预览确认与未知费用保护。 */
const {
preview,
acknowledged,
loading,
submitting,
error,
staleNotice,
recoveryNotice,
canSubmit,
loadPreview,
submit
} = useImageGenerationPreview({
open,
recoveryTarget: () => (props.shotId ? 'keyframe:' + props.shotId : ''),
target: () => JSON.stringify([props.shotId, props.direction, props.visualState]),
input: () => generationInput.value,
disabled: () => props.disabled || !imageProvider.value,
load: async (input, signal) => {
const shotId = props.shotId
const result = await productionApi.previewKeyframe(shotId, input, signal)
if (result?.shotId !== shotId) throw new Error('预览结果与当前镜头不匹配。')
return result
},
generate: input => props.submitGeneration({ ...input, setPrimary: false })
})
/** 切换镜头或重新打开时清空费用确认;新图一律先作为候选。 */
async function reset() {
confirmed.value = false
preview.value = null
previewError.value = ''
previewPending.value = false
generationCatalogError.value = ''
if (!open.value) return
try {
const [catalog, profile] = await Promise.all([
generationConfigApi.catalog(),
generationConfigApi.profile(props.projectId)
])
generationCatalog.value = catalog
projectAspectRatio.value = profile?.aspectRatio ?? '9:16'
imageProvider.value = profile?.imageProvider || catalog.defaults.imageProvider
const selected = catalog.images.find(item => item.provider === imageProvider.value)
imageGenerationOptions.value = { ...selected?.defaults, ...profile?.imageOptions }
} catch (cause) {
generationCatalogError.value = errorMessage(cause)
}
}
watch([() => props.shotId, open], reset, { immediate: true })
/** 发送当前模型与动态生成参数;图片尺寸统一由 generationOptions.size 管理。 */
function submit() {
if (!canSubmit.value) return
emit('generate', {
provider: imageProvider.value || undefined,
generationOptions: imageGenerationOptions.value,
setPrimary: false
})
open.value = false
reset()
}
/** 读取后端最终参考图选择与 Prompt,不创建首帧候选。 */
async function loadPreview() {
if (!props.shotId || previewPending.value) return
previewPending.value = true
previewError.value = ''
const requestKey = previewRequestKey.value
try {
const result = await productionApi.previewKeyframe(props.shotId, {
provider: imageProvider.value || undefined,
generationOptions: imageGenerationOptions.value
})
if (requestKey !== previewRequestKey.value || !open.value) return
if (!result || result.shotId !== props.shotId) throw new Error('预览结果与当前镜头不匹配。')
preview.value = result
} catch (cause) {
if (requestKey === previewRequestKey.value && open.value) {
preview.value = null
previewError.value = errorMessage(cause)
/** 切换镜头或重新打开时只读取模型配置,忽略已关闭弹窗的结果。 */
watch(
[() => props.shotId, () => props.projectId, open],
async ([, projectId, isOpen], _, onCleanup) => {
if (!isOpen) return
const controller = new AbortController()
onCleanup(() => controller.abort())
generationCatalog.value = null
generationCatalogError.value = ''
imageProvider.value = ''
try {
const [catalog, profile] = await Promise.all([
generationConfigApi.catalog(controller.signal),
generationConfigApi.profile(projectId, controller.signal)
])
if (controller.signal.aborted) return
generationCatalog.value = catalog
projectAspectRatio.value = profile?.aspectRatio ?? '9:16'
imageProvider.value = profile?.imageProvider || catalog.defaults.imageProvider
const selected = catalog.images.find(item => item.provider === imageProvider.value)
imageGenerationOptions.value = { ...selected?.defaults, ...profile?.imageOptions }
} catch (cause) {
if (!controller.signal.aborted) generationCatalogError.value = errorMessage(cause)
}
} finally {
previewPending.value = false
}
}
},
{ immediate: true }
)
</script>
<template>
@@ -115,11 +119,12 @@ async function loadPreview() {
v-model:open="open"
:title="`${replacePrimary ? '生成替代候选' : '生成首帧候选'} · ${shotTitle}`"
description="新图先作为候选;完成质量检查并通过后,才能设为主首帧。"
:busy="submitting"
>
<AppForm
ref="formRef"
:model="imageGenerationOptions"
:disabled="disabled"
:disabled="disabled || submitting"
:reset-key="`${open}:${shotId}`"
validate-on-change
@submit="submit"
@@ -141,7 +146,7 @@ async function loadPreview() {
:provider="imageProvider"
:options="imageGenerationOptions"
:aspect-ratio="projectAspectRatio"
:disabled="disabled"
:disabled="disabled || submitting"
@update:provider="imageProvider = $event"
@update:options="imageGenerationOptions = $event"
/>
@@ -149,22 +154,53 @@ async function loadPreview() {
<ContextNotice v-else-if="generationCatalogError" type="warning" :show-icon="false" class="mt-5 text-xs">
生成模型目录读取失败:{{ generationCatalogError }}
</ContextNotice>
<div class="mt-5 flex flex-wrap items-center gap-3">
<NButton :loading="previewPending" @click="loadPreview">预览实际生成输入</NButton>
<span class="text-xs text-muted">只读取参考图规划与最终画面描述,不调用图片模型。</span>
</div>
<FeedbackMessage v-if="previewError" :message="previewError" />
<div v-if="preview" class="panel mt-3 p-4 text-xs leading-6">
<div class="flex flex-wrap items-center gap-2">
<strong>{{ preview.provider }} / {{ preview.model }}</strong>
<NTag size="small" :bordered="false">
已选 {{ preview.referencePlan.selected.length }} /
{{ preview.referencePlan.totalCandidates }} 张
</NTag>
<NTag v-if="preview.referencePlan.omitted.length" size="small" type="warning" :bordered="false">
省略 {{ preview.referencePlan.omitted.length }} 张
</NTag>
</div>
<!-- 以下是正式摄影设计与画面状态 -->
<NCollapse v-if="direction || visualState" class="mt-5">
<NCollapseItem v-if="direction" name="direction" title="当前镜头设计">
<p class="text-xs leading-6">{{ directionSummary }}</p>
</NCollapseItem>
<NCollapseItem v-if="visualState" name="visual-state" title="当前画面状态">
<p class="text-xs leading-6">
{{
[
visualState.timeOfDay,
visualState.weather,
visualState.atmosphere,
visualState.environmentTransientState,
visualState.continuityNote
]
.filter(Boolean)
.join(' · ')
}}
</p>
<p v-for="subject in visualState.subjects" :key="subject.subjectId" class="mt-2 text-xs leading-6">
{{
[
subject.subjectRef,
subject.formName,
subject.position,
subject.pose,
subject.expression,
subject.gaze,
subject.transientState
]
.filter(Boolean)
.join(' · ')
}}
</p>
</NCollapseItem>
</NCollapse>
<!-- 以下是最终模型输入和正式参考资产 -->
<ImageGenerationPreview
class="mt-5"
:preview="preview"
:loading="loading"
:disabled="!imageProvider || submitting"
:error="error"
:stale-notice="staleNotice || recoveryNotice"
@load="loadPreview"
/>
<div v-if="preview" class="mt-3 text-xs leading-6">
<!-- 规格审计仅提示导演约束风险,不阻止首帧生成。 -->
<section
v-if="preview.specConsistencySummary"
@@ -201,43 +237,18 @@ async function loadPreview() {
</NCollapseItem>
</NCollapse>
</section>
<ul v-if="preview.referencePlan.selected.length" class="mt-3 space-y-1 text-muted">
<li v-for="item in preview.referencePlan.selected" :key="`${item.role}:${item.imageId}`">
{{ item.subjectRef }} · {{ item.role }} · <code>{{ item.imageId }}</code>
</li>
</ul>
<NCollapse class="mt-3" :default-expanded-names="['prompt']">
<NCollapseItem name="prompt" title="本次实际使用的画面描述">
<p class="mt-3 whitespace-pre-wrap">{{ preview.providerPrompt }}</p>
</NCollapseItem>
<NCollapseItem
v-if="preview.referencePlan.omitted.length"
name="omitted"
title="未进入模型的参考图"
>
<ul class="mt-3 space-y-1 text-muted">
<li v-for="item in preview.referencePlan.omitted" :key="`${item.role}:${item.imageId}`">
{{ item.subjectRef }} · {{ item.role }} · <code>{{ item.imageId }}</code>
</li>
</ul>
</NCollapseItem>
<NCollapseItem name="config" title="生成配置">
<pre class="mt-3 whitespace-pre-wrap">{{
JSON.stringify(preview.generationConfig, null, 2)
}}</pre>
</NCollapseItem>
</NCollapse>
</div>
<NCheckbox
id="confirm-keyframe-cost"
v-model:checked="confirmed"
v-model:checked="acknowledged"
:disabled="!preview || submitting || !!recoveryNotice"
class="mt-5 flex items-start gap-3 text-sm leading-6"
>我已确认调用图片模型可能产生费用,且当前没有相同镜头的生图任务。
>我已核对实际输入,并确认本次图片生成可能产生费用。
</NCheckbox>
</AppForm>
<template #footer>
<NButton @click="open = false">取消</NButton>
<NButton :disabled="disabled || !confirmed" @click="formRef?.validate(submit)" type="primary"
<NButton :disabled="submitting" @click="open = false">取消</NButton>
<NButton :disabled="!canSubmit" :loading="submitting" @click="formRef?.validate(submit)" type="primary"
>确认生成首帧</NButton
>
</template>