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

113 lines
5.2 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 } from 'vue'
import { NButton } from 'naive-ui'
import type { BreakdownState } from '../types'
import { candidateCommitIssue } from '../candidate'
import { breakdownApi } from '../api'
import { runOperation, getOperation, isOperationRunning } from '../../workflows/operations'
import ConfirmAction from '../../workflows/ConfirmAction.vue'
import { projectsApi } from '../../projects/api'
import { workflowCheckpoints } from '../../workflows/selectors'
/** 最新候选快照及独立提交入口。 */
const props = defineProps<{
/** 当前正式项目编号。 */
projectId: string
/** 服务端最新原始快照,不使用历史回退结果。 */
state?: BreakdownState
/** 当前快照版本,用于撤销旧确认。 */
checkpointId?: string
/** 项目存在活动任务或读取错误。 */
disabled: boolean
}>()
/** 提交后刷新正式资产和阶段状态。 */
const emit = defineEmits<{ refresh: [] }>()
/** 项目级操作锁与错误反馈沿用现有工作区。 */
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
}))
/** 只提交一次,后端事务再次校验剧本版本、候选审核和下游资产。 */
async function commit() {
if (props.disabled || issue.value || operation.value.pending) return
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')
}
</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
>
</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>
<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>
</div>
<p
v-if="operation.error && operation.label === '正在提交拆解候选'"
role="alert"
class="text-xs leading-6 text-danger"
>
{{ operation.error }}
</p>
</section>
</template>