feat(short-drama-agent-front): 同步拆解候选审核与安全提交

This commit is contained in:
GJ committed 2026-10-17 20:18:20 +08:00
1 parent cc27d463e0
commit 190333d4f9
26 files changed
+1495 -249

No files matched your search

@@ -1,112 +1,152 @@
<script setup lang="ts">
import { computed } from 'vue'
import { NButton } from 'naive-ui'
import { computed, onScopeDispose, ref, watch } from 'vue'
import { NButton, NCheckbox } from 'naive-ui'
import { AppDialog, WorkspaceRefreshButton } from '../../../components/ui'
import type { BreakdownState } from '../types'
import { candidateCommitIssue } from '../candidate'
import type { BreakdownQuality } from '../quality'
import type { CandidateCommitPreview } from '../candidate.types'
import { candidateCheckKeys, candidateCheckLabels, candidatePreviewReady } from '../candidate'
import { breakdownApi } from '../api'
import { runOperation, getOperation, isOperationRunning } from '../../workflows/operations'
import ConfirmAction from '../../workflows/ConfirmAction.vue'
import { runOperation, getOperation } from '../../workflows/operations'
import { projectsApi } from '../../projects/api'
import { workflowCheckpoints } from '../../workflows/selectors'
import { errorMessage } from '../../../lib/http'
import { showActionFeedback, useActionMessage } from '../../../components/ui/useActionMessage'
/** 最新候选快照及独立提交入口。 */
/** 当前原始版本与集中审核结论共同决定安全检查入口。 */
const props = defineProps<{
/** 当前正式项目编号。 */
/** 当前项目。 */
projectId: string
/** 服务端最新原始快照,不使用历史回退结果。 */
/** 当前版本归一化候选。 */
state?: BreakdownState
/** 当前快照版本,用于撤销旧确认。 */
/** 当前检查点。 */
checkpointId?: string
/** 项目存在活动任务或读取错误。 */
/** 页面统一质量结论。 */
quality: BreakdownQuality
/** 活动任务或读取失败时禁止写入。 */
disabled: boolean
}>()
/** 提交后刷新正式资产和阶段状态。 */
/** 只在真实写回后刷新服务端资产及阶段状态。 */
const emit = defineEmits<{ refresh: [] }>()
/** 项目级操作锁与错误反馈沿用现有工作区。 */
/** 应用消息层。 */
const message = useActionMessage()
/** 项目级写操作锁。 */
const operation = computed(() => getOperation(props.projectId))
/** 显式候选标记,历史通过记录不作为提交依据。 */
const isCandidate = computed(() => props.state?.candidateOnly === true)
/** 候选完成后是否已经提交。 */
const committed = computed(() => props.state?.storyboardPersisted === true || props.state?.candidateCommitted === true)
/** 本地可见的提交阻断原因。 */
const issue = computed(() => candidateCommitIssue(props.state))
/** 本轮候选的真实规模。 */
const counts = computed(() => ({
subjects: props.state?.subjectCandidates?.length ?? 0,
episodes: props.state?.storyboardEpisodeShots?.length ?? 0,
shots:
props.state?.storyboardEpisodeShots?.reduce(
(total, episode) => total + episode.beatShots.reduce((sum, beat) => sum + beat.shots.length, 0),
0
) ?? 0
}))
/** 当前预检查回执。 */
const preview = ref<CandidateCommitPreview | null>(null)
/** 只读安全检查加载状态。 */
const checking = ref(false)
/** 本面板正式提交状态。 */
const committing = ref(false)
/** 预检查请求失败原因。 */
const checkError = ref('')
/** 仅通过预检查才能打开最终确认。 */
const confirmOpen = ref(false)
/** 用户对替换正式资产的明确确认。 */
const acknowledged = ref(false)
/** 已收到成功回执的版本,服务端刷新前也不允许重复写入。 */
const submittedId = ref('')
/** 过期、关闭和卸载时取消只读预检查。 */
let controller: AbortController | undefined
/** 拒绝忽略取消信号后返回的旧响应。 */
let version = 0
/** 当前候选生成或提交后的面板。 */
const isCandidate = computed(() => props.state?.candidateOnly === true && (props.quality.isCandidate || props.quality.committed))
/** 后端持久化标记优先,成功回执只在当前会话补充防重复锁。 */
const committed = computed(() => props.quality.committed || submittedId.value === `${props.projectId}:${props.checkpointId}`)
/** 审核通过后只允许请求预检查,绝不直接允许写入。 */
const canCheck = computed(() => !props.disabled && !operation.value.pending && !committed.value && props.quality.canRequestCommitPreview && props.quality.checkpointId === props.checkpointId)
/** 逐项与版本确认后的预检查结果。 */
const ready = computed(() => candidatePreviewReady(preview.value, props.projectId, props.checkpointId))
/** 仅展示具体未通过的安全检查。 */
const failedChecks = computed(() => preview.value ? candidateCheckKeys.filter(key => preview.value!.checks?.[key] !== true).map(key => candidateCheckLabels[key]) : [])
/** 当前候选规模与正式资产区别标注。 */
const counts = computed(() => ({ subjects: props.state?.subjectCandidates?.length ?? 0, episodes: props.state?.storyboardEpisodeShots?.length ?? 0, shots: props.state?.storyboardEpisodeShots?.reduce((sum, episode) => sum + episode.beatShots.reduce((total, beat) => total + beat.shots.length, 0), 0) ?? 0 }))
/** 只提交一次,后端事务再次校验剧本版本、候选审核和下游资产。 */
async function commit() {
if (props.disabled || issue.value || operation.value.pending) return
/** 撤销旧检查与确认,版本变化后不能复用提交许可。 */
function invalidate() {
version++
controller?.abort()
checking.value = false
preview.value = null
confirmOpen.value = false
acknowledged.value = false
checkError.value = ''
}
watch([() => props.projectId, () => props.checkpointId, () => props.quality.canRequestCommitPreview, () => props.quality.committed], invalidate, { flush: 'sync' })
watch(() => props.disabled, disabled => { if (disabled && !committing.value) invalidate() })
onScopeDispose(invalidate)
/** 安全检查通过后才展示最终确认;不调用任何写接口。 */
async function check() {
if (!canCheck.value || checking.value) return
invalidate()
const current = version
const id = props.projectId
const checkpointId = props.checkpointId
await runOperation(
id,
'正在提交拆解候选',
async () => {
const records = await projectsApi.checkpoints(id)
const latest = workflowCheckpoints(records, 'breakdown').at(-1)
if (
!checkpointId ||
!latest ||
props.projectId !== id ||
props.checkpointId !== checkpointId ||
latest.checkpointId !== checkpointId
)
throw new Error('拆解候选版本已变化,请刷新后重新确认。')
const nextIssue = candidateCommitIssue(latest.state)
if (nextIssue) throw new Error(nextIssue)
const receipt = await breakdownApi.commitCandidate(id)
if (receipt.projectId !== id) throw new Error('候选提交回执的项目不一致,请刷新确认。')
return receipt
},
receipt => ({
type: 'success',
content: `候选已提交:${receipt.subjectCount} 个主体、${receipt.episodeCount} 集、${receipt.shotCount} 个镜头。`
})
)
if (props.projectId === id) emit('refresh')
controller = new AbortController()
checking.value = true
try {
const result = await breakdownApi.candidateCommitPreview(id, controller.signal)
if (current !== version) return
if (result.projectId !== id || result.checkpointId !== checkpointId || result.readOnly !== true) throw new Error('候选安全预检查已过期,请刷新后重新检查。')
preview.value = result
if (candidatePreviewReady(result, id, checkpointId)) confirmOpen.value = true
else showActionFeedback(message, '候选暂不能提交,请处理未通过的安全检查。', 'warning')
} catch (cause) {
if (current === version) {
checkError.value = errorMessage(cause)
showActionFeedback(message, checkError.value, 'error')
}
} finally { if (current === version) checking.value = false }
}
/** 最终确认时重新核对版本和全部安全门禁,随后交由后端事务提交。 */
async function commit() {
if (!canCheck.value || !ready.value || !confirmOpen.value || !acknowledged.value || committing.value) return
const id = props.projectId
const checkpointId = props.checkpointId
const checkedVersion = version
committing.value = true
const ok = await runOperation(id, '正在提交拆解候选', async () => {
const records = await projectsApi.checkpoints(id)
const latest = workflowCheckpoints(records, 'breakdown').at(-1)
if (!checkpointId || latest?.checkpointId !== checkpointId || latest.state.storyboardPersisted || latest.state.candidateCommitted || props.projectId !== id || props.checkpointId !== checkpointId) throw new Error('拆解候选版本已变化或已经提交,请刷新后重新确认。')
const checked = await breakdownApi.candidateCommitPreview(id)
if (checkedVersion !== version || !props.quality.canRequestCommitPreview || !candidatePreviewReady(checked, id, checkpointId) || props.projectId !== id || props.checkpointId !== checkpointId) throw new Error('提交安全条件已变化,请重新检查候选。')
const receipt = await breakdownApi.commitCandidate(id)
if (receipt.projectId !== id) throw new Error('提交回执所属项目不一致,请刷新确认。')
return receipt
}, receipt => ({ type: 'success', content: `候选已提交:${receipt.subjectCount} 个主体、${receipt.episodeCount} 集、${receipt.shotCount} 个镜头。` }))
if (props.projectId === id) {
if (ok) submittedId.value = `${id}:${checkpointId}`
invalidate()
emit('refresh')
}
committing.value = false
}
</script>
<template>
<!-- 以下是候选审核与正式提交模块,沿用设置区的模块间距和按钮层级 -->
<!-- 以下是候选质量与安全提交模块,不使用只读审核结果替代事务门禁 -->
<section v-if="isCandidate" 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">{{ committed ? '候选已提交' : '待确认的拆解候选' }}</h3>
<span class="text-xs text-muted"
>主体 {{ counts.subjects }} · {{ counts.episodes }} 集 · {{ counts.shots }} 镜</span
>
<span class="text-xs text-muted">{{ committed ? '正式主体' : '候选主体' }} {{ counts.subjects }} · {{ counts.episodes }} 集 · {{ counts.shots }} 镜</span>
</div>
<p class="text-xs leading-6 text-muted">
{{ committed ? '这份结果已写入正式主体、形态与分镜。' : '候选不替换正式数据,校验通过后单独提交。' }}
</p>
<p v-if="!committed && issue" class="text-xs leading-6 text-muted" role="status">{{ issue }}</p>
<p class="text-xs leading-6 text-muted">{{ committed ? '这份结果已写入正式主体、形态与分镜。' : '候选尚未写入正式资产,质量审核后还需通过安全预检查。' }}</p>
<p v-if="!committed" class="text-xs text-muted" role="status">{{ quality.loading ? '正在重新审核当前候选…' : quality.needsRefresh ? '当前候选审核尚未确认,请刷新候选状态。' : quality.canRequestCommitPreview ? '候选质量审核通过,可执行提交安全预检查。' : '候选仍有待处理问题,请先修订。' }}</p>
<div class="flex flex-wrap items-center gap-3">
<ConfirmAction
v-if="!committed"
:key="checkpointId"
label="提交候选为正式结果"
description="将使用服务端最新候选统一替换正式主体、形态与分镜。此操作不调用模型;已有下游资产、剧本变化或审核未通过时,后端会拒绝提交。"
acknowledgement
:disabled="disabled || !!issue || operation.pending"
:loading="isOperationRunning(operation, '正在提交拆解候选')"
@confirm="commit"
/>
<NButton text :disabled="operation.pending" @click="emit('refresh')">刷新候选状态</NButton>
<NButton v-if="!committed" :disabled="!canCheck" :loading="checking || committing" @click="check">提交候选为正式结果</NButton>
<WorkspaceRefreshButton label="刷新候选状态" :loading="quality.loading" :disabled="operation.pending || checking" @refresh="emit('refresh')" />
</div>
<p
v-if="operation.error && operation.label === '正在提交拆解候选'"
role="alert"
class="text-xs leading-6 text-danger"
>
{{ operation.error }}
</p>
<section v-if="failedChecks.length" class="problem-surface p-4" aria-label="未通过的提交安全检查"><p class="mb-2 text-sm">提交安全检查未通过</p><ul class="list-inside list-disc space-y-2 text-xs"><li v-for="label in failedChecks" :key="label">{{ label }}</li></ul></section>
<p v-if="checkError" class="text-xs text-danger" role="alert">{{ checkError }}</p>
<!-- 以下是通过只读预检查后才出现的最终确认,取消和关闭撤销确认 -->
<AppDialog v-model:open="confirmOpen" title="确认提交候选为正式结果" :busy="committing" description="将替换正式主体、形态与分镜。提交时后端仍会在事务内重新检查剧本版本和下游资产。">
<p class="text-sm">本次候选:{{ counts.subjects }} 个主体、{{ counts.episodes }} 集、{{ counts.shots }} 个镜头。</p>
<NCheckbox v-model:checked="acknowledged" class="mt-5">我已确认替换正式结果,当前没有同项目的制作任务在运行。</NCheckbox>
<template #footer><NButton :disabled="committing" @click="confirmOpen = false; acknowledged = false">取消</NButton><NButton type="primary" :loading="committing" :disabled="!acknowledged || !ready || !canCheck" @click="commit">确认提交候选为正式结果</NButton></template>
</AppDialog>
</section>
</template>