302 lines
14 KiB
Vue
302 lines
14 KiB
Vue
<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 ModelCapabilities from './ModelCapabilities.vue'
|
||
|
||
/** 单素材与当前集质量生成共用一个按需打开的面板,默认小批量且不自动调用模型。 */
|
||
const props = defineProps<{
|
||
projectId: string
|
||
target: QualityTarget | null
|
||
disabled: boolean
|
||
}>()
|
||
const open = defineModel<boolean>('open', { default: false })
|
||
const emit = defineEmits<{ changed: []; locate: [shotId: string] }>()
|
||
const { key, session, operation, blocked, run } = useQuality(
|
||
props,
|
||
() => open.value,
|
||
() => emit('changed')
|
||
)
|
||
const action = ref<QualityAction>('validate')
|
||
const attempts = ref<number | null>(1)
|
||
const concurrency = ref<number | null>(1)
|
||
const limit = ref<number | null>(1)
|
||
const force = ref(false)
|
||
const width = ref<number | null>(null)
|
||
const height = ref<number | null>(null)
|
||
const texts = ref('')
|
||
const acknowledged = ref(false)
|
||
const videoRepair = computed(() => props.target?.kind === 'video' && action.value === 'repair')
|
||
const input = computed<QualityInput>(() => ({
|
||
concurrency: action.value === 'batch' ? (concurrency.value ?? 0) : 1,
|
||
limit: action.value === 'batch' ? (limit.value ?? 0) : 1,
|
||
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 valid = computed(
|
||
() => validQualityInput(input.value) && (!videoRepair.value || input.value.maxRepairAttempts > 0)
|
||
)
|
||
const generating = computed(() => action.value !== 'validate')
|
||
const label = computed(() =>
|
||
action.value === 'batch'
|
||
? '开始质量生成'
|
||
: action.value === 'repair'
|
||
? videoRepair.value
|
||
? '创建视频修复候选'
|
||
: '校验并修复'
|
||
: '开始视觉校验'
|
||
)
|
||
const maxImages = computed(() =>
|
||
action.value === 'batch'
|
||
? input.value.limit * (1 + input.value.maxRepairAttempts)
|
||
: action.value === 'repair'
|
||
? input.value.maxRepairAttempts
|
||
: 0
|
||
)
|
||
const maxValidations = computed(() =>
|
||
action.value === 'batch' ? maxImages.value : action.value === 'repair' ? input.value.maxRepairAttempts + 1 : 1
|
||
)
|
||
const saved = computed(() => (props.target?.kind === 'video' ? (session.value.videoValidation ?? null) : null))
|
||
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 = ''
|
||
acknowledged.value = false
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
watch([input, action], () => {
|
||
acknowledged.value = false
|
||
})
|
||
/** 付费入口保留明确确认,不因菜单选择或查看历史自动提交。 */
|
||
async function submit() {
|
||
if (!acknowledged.value || !valid.value || blocked.value || !repairAvailable.value) return
|
||
acknowledged.value = false
|
||
await run(action.value, input.value)
|
||
}
|
||
const formModel = computed(() => ({
|
||
attempts: attempts.value,
|
||
concurrency: concurrency.value,
|
||
limit: limit.value,
|
||
width: width.value,
|
||
height: height.value,
|
||
texts: texts.value
|
||
}))
|
||
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
|
||
:model="formModel"
|
||
:rules="rules"
|
||
:disabled="operation.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="operation.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="operation.pending"
|
||
:min="videoRepair ? 1 : 0"
|
||
:step="1"
|
||
:input-props="{ 'aria-label': '每镜最多修复次数' }"
|
||
/></NFormItem>
|
||
<NFormItem v-if="target?.kind === 'batch'" path="limit" label="本批镜头上限"
|
||
><NInputNumber
|
||
v-model:value="limit"
|
||
:disabled="operation.pending"
|
||
:min="1"
|
||
:step="1"
|
||
:input-props="{ 'aria-label': '质量生成镜头上限' }"
|
||
/></NFormItem>
|
||
</div>
|
||
<NCheckbox
|
||
v-if="target?.kind === 'batch'"
|
||
v-model:checked="force"
|
||
:disabled="operation.pending"
|
||
class="mt-4"
|
||
>重做本集已有有效首帧(通过后替换主图)</NCheckbox
|
||
>
|
||
<p v-if="target?.kind === 'batch'" class="mt-3 text-xs text-muted">
|
||
仅第 {{ target.episodeNo }} 集,最多
|
||
{{ 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="operation.pending"
|
||
:min="1"
|
||
:step="1"
|
||
:input-props="{ 'aria-label': '质量生成并发' }"
|
||
/></NFormItem>
|
||
<NFormItem v-if="generating" path="width" label="宽度(可选)"
|
||
><NInputNumber
|
||
v-model:value="width"
|
||
:disabled="operation.pending"
|
||
:min="1"
|
||
:input-props="{ 'aria-label': '质量生成宽度' }"
|
||
/></NFormItem>
|
||
<NFormItem v-if="generating" path="height" label="高度(可选)"
|
||
><NInputNumber
|
||
v-model:value="height"
|
||
:disabled="operation.pending"
|
||
:min="1"
|
||
:input-props="{ 'aria-label': '质量生成高度' }"
|
||
/></NFormItem>
|
||
</div>
|
||
<NFormItem class="mt-4 block" path="texts" label="额外允许的画面文字(一行一项,可留空)"
|
||
><NInput
|
||
v-model:value="texts"
|
||
:disabled="operation.pending"
|
||
type="textarea"
|
||
:autosize="{ minRows: 2, maxRows: 5 }"
|
||
:input-props="{ 'aria-label': '额外允许的画面文字' }"
|
||
/></NFormItem>
|
||
<ModelCapabilities :shot-id="target && target.kind !== 'batch' ? target.shotId : 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>
|
||
<NCheckbox v-model:checked="acknowledged" :disabled="operation.pending" class="mt-4"
|
||
>我已确认费用、处理范围,且同项目没有其他生成任务。</NCheckbox
|
||
>
|
||
<div class="dialog-footer">
|
||
<NButton @click="open = false">关闭</NButton>
|
||
<NButton
|
||
type="primary"
|
||
:loading="operation.pending"
|
||
:disabled="blocked || !acknowledged || !repairAvailable"
|
||
attr-type="submit"
|
||
>{{ label }}</NButton
|
||
>
|
||
</div>
|
||
</AppForm>
|
||
<p v-if="operation.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>
|
||
<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>
|
||
</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;
|
||
}
|
||
</style>
|