Files
short-drama-agent-front/src/features/production/components/QualityDialog.vue
T

446 lines
21 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 AppForm from '../../../components/ui/AppForm.vue'
import { NFormItem } from 'naive-ui'
import { integerRule, sizeRules } from '../../../lib/form-rules'
import { computed, ref, watch } from 'vue'
import {
NAlert,
NButton,
NCheckbox,
NCollapse,
NCollapseItem,
NInput,
NInputNumber,
NRadioButton,
NRadioGroup
} from 'naive-ui'
import { AppDialog } from '../../../components/ui'
import { allowedTextLines, validQualityInput } from '../quality'
import type { QualityAction, QualityInput, QualityTarget } from '../quality.types'
import { useQuality } from '../useQuality'
import QualityResult from './QualityResult.vue'
import KeyframeValidationHistory from './KeyframeValidationHistory.vue'
import WorkflowExecutionPanel from '../../workflows/WorkflowExecutionPanel.vue'
import GenerationModelControls from '../../generation-config/components/GenerationModelControls.vue'
import { generationConfigApi } from '../../generation-config/api'
import type { GenerationOptions } from '../../generation-config/types'
import { useQuery } from '../../../composables/useQuery'
import ModelCapabilities from './ModelCapabilities.vue'
/** 单素材与当前集质量生成共用一个按需打开的面板,默认小批量且不自动调用模型。 */
const props = defineProps<{
/** 当前项目 */
projectId: string
/** 固定质量目标 */
target: QualityTarget | null
/** 上游状态阻断 */
disabled: boolean
}>()
/** 质量面板的open状态,随目标更新。 */
const open = defineModel<boolean>('open', { default: false })
/** 通知外部刷新、定位与后台任务开始。 */
const emit = defineEmits<{ changed: []; locate: [shotId: string]; started: [executionId: string] }>()
const { key, session, operation, execution, blocked, run } = useQuality(
props,
() => open.value,
() => emit('changed'),
id => emit('started', id)
)
/** 模型目录只读查询,随当前项目和弹窗状态取消过期请求。 */
const modelKey = computed(() =>
open.value && props.target?.kind === 'batch' && props.projectId ? props.projectId : ''
)
/** 模型与项目画幅读取,不自动写入配置。 */
const modelQuery = useQuery(modelKey, async (projectId, signal) =>
projectId
? {
catalog: await generationConfigApi.catalog(signal),
profile: await generationConfigApi.profile(projectId, signal)
}
: null
)
/** 本次明确选择的图片供应方。 */
const provider = ref('')
/** 本次生成与修复共用参数。 */
const generationOptions = ref<GenerationOptions>({})
/** 后台任务期间表单也保持锁定。 */
const pending = computed(() => operation.value.pending || execution.active.value)
/** 当前目标的单镜头范围。 */
const singleShot = computed(() => props.target?.kind === 'batch' && !!props.target.shotId)
/** 质量面板的formRef状态,随目标更新。 */
const formRef = ref<InstanceType<typeof AppForm> | null>(null)
/** 质量面板的action状态,随目标更新。 */
const action = ref<QualityAction>('validate')
/** 质量面板的attempts状态,随目标更新。 */
const attempts = ref<number | null>(1)
/** 质量面板的concurrency状态,随目标更新。 */
const concurrency = ref<number | null>(1)
/** 质量面板的limit状态,随目标更新。 */
const limit = ref<number | null>(1)
/** 质量面板的force状态,随目标更新。 */
const force = ref(false)
/** 质量面板的width状态,随目标更新。 */
const width = ref<number | null>(null)
/** 质量面板的height状态,随目标更新。 */
const height = ref<number | null>(null)
/** 质量面板的texts状态,随目标更新。 */
const texts = ref('')
/** 质量面板的acknowledged状态,随目标更新。 */
const acknowledged = ref(false)
/** 质量面板的videoRepair状态,随目标更新。 */
const videoRepair = computed(() => props.target?.kind === 'video' && action.value === 'repair')
/** 质量面板的input状态,随目标更新。 */
const input = computed<QualityInput>(() => ({
concurrency: action.value === 'batch' ? (concurrency.value ?? 0) : 1,
limit: action.value === 'batch' && !singleShot.value ? (limit.value ?? 0) : 1,
...(props.target?.kind === 'batch' && props.target.shotId ? { shotId: props.target.shotId } : {}),
...(action.value === 'batch' && provider.value
? { provider: provider.value, generationOptions: { ...generationOptions.value } }
: {}),
maxRepairAttempts: action.value === 'validate' ? 0 : (attempts.value ?? -1),
force: force.value,
episodeNo: props.target?.kind === 'batch' ? props.target.episodeNo : 1,
allowedTexts: allowedTextLines(texts.value),
...(action.value === 'validate' || width.value === null ? {} : { width: width.value }),
...(action.value === 'validate' || height.value === null ? {} : { height: height.value })
}))
/** 批量生图必须读到真实配置并显式选定启用模型,不能回退到未确认的全局默认。 */
const modelReady = computed(
() =>
props.target?.kind !== 'batch' ||
(!modelQuery.loading.value &&
!modelQuery.error.value &&
!!modelQuery.data.value?.profile &&
modelQuery.data.value.catalog.images.some(model => model.provider === provider.value && model.enabled))
)
/** 参数及模型均有效时才允许进入费用确认后的提交。 */
const valid = computed(
() =>
modelReady.value && validQualityInput(input.value) && (!videoRepair.value || input.value.maxRepairAttempts > 0)
)
/** 质量面板的generating状态,随目标更新。 */
const generating = computed(() => action.value !== 'validate')
/** 质量面板的label状态,随目标更新。 */
const label = computed(() =>
action.value === 'batch'
? '开始质量生成'
: action.value === 'repair'
? videoRepair.value
? '创建视频修复候选'
: '校验并修复'
: '开始视觉校验'
)
/** 质量面板的maxImages状态,随目标更新。 */
const maxImages = computed(() =>
action.value === 'batch'
? input.value.limit * (1 + input.value.maxRepairAttempts)
: action.value === 'repair'
? input.value.maxRepairAttempts
: 0
)
/** 质量面板的maxValidations状态,随目标更新。 */
const maxValidations = computed(() =>
action.value === 'batch' ? maxImages.value : action.value === 'repair' ? input.value.maxRepairAttempts + 1 : 1
)
/** 质量面板的saved状态,随目标更新。 */
const saved = computed(() => (props.target?.kind === 'video' ? (session.value.videoValidation ?? null) : null))
/** 质量面板的repairAvailable状态,随目标更新。 */
const repairAvailable = computed(
() =>
!videoRepair.value ||
(session.value.receipt?.kind === 'video'
? session.value.receipt.result.passed === false
: saved.value?.passed === false)
)
/** 目标和费用范围变化均撤销确认;关闭不取消已经发送到后端的长请求。 */
watch(
[key, open],
() => {
action.value = props.target?.kind === 'batch' ? 'batch' : 'validate'
attempts.value = props.target?.kind === 'video' ? 2 : 1
concurrency.value = 1
limit.value = 1
force.value = false
width.value = null
height.value = null
texts.value = ''
provider.value = ''
generationOptions.value = {}
acknowledged.value = false
},
{ immediate: true }
)
/** 参数变化撤销付费确认。 */
watch([input, action], () => {
acknowledged.value = false
})
/** 模型目录加载后使用项目已保存的供应方与参数,切镜头重置单次覆盖。 */
watch(
[() => modelQuery.data.value, key],
([data]) => {
if (!data?.profile || props.target?.kind !== 'batch') return
const selected = data.catalog.images.find(item => item.provider === data.profile!.imageProvider && item.enabled)
if (!selected) return
provider.value = selected.provider
generationOptions.value = { ...selected.defaults, ...data.profile.imageOptions }
},
{ flush: 'post' }
)
/** 付费入口保留明确确认,不因菜单选择或查看历史自动提交。 */
async function submit() {
if (!acknowledged.value || !valid.value || blocked.value || !repairAvailable.value) return
acknowledged.value = false
await run(action.value, input.value)
}
/** 质量面板的formModel状态,随目标更新。 */
const formModel = computed(() => ({
attempts: attempts.value,
concurrency: concurrency.value,
limit: limit.value,
width: width.value,
height: height.value,
texts: texts.value
}))
/** 质量面板的rules状态,随目标更新。 */
const rules = computed(() => ({
attempts: integerRule('修复次数', videoRepair.value ? 1 : 0),
concurrency: integerRule('批量并发'),
limit: integerRule('本批镜头上限'),
...sizeRules(() => formModel.value)
}))
/** 更多参数折叠状态。 */
const optionsExpanded = ref<string[]>(['options'])
</script>
<template>
<!-- 以下是质量操作与显式费用确认模块 -->
<AppDialog
v-model:open="open"
:title="`质量检查 · ${target?.title ?? ''}`"
description="查看质量结果,或按需发起新的视觉检查。"
wide
>
<AppForm
ref="formRef"
:model="formModel"
:rules="rules"
:disabled="pending"
:reset-key="`${open}:${key}:${action}`"
validate-on-change
@invalid="optionsExpanded = ['options']"
@submit="submit"
>
<NRadioGroup
v-if="target && target.kind !== 'batch'"
v-model:value="action"
:disabled="pending"
class="mt-4"
aria-label="素材质量操作"
>
<NRadioButton value="validate">视觉校验</NRadioButton
><NRadioButton value="repair">{{
target?.kind === 'video' ? '生成修复候选' : '校验并修复'
}}</NRadioButton>
</NRadioGroup>
<NAlert v-if="target?.kind === 'video'" type="info" :show-icon="false" class="mt-4"
>视频校验会按镜头启用抽样帧、运动及道具专项检查,不含音频和口型。普通候选只校验;修复候选复检通过后会自动设为主视频。</NAlert
>
<div v-if="generating" class="quality-fields mt-4">
<NFormItem path="attempts" :label="videoRepair ? '修复链次数上限' : '每镜最多修复'"
><NInputNumber
v-model:value="attempts"
:disabled="pending"
:min="videoRepair ? 1 : 0"
:step="1"
:input-props="{ 'aria-label': '每镜最多修复次数' }"
/></NFormItem>
<NFormItem v-if="target?.kind === 'batch' && !singleShot" path="limit" label="本批镜头上限"
><NInputNumber
v-model:value="limit"
:disabled="pending"
:min="1"
:step="1"
:input-props="{ 'aria-label': '质量生成镜头上限' }"
/></NFormItem>
</div>
<NCheckbox v-if="target?.kind === 'batch'" v-model:checked="force" :disabled="pending" class="mt-4"
>重做当前范围已有有效首帧(通过后替换主图)</NCheckbox
>
<p v-if="target?.kind === 'batch'" class="mt-3 text-xs text-muted">
仅第 {{ target.episodeNo }} 集{{ singleShot ? `,指定镜头 ${target.shotId}` : '' }},最多
{{ singleShot ? 1 : (limit ?? '—') }} 镜;非重做模式处理符合条件的过期和缺失首帧。
</p>
<p v-if="videoRepair" class="mt-3 text-xs text-muted">
本次仅创建一个修复视频,不自动等待或复检。完成后请打开新候选的质量检查;修复约束沿用上次失败校验,不使用额外参数。
</p>
<NAlert v-if="!repairAvailable" type="warning" :show-icon="false" class="mt-3"
>请先执行视觉校验,只有未通过的视频可以创建修复候选。</NAlert
>
<NCollapse
v-if="!videoRepair"
v-model:expanded-names="optionsExpanded"
display-directive="show"
class="mt-4"
>
<NCollapseItem name="options" title="更多参数与模型限制">
<div class="quality-fields">
<NFormItem v-if="target?.kind === 'batch'" path="concurrency" label="批量并发"
><NInputNumber
v-model:value="concurrency"
:disabled="pending"
:min="1"
:step="1"
:input-props="{ 'aria-label': '质量生成并发' }"
/></NFormItem>
<NFormItem v-if="generating" path="width" label="宽度(可选)"
><NInputNumber
v-model:value="width"
:disabled="pending"
:min="1"
:input-props="{ 'aria-label': '质量生成宽度' }"
/></NFormItem>
<NFormItem v-if="generating" path="height" label="高度(可选)"
><NInputNumber
v-model:value="height"
:disabled="pending"
:min="1"
:input-props="{ 'aria-label': '质量生成高度' }"
/></NFormItem>
</div>
<NFormItem class="mt-4 block" path="texts" label="额外允许的画面文字(一行一项,可留空)"
><NInput
v-model:value="texts"
:disabled="pending"
type="textarea"
:autosize="{ minRows: 2, maxRows: 5 }"
:input-props="{ 'aria-label': '额外允许的画面文字' }"
/></NFormItem>
<!-- 以下是复用现有模型目录的单次质量生成配置模块 -->
<GenerationModelControls
v-if="target?.kind === 'batch' && modelQuery.data.value?.profile"
v-model:provider="provider"
v-model:options="generationOptions"
type="image"
:catalog="modelQuery.data.value.catalog"
:aspect-ratio="modelQuery.data.value.profile.aspectRatio"
:disabled="pending"
/>
<NAlert v-if="modelQuery.error.value" type="error" :show-icon="false">{{
modelQuery.error.value
}}</NAlert>
<NAlert
v-if="target?.kind === 'batch' && !modelReady && !modelQuery.error.value"
type="warning"
:show-icon="false"
>
{{
modelQuery.loading.value
? '正在读取项目模型配置,请稍候。'
: '请先保存有效的项目图片模型配置,再选择本次模型。'
}}
</NAlert>
<ModelCapabilities
:shot-id="target?.shotId"
:provider="target?.kind === 'batch' ? provider : undefined"
/>
</NCollapseItem>
</NCollapse>
<NAlert type="warning" :show-icon="false" class="mt-4">
<template v-if="videoRepair"
>本次最多提交 1
个视频生成任务,可能产生费用;生成完成不会切换主视频,需再次付费复检通过后才会晋升。</template
>
<template v-else-if="target?.kind === 'video'"
>本次提交一次视频校验请求,后端可能调用多个视觉模型并产生费用。</template
>
<template v-else-if="valid"
>本次最多调用 {{ maxImages }} 次生图、{{ maxValidations }} 次视觉校验,均可能产生费用。</template
>
<template v-if="generating && !videoRepair"
>修复/质量生成通过后可能替换主首帧;失败候选仍会保留,已有视频不会自动更新。</template
>
<template v-else-if="!generating">{{
target?.kind === 'video'
? '如果当前是修复候选,校验通过将替换当前主视频。'
: '仅校验,不修改主资产。'
}}</template>
</NAlert>
</AppForm>
<p v-if="pending" role="status" class="mt-3 text-xs text-muted">{{ operation.label }}进行中,请勿重复提交。</p>
<NAlert v-if="session.error" role="alert" type="error" :show-icon="false" class="mt-4">{{
session.error
}}</NAlert>
<!-- 以下是持久化任务进度与原目标最终回执模块 -->
<WorkflowExecutionPanel
v-if="execution.executionId.value"
title="首帧质量后台任务"
:execution="execution.query.data.value"
:loading="execution.query.loading.value"
:error="execution.query.error.value"
@refresh="execution.query.refresh"
@dismiss="execution.dismiss"
/>
<KeyframeValidationHistory
v-if="target?.kind === 'keyframe'"
:project-id="projectId"
:shot-id="target.shotId"
:keyframe-id="target.assetId"
/>
<QualityResult v-if="session.receipt" :receipt="session.receipt" @locate="emit('locate', $event)" />
<NCollapse v-else-if="saved" class="mt-4" :default-expanded-names="['saved']"
><NCollapseItem name="saved" :title="`本会话最近校验 · ${saved.passed ? '通过' : '未通过'}`"
><p>{{ saved.summary }}</p>
<p v-for="(issue, index) in saved.issues" :key="index" class="mt-2 text-danger">
{{ issue.description }}
</p>
<p class="mt-3 text-xs text-muted">此为历史抽样结论,不保证当前上游素材仍然一致。</p></NCollapseItem
></NCollapse
>
<p v-if="target?.kind !== 'batch'" class="mt-3 text-xs text-muted">
本会话回执可导出;首帧已有校验可在历史中只读查看,后台质量任务刷新后继续恢复。
</p>
<!-- 以下是底栏左侧费用确认与右侧操作按钮模块 -->
<template #footer>
<div class="quality-dialog-footer">
<NCheckbox v-model:checked="acknowledged" :disabled="pending" class="quality-dialog-acknowledgement"
>我已确认费用、处理范围,且同项目没有其他生成任务。</NCheckbox
>
<div class="quality-dialog-actions">
<NButton @click="open = false">关闭</NButton>
<NButton
type="primary"
:loading="pending"
:disabled="blocked || !acknowledged || !repairAvailable"
@click="formRef?.validate(submit)"
>{{ label }}</NButton
>
</div>
</div>
</template>
</AppDialog>
</template>
<style>
/* 本组件专属布局与 Naive 内部结构覆盖。 */
@reference "../../../styles/styles.css";
.quality-fields {
@apply grid grid-cols-[repeat(auto-fit,_minmax(min(100%,_180px),_1fr))] items-start gap-4;
}
/* 确认项固定在底栏左侧,操作按钮在右侧;窄屏允许分行。 */
.app-dialog .dialog-footer:has(> .quality-dialog-footer) {
@apply w-full;
}
.quality-dialog-footer {
@apply flex w-full flex-wrap items-center justify-between gap-4;
}
.quality-dialog-acknowledgement {
@apply min-w-0 flex-1;
flex-basis: 360px;
}
.quality-dialog-actions {
@apply ml-auto flex shrink-0 items-center gap-2;
}
</style>