Files
short-drama-agent-front/src/features/breakdown/components/StoryboardQualityRepair.vue
T

254 lines
10 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 { computed, onScopeDispose, ref, watch } from 'vue'
import { NButton } from 'naive-ui'
import { AppDialog } from '../../../components/ui'
import { breakdownApi } from '../api'
import type { Checkpoint } from '../../workflows/types'
import type { QualityRepairCandidates, QualityRepairPlan, QualityRepairTarget, ShotActionDraft } from '../repair.types'
import { actionDraft, actionDraftIssue, qualityIssueLabel } from '../repair'
import { errorMessage } from '../../../lib/http'
import { getOperation, runOperation } from '../../workflows/operations'
import ShotActionEditor from './ShotActionEditor.vue'
import ConfirmAction from '../../workflows/ConfirmAction.vue'
/** 未入库镜头的质量门禁修订面板,正式资产仍使用独立接口保护。 */
const props = defineProps<{
/** 当前项目编号。 */
projectId: string
/** 当前最新原始检查点。 */
checkpoint?: Checkpoint
/** 活动任务、读取错误等外部禁用条件。 */
disabled: boolean
}>()
/** 保存后读取新检查点,不能直接宣称已正式入库。 */
const emit = defineEmits<{ refresh: [] }>()
/** 实际修复计划。 */
const plan = ref<QualityRepairPlan | null>(null)
/** 实际局部修复候选。 */
const candidates = ref<QualityRepairCandidates | null>(null)
/** 只读查询状态。 */
const loading = ref(false)
/** 查询或版本错误。 */
const error = ref('')
/** 当前人工选择的修订目标。 */
const target = ref<QualityRepairTarget | null>(null)
/** 用户编辑的独立草稿。 */
const draft = ref<ShotActionDraft | null>(null)
/** 编辑弹窗可见性。 */
const open = ref(false)
/** 草稿修订号,任何修改均撤销先前确认。 */
const draftVersion = ref(0)
/** 项目级活动操作锁。 */
const operation = computed(() => getOperation(props.projectId))
/** 计划必须与当前原始检查点完全一致。 */
const current = computed(() => !!plan.value?.checkpointId && plan.value.checkpointId === props.checkpoint?.checkpointId)
/** 当前镜头的有效候选指纹与建议。 */
const candidate = computed(() =>
target.value && candidates.value && candidates.value.checkpointId === plan.value?.checkpointId
? candidates.value.candidates.find(
item =>
item.shotId ===
`episode:${target.value!.episodeNo}/beat:${target.value!.beatNo}/shot:${target.value!.shotNo}`
)
: undefined
)
/** 草稿字段校验问题。 */
const issue = computed(() => (draft.value ? actionDraftIssue(draft.value) : '请先选择待修订镜头。'))
/** 当前编辑目标的可读名称。 */
const targetLabel = computed(() =>
target.value
? `第 ${target.value.episodeNo} 集 · 节拍 ${target.value.beatNo} · 镜头 ${target.value.shotNo}`
: '镜头修订'
)
/** 请求版本控制,关闭或切换项目后不回填旧结果。 */
let version = 0
/** 当前查询取消控制器。 */
let controller: AbortController | undefined
/** 按需读取真实修复计划与有效候选,不触发模型。 */
async function load() {
if (loading.value || props.disabled) return
const currentVersion = ++version
const id = props.projectId
controller?.abort()
controller = new AbortController()
loading.value = true
error.value = ''
plan.value = null
candidates.value = null
try {
const [nextPlan, nextCandidates] = await Promise.all([
breakdownApi.qualityRepairPlan(id, controller.signal),
breakdownApi.qualityRepairCandidates(id, controller.signal)
])
if (version !== currentVersion) return
if (nextPlan.projectId !== id || nextCandidates.projectId !== id)
throw new Error('修复清单所属项目不一致,请刷新。')
plan.value = nextPlan
candidates.value = nextCandidates
if (nextPlan.repairPlan.length && nextPlan.checkpointId !== props.checkpoint?.checkpointId)
throw new Error('拆解结果已更新,请先刷新候选状态,再重新读取修复清单。')
} catch (cause) {
if (version === currentVersion) error.value = errorMessage(cause)
} finally {
if (version === currentVersion) loading.value = false
}
}
/**
* 从对应版本的原始镜头创建完整草稿,不用历史诊断重建动作证据。
* @param item 当前修复计划中的镜头坐标
*/
function edit(item: QualityRepairTarget) {
if (!current.value || props.disabled) return
const shot = props.checkpoint?.state.storyboardEpisodeShots
?.find(episode => episode.episodeNo === item.episodeNo)
?.beatShots.find(beat => beat.beatNo === item.beatNo)
?.shots.find(value => value.shotNo === item.shotNo)
if (!shot) {
error.value = '当前版本缺少镜头原始数据,请刷新拆解结果。'
return
}
target.value = { ...item }
draft.value = actionDraft(shot)
open.value = true
}
/** 人工确认后只写入新的检查点,恢复资格采用服务端结果。 */
async function save() {
if (
!current.value ||
props.disabled ||
operation.value.pending ||
issue.value ||
!target.value ||
!draft.value ||
!plan.value?.checkpointId
)
return
const id = props.projectId
const input = {
...actionDraft(draft.value),
episodeNo: target.value.episodeNo,
beatNo: target.value.beatNo,
shotNo: target.value.shotNo,
expectedCheckpointId: plan.value.checkpointId,
...(candidate.value
? { expectedFingerprint: candidate.value.expectedFingerprint, source: 'candidate' as const }
: { source: 'manual' as const })
}
const success = await runOperation(
id,
'正在保存镜头人工修订',
async () => {
const result = await breakdownApi.repairQualityShot(id, input)
if (result.projectId !== id || !result.checkpointId || result.checkpointId === input.expectedCheckpointId)
throw new Error('未取得新的修订版本,请刷新确认。')
return result
},
result => ({
type: result.canResumeBreakdown ? 'success' : 'warning',
content: result.canResumeBreakdown
? '人工修订已保存,可继续恢复拆解。正式数据尚未提交。'
: '人工修订已保存,仍有待处理质量问题。'
})
)
if (props.projectId !== id) return
if (success) {
open.value = false
plan.value = null
candidates.value = null
} else {
plan.value = null
error.value = '保存未成功,请刷新拆解结果并重新读取修复清单。'
}
emit('refresh')
}
watch(
draft,
() => {
draftVersion.value++
},
{ deep: true, flush: 'sync' }
)
watch(
() => [props.projectId, props.checkpoint?.checkpointId],
() => {
version++
controller?.abort()
loading.value = false
plan.value = null
candidates.value = null
target.value = null
draft.value = null
open.value = false
error.value = ''
}
)
onScopeDispose(() => {
version++
controller?.abort()
})
</script>
<template>
<!-- 以下是未入库分镜质量门禁的按需修订入口 -->
<section class="workspace-panel space-y-4" aria-label="分镜质量修订">
<div class="flex flex-wrap items-center justify-between gap-3">
<h3 class="text-sm font-medium">分镜质量修订</h3>
<NButton :loading="loading" :disabled="disabled || loading" @click="load">读取修复清单</NButton>
</div>
<p class="text-xs leading-6 text-muted">仅修订尚未入库的镜头,保存后再恢复拆解。</p>
<p v-if="error" role="alert" class="text-xs leading-6 text-danger">{{ error }}</p>
<p v-if="plan && !plan.repairPlan.length && !error" role="status" class="text-xs text-muted">
当前没有可人工修订的质量阻断镜头,不代表未诊断镜头已通过。
</p>
<article
v-for="item in plan?.repairPlan"
:key="`${item.episodeNo}-${item.beatNo}-${item.shotNo}`"
class="flex flex-wrap items-center justify-between gap-3"
>
<div class="min-w-0">
<p class="text-sm">第 {{ item.episodeNo }} 集 · 节拍 {{ item.beatNo }} · 镜头 {{ item.shotNo }}</p>
<p class="mt-2 break-words text-xs text-muted">
{{ item.blockingCodes.map(qualityIssueLabel).join('、') }}
</p>
</div>
<NButton :disabled="disabled || !current" @click="edit(item)">人工修订</NButton>
</article>
</section>
<!-- 以下是版本化镜头人工修订模块,沿用公共弹窗底栏与间距 -->
<AppDialog
v-model:open="open"
:title="targetLabel"
description="调整镜头中的动作和先后顺序,保存时会重新检查这个镜头。此操作不调用模型。"
:busy="operation.pending"
wide
>
<div v-if="draft" class="space-y-5">
<p v-if="candidate" class="text-xs leading-6 text-muted">
{{ candidate.suggestion }} {{ candidate.blockingReasons.join(';') }}
</p>
<ShotActionEditor v-model="draft" :disabled="disabled || operation.pending || !current" />
<p v-if="issue" role="status" class="text-xs leading-6 text-danger">{{ issue }}</p>
<p
v-if="operation.error && operation.label === '正在保存镜头人工修订'"
role="alert"
class="text-xs leading-6 text-danger"
>
{{ operation.error }}
</p>
</div>
<template #footer
><NButton :disabled="operation.pending" @click="open = false">取消</NButton
><ConfirmAction
:key="draftVersion"
label="保存人工修订"
description="保存当前镜头的动作安排。如果内容版本已变化或检查仍未通过,需要先处理问题。保存后还需继续拆解并提交正式结果。"
:disabled="disabled || operation.pending || !current || !!issue"
@confirm="save"
/></template>
</AppDialog>
</template>