223 lines
11 KiB
Vue
223 lines
11 KiB
Vue
<script setup lang="ts">
|
||
import AppForm from '../../../components/ui/AppForm.vue'
|
||
import { NAlert, NButton, NCheckbox, NCollapse, NCollapseItem, NTag } from 'naive-ui'
|
||
import { computed, ref, watch } from 'vue'
|
||
import { generationConfigApi } from '../../generation-config/api'
|
||
import type {
|
||
CreativeProfileAspectRatio,
|
||
GenerationModelCatalog,
|
||
GenerationOptions
|
||
} from '../../generation-config/types'
|
||
import GenerationModelControls from '../../generation-config/components/GenerationModelControls.vue'
|
||
import { AppDialog, FieldLabel } from '../../../components/ui'
|
||
import { errorMessage } from '../../../lib/http'
|
||
import { productionApi } from '../api'
|
||
import type { GenerateKeyframeInput, KeyframeGenerationPreview } from '../types'
|
||
|
||
/** 单镜头首帧表单;所有新图先生成候选,通过质量检查后再人工晋升。 */
|
||
const props = defineProps<{
|
||
shotId: string
|
||
shotTitle: string
|
||
projectId: string
|
||
disabled: boolean
|
||
replacePrimary?: boolean
|
||
}>()
|
||
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 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)
|
||
|
||
/** 切换镜头或重新打开时清空费用确认;新图一律先作为候选。 */
|
||
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 = ''
|
||
try {
|
||
const result = await productionApi.previewKeyframe(props.shotId, {
|
||
provider: imageProvider.value || undefined,
|
||
generationOptions: imageGenerationOptions.value
|
||
})
|
||
if (!result || result.shotId !== props.shotId) throw new Error('预览结果与当前镜头不匹配。')
|
||
preview.value = result
|
||
} catch (cause) {
|
||
preview.value = null
|
||
previewError.value = errorMessage(cause)
|
||
} finally {
|
||
previewPending.value = false
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<AppDialog
|
||
v-model:open="open"
|
||
:title="`${replacePrimary ? '生成替代候选' : '生成首帧候选'} · ${shotTitle}`"
|
||
description="新图先作为候选;完成质量检查并通过后,才能设为主首帧。"
|
||
>
|
||
<AppForm
|
||
ref="formRef"
|
||
:model="imageGenerationOptions"
|
||
:disabled="disabled"
|
||
:reset-key="`${open}:${shotId}`"
|
||
validate-on-change
|
||
@submit="submit"
|
||
>
|
||
<NAlert v-if="replacePrimary" type="info" :show-icon="false" class="mt-5 text-xs">
|
||
当前主首帧使用的主体参考资产已经变化。新图成功后应设为主首帧,旧图会继续保留为历史候选。
|
||
</NAlert>
|
||
<section v-if="generationCatalog" class="dialog-section mt-5" aria-label="本次首帧生成模型设置">
|
||
<p class="text-xs font-medium">
|
||
<FieldLabel
|
||
label="本次生成设置"
|
||
description="仅覆盖当前镜头本次首帧生成,不修改项目默认图片模型。"
|
||
/>
|
||
</p>
|
||
<GenerationModelControls
|
||
class="mt-4"
|
||
type="image"
|
||
:catalog="generationCatalog"
|
||
:provider="imageProvider"
|
||
:options="imageGenerationOptions"
|
||
:aspect-ratio="projectAspectRatio"
|
||
:disabled="disabled"
|
||
@update:provider="imageProvider = $event"
|
||
@update:options="imageGenerationOptions = $event"
|
||
/>
|
||
</section>
|
||
<NAlert v-else-if="generationCatalogError" type="warning" :show-icon="false" class="mt-5 text-xs">
|
||
生成模型目录读取失败:{{ generationCatalogError }}
|
||
</NAlert>
|
||
<div class="mt-5 flex flex-wrap items-center gap-3">
|
||
<NButton :loading="previewPending" @click="loadPreview">预览实际生成输入</NButton>
|
||
<span class="text-xs text-muted">只读取参考图规划与最终 Prompt,不调用图片模型。</span>
|
||
</div>
|
||
<NAlert v-if="previewError" type="error" :show-icon="false" class="mt-3">{{ previewError }}</NAlert>
|
||
<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>
|
||
<!-- 规格审计仅提示导演约束风险,不阻止首帧生成。 -->
|
||
<section class="mt-3 bg-muted/10 p-3" aria-label="生成规格一致性检查">
|
||
<div class="flex flex-wrap items-center gap-2">
|
||
<strong>生成规格检查</strong>
|
||
<NTag
|
||
size="small"
|
||
:bordered="false"
|
||
:type="preview.specConsistencySummary?.hasWarnings ? 'warning' : 'success'"
|
||
>
|
||
{{ preview.specConsistencySummary?.hasWarnings
|
||
? `发现 ${preview.specConsistencySummary.warningCount} 项预警`
|
||
: '检查通过' }}
|
||
</NTag>
|
||
<span class="text-muted">仅提示,不阻止生成</span>
|
||
</div>
|
||
<NCollapse v-if="preview.specConsistencyIssues?.length" class="mt-2">
|
||
<NCollapseItem name="issues" title="查看规格预警与处理建议">
|
||
<div
|
||
v-for="(issue, index) in preview.specConsistencyIssues"
|
||
:key="`${issue.code}:${issue.subjectRef ?? index}`"
|
||
class="mt-3 bg-muted/10 p-3"
|
||
>
|
||
<p class="font-medium">{{ issue.message }}</p>
|
||
<p v-if="issue.subjectRef" class="mt-1 text-muted">主体:{{ issue.subjectRef }}</p>
|
||
<p class="mt-1 text-muted">涉及字段:{{ issue.fieldPaths.join('、') }}</p>
|
||
<p class="mt-1">建议:{{ issue.suggestion }}</p>
|
||
</div>
|
||
</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="最终 Provider Prompt">
|
||
<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"
|
||
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
|
||
>
|
||
</template>
|
||
</AppDialog>
|
||
</template>
|