feat(short-drama-agent-front): 接入关系修复并优化配置与弹窗

This commit is contained in:
GJ committed 2026-10-31 22:37:22 +08:00
1 parent 2db8549818
commit 41d1cfe3ed
15 files changed
+1134 -323

No files matched your search

+76 -9
View File
@@ -49,6 +49,10 @@ const issuesOpen = ref(false)
const exceptionSaving = ref(false)
/** 从设置切换时等待关闭动画结束,避免两层弹窗同时显示。 */
const pendingIssues = ref(false)
/** 候选安全预检与关系修复使用独立抽屉,不与拆解设置叠加。 */
const candidateSafetyOpen = ref(false)
/** 从设置交接时绑定项目,离场后禁止打开旧项目预检。 */
const pendingSafetyProject = ref('')
/** 问题入口统一使用红色文字、图标和柔和底色,交互时保持错误语义。 */
const issueButtonTheme = {
color: 'var(--app-danger-soft)',
@@ -209,7 +213,24 @@ function finishOpeningIssues() {
pendingIssues.value = false
issuesOpen.value = true
}
if (pendingSafetyProject.value) {
const id = pendingSafetyProject.value
pendingSafetyProject.value = ''
if (id === projectId.value) candidateSafetyOpen.value = true
}
}
/** 打开同一个候选预检抽屉;从设置进入先释放原有焦点约束。 */
function openCandidateSafety() {
if (toolsOpen.value) {
pendingSafetyProject.value = projectId.value
toolsOpen.value = false
} else candidateSafetyOpen.value = true
}
/** 项目变化时撤销旧的抽屉交接,不回填旧项目预检。 */
watch(projectId, () => {
pendingSafetyProject.value = ''
candidateSafetyOpen.value = false
})
/**
* 切换到分镜结果并定位后端返回的真实问题坐标。
* @param issue 问题所属剧集、节拍和镜头
@@ -785,15 +806,18 @@ const isInitialEmpty = computed(
任务状态尚未确认,请重新读取后台状态后再操作。
</p>
</section>
<BreakdownCandidatePanel
v-show="!startPolicy.reviewOpen.value"
:project-id="projectId"
:state="qualityObservation.source.value.state || undefined"
:quality="quality"
:checkpoint-id="latestCheckpoint?.checkpointId"
:disabled="issueActionsDisabled"
@refresh="refreshCandidate"
/>
<!-- 以下是候选确认交接入口,问题与预检在独立抽屉处理 -->
<section v-if="quality.isCandidate && !startPolicy.reviewOpen.value" class="space-y-3">
<h3 class="text-sm font-medium">待确认的拆解候选</h3>
<p class="text-sm text-muted">候选通过质量审核后,再核对安全预检并确认采用正式结果。</p>
<NButton
class="workspace-action-button"
:disabled="issueActionsDisabled || !quality.canRequestCommitPreview"
@click="openCandidateSafety"
>
<template #icon><ShieldCheck :size="15" aria-hidden="true" /></template>候选安全预检
</NButton>
</section>
<!-- 以下是明确标记的历史执行回执,旧任务结论不表示当前候选质量 -->
<component
:is="executionHistorical ? NCollapse : 'div'"
@@ -898,6 +922,24 @@ const isInitialEmpty = computed(
>
<template #suffix
><div class="tabs-toolbar-actions breakdown-toolbar-actions">
<!-- 以下是待安全预检候选的直接入口,桌面显示文字,手机保留图标与提示 -->
<WorkspaceActionTooltip
v-if="quality.isCandidate && quality.canRequestCommitPreview"
label="候选安全预检"
mobile-only
>
<NButton
class="workspace-action-button breakdown-safety-trigger"
aria-label="候选安全预检"
aria-haspopup="dialog"
:aria-expanded="candidateSafetyOpen"
:disabled="issueActionsDisabled"
@click="openCandidateSafety"
>
<template #icon><ShieldCheck :size="15" aria-hidden="true" /></template>
<span class="breakdown-safety-label">候选安全预检</span>
</NButton>
</WorkspaceActionTooltip>
<!-- 以下是移动端校验问题入口,与设置图标并排且共用问题详情 -->
<NButton
v-if="hasBreakdownIssues"
@@ -1055,6 +1097,17 @@ const isInitialEmpty = computed(
</section>
</template>
</WorkspacePage>
<!-- 以下是独立的安全预检、单条关系修复和最终采用流程,共用真实状态刷新 -->
<BreakdownCandidatePanel
v-model:open="candidateSafetyOpen"
:project-id="projectId"
:state="qualityObservation.source.value.state || undefined"
:quality="quality"
:checkpoint-id="latestCheckpoint?.checkpointId"
:disabled="issueActionsDisabled"
:episodes="project?.episodes ?? []"
@refresh="refreshCandidate"
/>
<!-- 以下是与拆解设置分离的全屏问题详情抽屉 -->
<BreakdownIssuesDialog
v-model:open="issuesOpen"
@@ -1398,4 +1451,18 @@ const isInitialEmpty = computed(
@apply min-h-0 flex-nowrap;
}
}
/* 工具栏在手机仅保留预检图标,正文与底栏的确认操作继续显示完整文字。 */
@media (max-width: 639px) {
.breakdown-safety-label {
display: none;
}
.breakdown-safety-trigger {
width: 34px;
height: 34px;
padding: 0;
}
.breakdown-safety-trigger .n-button__icon {
margin: 0;
}
}
</style>
+17 -1
View File
@@ -20,7 +20,9 @@ import type {
CandidateSubjectRepairInput,
CandidateSubjectRepairResult,
CandidateActionRepairInput,
CandidateActionRepairResult
CandidateActionRepairResult,
CandidateRelationRepairInput,
CandidateRelationRepairResult
} from './candidate.types'
import type {
QualityRepairPlan,
@@ -89,6 +91,20 @@ export const breakdownApi = {
request<CandidateCommitPreview>(`/projects/${encodeURIComponent(id)}/breakdown/candidate-commit-preview`, {
signal
}),
/**
* 用户明确确认后移除预检中的单条无来源关系,只创建候选新版本。
* @param id 当前项目
* @param input 用户选定的原始关系、确认与保存记录
* @returns 新候选版本和实际移除数量
*/
repairCandidateRelation: (id: string, input: CandidateRelationRepairInput) =>
request<CandidateRelationRepairResult>(
`/projects/${encodeURIComponent(id)}/breakdown/candidate-relation-repair`,
{
method: 'POST',
body: input
}
),
/**
* 用户确认后补齐候选主体引用与真实形态。
* @param id 当前项目
+13 -5
View File
@@ -1,8 +1,8 @@
import type { BreakdownState } from './types'
import type { CandidateCommitPreview } from './candidate.types'
import type { CandidateCommitPreview, CandidateCommitCheckPreview } from './candidate.types'
/** 安全检查项与用户可理解的阻断原因共用一份映射。 */
export const candidateCheckLabels: Record<keyof CandidateCommitPreview['checks'], string> = {
export const candidateCheckLabels: Record<keyof CandidateCommitCheckPreview['checks'], string> = {
qualityPolicyMatches: '质量规则与当前已确认版本一致',
episodeNumbersMatch: '剧集范围与候选一致',
episodeFingerprintsMatch: '剧本正文版本未变化',
@@ -10,7 +10,8 @@ export const candidateCheckLabels: Record<keyof CandidateCommitPreview['checks']
noActiveVideos: '没有正在生成的视频',
noSubjectIdentities: '没有需要保护的主体身份',
noSubjectImages: '没有需要保护的主体图片',
noProtectedShots: '没有需要保护的镜头资产'
noProtectedShots: '没有需要保护的镜头资产',
relationEvidenceValid: '场景、道具关系的来源证据有效'
}
/** 必须逐项校验的固定安全门禁,不根据响应动态减少检查项。 */
export const candidateCheckKeys = [
@@ -21,7 +22,8 @@ export const candidateCheckKeys = [
'noActiveVideos',
'noSubjectIdentities',
'noSubjectImages',
'noProtectedShots'
'noProtectedShots',
'relationEvidenceValid'
] as const
/**
@@ -36,7 +38,13 @@ export function candidatePreviewReady(
projectId: string,
checkpointId?: string
): boolean {
if (!preview || preview.projectId !== projectId || preview.checkpointId !== checkpointId) return false
if (
!preview ||
preview.status === 'already_committed' ||
preview.projectId !== projectId ||
preview.checkpointId !== checkpointId
)
return false
// 外部 JSON 的布尔值必须严格为 true,不接受缺失值或字符串等真值。
const flags: unknown[] = [preview.readOnly, preview.ready, ...candidateCheckKeys.map(key => preview.checks?.[key])]
return flags.every(value => value === true)
+42 -2
View File
@@ -114,14 +114,39 @@ export interface CandidateRevalidation {
canCommit: false
}
/** 候选提交安全预检查响应,正式提交仍会在事务内复查。 */
export interface CandidateCommitPreview {
/** 预检返回的单条无来源关系,所有定位字段均须原样提交。 */
export interface CandidateRelationTarget {
/** 候选主体引用。 */ subjectRef: string
/** 候选主体名称。 */ subjectName: string
/** 原始关系。 */ relation: string
/** 原始关系目标。 */ target: string
/** 原始来源证据。 */ evidence: string
}
/** 人工明确移除单条关系的版本化请求,不允许删除主体或改写证据。 */
export interface CandidateRelationRepairInput extends Omit<CandidateRelationTarget, 'subjectName'> {
/** 必须由用户明确确认。 */ confirmed: true
/** 本次预检对应的保存记录。 */ expectedCheckpointId: string
}
/** 关系修复只保存新的候选版本,不代表候选已正式采用。 */
export interface CandidateRelationRepairResult {
/** 新保存记录。 */ checkpointId: string
/** 已处理的主体引用。 */ subjectRef: string
/** 本次仅移除一条。 */ removed: 1
}
/** 未提交候选的安全预检查响应,正式提交仍会在事务内复查。 */
export interface CandidateCommitCheckPreview {
/** 所属项目。 */
projectId: string
/** 被检查的候选版本。 */
checkpointId: string
/** 所有检查是否通过。 */
ready: boolean
/** 未提交分支不携带已提交状态。 */ status?: never
/** 关系来源阻断的原始说明。 */ relationIssues: string[]
/** 可供人工核对的原始关系,不代表已经确认删除。 */ relationRepairTargets: CandidateRelationTarget[]
/** 剧本版本、活动任务及下游资产保护。 */
checks: {
/** 候选使用的质量规则与当前明确确认版本一致。 */
@@ -140,6 +165,8 @@ export interface CandidateCommitPreview {
noSubjectImages: boolean
/** 没有受保护镜头资产。 */
noProtectedShots: boolean
/** 场景、道具关系的证据可在正式剧本中找到。 */
relationEvidenceValid: boolean
}
/** 真实数据数量。 */
counts: {
@@ -162,6 +189,19 @@ export interface CandidateCommitPreview {
readOnly: true
}
/** 已采用的候选没有 checks 和 counts,不能按预检失败处理。 */
export interface CandidateAlreadyCommitted {
/** 所属项目。 */ projectId: string
/** 最新保存记录。 */ checkpointId: string
/** 已提交结果不再提供提交许可。 */ ready: false
/** 后端明确的已提交状态。 */ status: 'already_committed'
/** 原始说明只用于展示转换。 */ reason: string
/** 此操作只读。 */ readOnly: true
}
/** 安全预检按后端真实响应区分未提交和已提交结果。 */
export type CandidateCommitPreview = CandidateCommitCheckPreview | CandidateAlreadyCommitted
/** 人工确认的候选主体补齐请求。 */
export interface CandidateSubjectRepairInput extends CandidateShotLocation {
/** 乐观版本锁。 */
@@ -1,182 +1,342 @@
<script setup lang="ts">
import { computed, onScopeDispose, ref, watch } from 'vue'
import { NButton, NCheckbox } from 'naive-ui'
import { AppDialog, WorkspaceRefreshButton } from '../../../components/ui'
import { NButton, NCheckbox, NCollapse, NCollapseItem, NRadio, NSelect, NTag } from 'naive-ui'
import { Trash2 } from '@lucide/vue'
import { AppDrawer, WorkspaceRefreshButton, WorkspaceSectionHeading } from '../../../components/ui'
import type { BreakdownState } from '../types'
import type { BreakdownQuality } from '../quality'
import type { CandidateCommitPreview } from '../candidate.types'
import type { CandidateCommitPreview, CandidateRelationTarget } from '../candidate.types'
import type { Episode } from '../../projects/types'
import { candidateCheckKeys, candidateCheckLabels, candidatePreviewReady } from '../candidate'
import { breakdownApi } from '../api'
import { runOperation, getOperation } from '../../workflows/operations'
import { projectsApi } from '../../projects/api'
import { workflowCheckpoints } from '../../workflows/selectors'
import { errorMessage } from '../../../lib/http'
import { ApiError, 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 props = withDefaults(
defineProps<{
/** 当前项目。 */ projectId: string
/** 最新原始候选。 */ state?: BreakdownState
/** 最新保存记录。 */ checkpointId?: string
/** 集中的候选质量结论。 */ quality: BreakdownQuality
/** 活动任务或读取异常时禁止写入。 */ disabled: boolean
/** 项目详情已读取的正式原文,仅用于人工核对。 */ episodes?: Pick<Episode, 'episode' | 'content'>[]
}>(),
{ episodes: () => [] }
)
/** 抽屉关闭后立即废弃只读请求,不保留提交许可。 */
const open = defineModel<boolean>('open', { default: false })
/** 真实写回、发现旧版本或已提交结果后刷新项目、审核和阶段。 */
const emit = defineEmits<{ refresh: [] }>()
/** 应用消息层。 */
/** 全局消息反馈。 */
const message = useActionMessage()
/** 项目级写操作锁。 */
/** 当前项目的活动任务及短请求锁。 */
const operation = computed(() => getOperation(props.projectId))
/** 当前预检查回执。 */
/** 当前只读预检原始回执。 */
const preview = ref<CandidateCommitPreview | null>(null)
/** 只读安全检查加载状态。 */
/** 预检只读加载,允许关闭。 */
const checking = ref(false)
/** 本面板正式提交状态。 */
const committing = ref(false)
/** 预检查请求失败原因。 */
const checkError = ref('')
/** 仅通过预检查才能打开最终确认。 */
const confirmOpen = ref(false)
/** 用户对替换正式资产的明确确认。 */
/** 真实写入期间锁定关闭与重复操作。 */
const writing = ref(false)
/** 读取或本次写入失败,保留可操作的中文原因。 */
const actionError = ref('')
/** 默认不选关系,每次只允许人工处理一条。 */
const selectedIndex = ref<number | null>(null)
/** 人工勾选仅针对当前关系或最终提交,切换操作时清空。 */
const acknowledged = ref(false)
/** 已收到成功回执的版本,服务端刷新前也不允许重复写入。 */
const submittedId = ref('')
/** 过期、关闭和卸载时取消只读预检查。 */
/** 写入成功后等待页面拿到新版本,不能再次使用旧预检。 */
const awaitingRefresh = ref(false)
/** 正式原文核对的集号,不推断关系所属剧集。 */
const sourceEpisode = ref<number | null>(null)
/** 只读请求可取消,写操作不做自动重试。 */
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 committed = computed(() => props.quality.committed || preview.value?.status === 'already_committed')
/** 质量审核通过只是读取预检的前置条件。 */
const canCheck = computed(
() =>
!props.disabled &&
!operation.value.pending &&
!committed.value &&
!awaitingRefresh.value &&
props.quality.canRequestCommitPreview &&
props.quality.checkpointId === props.checkpointId
)
/** 逐项与版本确认后的预检查结果。 */
/** 自身写入期间保留原按钮与加载反馈,其余操作仍遵守项目锁。 */
const actionsVisible = computed(() => canCheck.value || writing.value)
/** 只使用当前项目、当前版本且只读标记有效的未提交预检。 */
const current = computed(() => {
const result = preview.value
return result &&
result.status !== 'already_committed' &&
result.readOnly === true &&
result.projectId === props.projectId &&
result.checkpointId === props.checkpointId
? result
: null
})
/** 全部门禁通过才能显示正式提交操作。 */
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])
: []
current.value ? candidateCheckKeys.filter(key => current.value!.checks?.[key] !== true) : []
)
/** 当前候选规模与正式资产区别标注。 */
/** 原始关系只能来自本次安全预检,不解析问题字符串构造删除参数。 */
const targets = computed(() => current.value?.relationRepairTargets ?? [])
/** 用户选择的关系仍需校验完整且定位唯一。 */
const selected = computed(() => (selectedIndex.value === null ? null : (targets.value[selectedIndex.value] ?? null)))
/** 非空字段与唯一关系是写入前提,不裁剪原始提交值。 */
const selectionIssue = computed(() => {
const target = selected.value
if (!target) return ''
if (
![target.subjectRef, target.relation, target.target, target.evidence].every(
value => typeof value === 'string' && value.trim()
)
)
return '这条关系缺少完整定位信息,请刷新预检。'
return targets.value.filter(item => sameRelation(item, target)).length === 1
? ''
: '关系定位不唯一,请重新读取并核对。'
})
/** 修复只在当前剧本和规则未变、无活动任务时开放;资产保护仍由最终提交独立检查。 */
const repairSafe = computed(() => !!current.value && repairConditions(current.value))
/** 读取项目详情中的正式正文,不调用模型,也不虚构剧集查询接口。 */
const episodeOptions = computed(() =>
props.episodes.map(item => ({ value: item.episode, label: `第 ${item.episode} 集` }))
)
/** 用户选集后按原样显示完整正文。 */
const sourceContent = computed(() => props.episodes.find(item => item.episode === sourceEpisode.value)?.content ?? '')
/** 候选规模只用于说明替换范围。 */
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),
(sum, episode) => sum + episode.beatShots.reduce((n, beat) => n + beat.shots.length, 0),
0
) ?? 0
}))
/** 撤销旧检查与确认,版本变化后不能复用提交许可。 */
/**
* 按后端四个精确定位字段比较关系,不改写证据。
* @param left 待检查关系
* @param right 用户核对的关系
* @returns 是否为同一原始关系
*/
function sameRelation(left: CandidateRelationTarget, right: CandidateRelationTarget): boolean {
return (
left.subjectRef === right.subjectRef &&
left.relation === right.relation &&
left.target === right.target &&
left.evidence === right.evidence
)
}
/**
* 关系修复依赖来源一致及无活动任务,不能以资产未生成代替任务锁。
* @param result 最新只读预检
* @returns 是否具备关系修复的来源与任务条件
*/
function repairConditions(result: CandidateCommitPreview): boolean {
return (
result.status !== 'already_committed' &&
result.readOnly === true &&
[
'qualityPolicyMatches',
'episodeNumbersMatch',
'episodeFingerprintsMatch',
'noActiveExecutions',
'noActiveVideos'
].every(key => result.checks?.[key as keyof typeof result.checks] === true)
)
}
/** 撤销旧回执与人工勾选,关闭或版本改变后不能复用。 */
function invalidate() {
version++
controller?.abort()
checking.value = false
preview.value = null
confirmOpen.value = false
selectedIndex.value = null
acknowledged.value = false
checkError.value = ''
actionError.value = ''
}
/** 打开、换项目、换版本后重新读取;关闭时仅取消只读请求。 */
watch(
[
() => props.projectId,
() => props.checkpointId,
() => props.quality.canRequestCommitPreview,
() => props.quality.committed
],
invalidate,
{ flush: 'sync' }
)
watch(
() => props.disabled,
disabled => {
if (disabled && !committing.value) invalidate()
}
[open, () => props.projectId, () => props.checkpointId],
([shown, id, cp], old) => {
invalidate()
if (!old || id !== old[1] || cp !== old[2]) {
awaitingRefresh.value = false
sourceEpisode.value = null
}
if (shown && canCheck.value) void check()
},
{ immediate: true }
)
/** 外部任务或质量变化立即撤销旧许可,自身写入造成的锁不清空人工选择。 */
watch([() => props.disabled, () => props.quality.canRequestCommitPreview, () => props.quality.committed], () => {
if (writing.value) return
if (!canCheck.value) invalidate()
else if (open.value && !preview.value && !checking.value) void check()
})
/** 用户切换关系后必须重新明确勾选。 */
watch(selectedIndex, () => {
acknowledged.value = false
})
onScopeDispose(invalidate)
/** 安全检查通过后才展示最终确认;不调用任何写接口。 */
/** 只读刷新安全预检,不自动删除关系或提交候选。 */
async function check() {
if (!canCheck.value || checking.value) return
if (!open.value || !canCheck.value || writing.value || checking.value) return
invalidate()
const current = version
const id = props.projectId
const checkpointId = props.checkpointId
const stamp = version,
id = props.projectId,
cp = props.checkpointId
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('候选安全预检查已过期,请刷新后重新检查。')
if (stamp !== version) return
if (
result.projectId !== id ||
result.readOnly !== true ||
(result.status !== 'already_committed' && result.checkpointId !== cp)
)
throw new Error('候选安全预检已过期,请刷新项目后重新检查。')
preview.value = result
if (candidatePreviewReady(result, id, checkpointId)) confirmOpen.value = true
else showActionFeedback(message, '候选暂不能提交,请处理未通过的安全检查。', 'warning')
if (result.status === 'already_committed') emit('refresh')
} catch (cause) {
if (current === version) {
checkError.value = errorMessage(cause)
showActionFeedback(message, checkError.value, 'error')
if (stamp === version) {
actionError.value = errorMessage(cause)
showActionFeedback(message, actionError.value, 'error')
}
} finally {
if (current === version) checking.value = false
if (stamp === version) checking.value = false
}
}
/** 取消最终确认时关闭弹窗并清除勾选,保留本次安全预检查结果。 */
function cancelConfirmation() {
confirmOpen.value = false
acknowledged.value = false
/** 刷新按钮同时恢复页面最新质量结论;等待新版本时不再检查旧保存记录。 */
function refreshPreview() {
if (writing.value) return
emit('refresh')
if (!awaitingRefresh.value) void check()
}
/** 最终确认时重新核对版本和全部安全门禁,随后交由后端事务提交。 */
/**
* 写入前读取最新原始保存记录,避免历史回退和跨项目写入。
* @param id 当前操作绑定的项目
* @param cp 用户核对过的保存记录
* @returns 当前版本核对完成
*/
async function assertCheckpoint(id: string, cp: string | undefined): Promise<void> {
const records = await projectsApi.checkpoints(id)
const latest = workflowCheckpoints(records, 'breakdown').at(-1)
if (
!cp ||
latest?.checkpointId !== cp ||
latest.state.storyboardPersisted ||
latest.state.candidateCommitted ||
props.projectId !== id ||
props.checkpointId !== cp ||
!open.value
)
throw new Error('拆解候选版本已变化或已经提交,请刷新后重新确认。')
}
/** 用户明确确认后只移除一条当前仍无来源的关系,成功后等待新版本重新预检。 */
async function repairRelation() {
if (
!canCheck.value ||
!repairSafe.value ||
!selected.value ||
selectionIssue.value ||
!acknowledged.value ||
writing.value ||
checking.value
)
return
const id = props.projectId,
cp = props.checkpointId,
target = { ...selected.value },
stamp = version
let stale = false
writing.value = true
actionError.value = ''
const ok = await runOperation(
id,
'正在移除无来源关系',
async () => {
try {
await assertCheckpoint(id, cp)
} catch (cause) {
stale = true
throw cause
}
const checked = await breakdownApi.candidateCommitPreview(id)
if (
stamp !== version ||
checked.projectId !== id ||
checked.checkpointId !== cp ||
!props.quality.canRequestCommitPreview ||
!repairConditions(checked) ||
checked.status === 'already_committed' ||
checked.relationRepairTargets?.filter(item => sameRelation(item, target)).length !== 1 ||
props.projectId !== id ||
props.checkpointId !== cp ||
!open.value
) {
stale = true
throw new Error('关系、来源或任务状态已变化,请重新预检后确认。')
}
const result = await breakdownApi.repairCandidateRelation(id, {
confirmed: true,
expectedCheckpointId: cp!,
subjectRef: target.subjectRef,
relation: target.relation,
target: target.target,
evidence: target.evidence
})
if (
result.removed !== 1 ||
result.subjectRef !== target.subjectRef ||
!result.checkpointId ||
result.checkpointId === cp
)
throw new Error('关系处理结果尚未确认,请重新读取最新结果。')
return result
},
{ type: 'info', content: '已移除这条候选关系,正在重新读取预检;正式结果尚未提交。' }
)
writing.value = false
if (props.projectId !== id || stamp !== version) return
const failure = operation.value.error
const conflict = operation.value.cause instanceof ApiError && operation.value.cause.status === 409
acknowledged.value = false
if (ok || stale || conflict) {
invalidate()
awaitingRefresh.value = ok
emit('refresh')
}
actionError.value = failure
}
/** 全部门禁通过且用户单独确认后,再次核对版本与预检,随后正式采用候选。 */
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
if (!canCheck.value || !ready.value || selected.value || !acknowledged.value || writing.value || checking.value)
return
const id = props.projectId,
cp = props.checkpointId,
stamp = version
writing.value = true
actionError.value = ''
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('拆解候选版本已变化或已经提交,请刷新后重新确认。')
await assertCheckpoint(id, cp)
const checked = await breakdownApi.candidateCommitPreview(id)
if (
checkedVersion !== version ||
!props.quality.canRequestCommitPreview ||
!candidatePreviewReady(checked, id, checkpointId) ||
props.projectId !== id ||
props.checkpointId !== checkpointId
)
if (stamp !== version || !props.quality.canRequestCommitPreview || !candidatePreviewReady(checked, id, cp))
throw new Error('提交安全条件已变化,请重新检查候选。')
const receipt = await breakdownApi.commitCandidate(id)
if (receipt.projectId !== id) throw new Error('提交回执所属项目不一致,请刷新确认。')
@@ -187,95 +347,174 @@ async function commit() {
content: `拆解结果已保存并采用:${receipt.subjectCount} 个主体、${receipt.episodeCount} 集、${receipt.shotCount} 个镜头。`
})
)
if (props.projectId === id) {
if (ok) submittedId.value = `${id}:${checkpointId}`
invalidate()
emit('refresh')
}
committing.value = false
writing.value = false
if (props.projectId !== id || stamp !== version) return
const failure = operation.value.error
invalidate()
awaitingRefresh.value = false
actionError.value = failure
if (ok) open.value = false
emit('refresh')
}
</script>
<template>
<!-- 以下是候选质量与安全提交模块,不使用只读审核结果替代事务门禁 -->
<section
v-if="isCandidate"
class="workspace-panel space-y-4"
:class="{ 'breakdown-candidate-committed': committed }"
aria-label="拆解候选"
<!-- 以下是与拆解设置分离的安全预检及关系问题处理全屏抽屉 -->
<AppDrawer
v-model:open="open"
title="候选安全预检"
:busy="writing"
description="核对剧本来源、活动任务和已有制作成果。无来源关系需逐条人工确认;全部预检通过后再确认采用正式结果。"
>
<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"
>{{ committed ? '正式主体' : '候选主体' }} {{ counts.subjects }} · {{ counts.episodes }} 集 ·
{{ counts.shots }} 镜</span
>
</div>
<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 v-if="!committed" class="flex flex-wrap items-center gap-3">
<NButton :disabled="!canCheck" :loading="checking || committing" @click="check">提交候选为正式结果</NButton>
<WorkspaceRefreshButton
label="重新检查"
:loading="quality.loading"
:disabled="operation.pending || checking"
@refresh="emit('refresh')"
/>
</div>
<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 }} 个镜头。
<div class="space-y-6" :aria-busy="checking">
<p v-if="checking" role="status" class="text-sm text-muted">正在读取安全预检…</p>
<p v-else-if="committed" role="status" class="text-sm">已提交正式结果,请以页面最新结果为准。</p>
<p v-else-if="awaitingRefresh" role="status" class="text-sm text-muted">
正在等待最新保存记录,请刷新状态后继续核对。
</p>
<NCheckbox v-model:checked="acknowledged" class="mt-5"
>我已确认替换正式结果,当前没有同项目的制作任务在运行。</NCheckbox
>
<template #footer
><NButton :disabled="committing" @click="cancelConfirmation">取消</NButton
><NButton
type="primary"
:loading="committing"
:disabled="!acknowledged || !ready || !canCheck"
@click="commit"
>确认提交候选为正式结果</NButton
></template
>
</AppDialog>
</section>
<p v-else-if="!canCheck && !current" role="status" class="text-sm text-muted">
当前任务或候选审核状态尚未满足预检条件,请刷新状态。
</p>
<p v-if="actionError" role="alert" class="text-sm text-danger">{{ actionError }}</p>
<template v-if="current && !committed">
<!-- 以下是当前候选规模与后端逐项预检结果,不把候选审核当作提交许可 -->
<section class="space-y-4" aria-label="候选提交预检">
<WorkspaceSectionHeading
title="提交安全检查"
:description="`候选主体 ${counts.subjects} · ${counts.episodes} 集 · ${counts.shots} 个镜头`"
/>
<NTag :type="ready ? 'success' : 'warning'" :bordered="false">{{
ready ? '安全预检通过,等待人工确认采用' : '安全预检未通过'
}}</NTag>
<section
v-if="failedChecks.length"
class="problem-surface p-4 space-y-3"
aria-label="未通过的提交安全检查"
>
<p class="text-sm">以下条件尚未满足:</p>
<ul class="list-inside list-disc space-y-2 text-sm">
<li v-for="key in failedChecks" :key="key">{{ candidateCheckLabels[key] }}</li>
</ul>
</section>
</section>
<!-- 以下是后端返回的关系问题与正式原文,窄屏自然改为单列 -->
<div v-if="targets.length || current.relationIssues?.length" class="grid min-w-0 gap-6 lg:grid-cols-2">
<section class="min-w-0 space-y-4" aria-label="无来源关系">
<WorkspaceSectionHeading
title="核对关系来源"
description="移除仅影响这条候选关系,不删除主体或镜头,也不会改写剧本。每次处理一条。"
/>
<article
v-for="(item, index) in targets"
:key="index"
class="problem-surface p-4 space-y-3 min-w-0 wrap-anywhere"
>
<h3 class="text-sm font-medium">
{{ item.subjectName }} · {{ item.relation }} → {{ item.target }}
</h3>
<p class="text-xs text-muted">候选引用:{{ item.subjectRef }}</p>
<p class="text-sm text-muted">原始来源证据</p>
<blockquote class="whitespace-pre-wrap text-sm leading-7">{{ item.evidence }}</blockquote>
<NRadio
:checked="selectedIndex === index"
:disabled="writing || checking || !canCheck || !repairSafe"
@update:checked="selectedIndex = index"
>核对后移除这条无来源关系</NRadio
>
</article>
<p v-if="!targets.length" class="text-sm text-muted">当前未提供可定位的关系,请刷新预检。</p>
<NCollapse v-if="current.relationIssues?.length"
><NCollapseItem name="details" title="关系检查详情">
<p
v-for="(issue, index) in current.relationIssues"
:key="index"
class="text-sm leading-7 wrap-anywhere"
>
{{ issue }}
</p>
</NCollapseItem></NCollapse
>
<p v-if="selectionIssue" role="alert" class="text-sm text-danger">{{ selectionIssue }}</p>
<NButton
v-if="selected"
class="workspace-action-button"
:disabled="writing"
@click="selectedIndex = null"
>取消选择</NButton
>
</section>
<!-- 以下是复用项目详情的正式原文,不推断问题所属集数 -->
<section class="min-w-0 space-y-4" aria-label="正式剧本核对">
<NCollapse :default-expanded-names="['source']"
><NCollapseItem name="source" title="正式剧本原文">
<div class="space-y-4">
<NSelect
v-model:value="sourceEpisode"
:options="episodeOptions"
aria-label="选择核对剧集"
placeholder="选择需要核对的剧集"
:disabled="!episodeOptions.length"
/>
<pre
class="max-h-[60dvh] overflow-auto whitespace-pre-wrap wrap-anywhere p-4 text-sm leading-7 bg-(--app-control)"
>{{
sourceContent ||
(episodeOptions.length
? '请选择需要核对的剧集。'
: '当前没有可核对的正式正文。')
}}</pre>
</div>
</NCollapseItem></NCollapse
>
</section>
</div>
<p v-if="ready" class="text-sm leading-7 text-muted">
采用候选将替换正式主体、形态与分镜。保存时还会检查剧本变化及已有制作成果,关系修复不会自动执行这一步。
</p>
</template>
</div>
<!-- 以下是固定底栏:关系移除与正式采用分别明确确认,禁止重复写入 -->
<template #footer>
<div class="flex w-full flex-wrap items-center justify-between gap-4">
<NCheckbox
v-if="actionsVisible && !checking && ((selected && !selectionIssue && repairSafe) || ready)"
v-model:checked="acknowledged"
:disabled="writing"
class="min-w-0 flex-[1_1_360px]"
>
{{
selected
? '我已核对原文,确认仅移除所选候选关系。'
: '我已核对预检结果,确认替换正式主体、形态与分镜。'
}}
</NCheckbox>
<div class="ml-auto flex flex-wrap items-center justify-end gap-2">
<NButton :disabled="writing" @click="open = false">关闭</NButton>
<WorkspaceRefreshButton
label="刷新预检"
:loading="checking"
:disabled="writing || operation.pending"
@refresh="refreshPreview"
/>
<NButton
v-if="selected && !selectionIssue && repairSafe && actionsVisible"
type="primary"
:loading="writing"
:disabled="!acknowledged || checking || writing"
@click="repairRelation"
>
<template #icon><Trash2 :size="15" aria-hidden="true" /></template>确认移除这条关系
</NButton>
<NButton
v-else-if="ready && actionsVisible"
type="primary"
:loading="writing"
:disabled="!acknowledged || checking || writing"
@click="commit"
>确认提交候选为正式结果</NButton
>
</div>
</div>
</template>
</AppDrawer>
</template>
<style scoped>
/* 只表达结果已成功保存并采用,未采用时保留默认底色,质量审核结论仍独立展示。 */
.workspace-panel.breakdown-candidate-committed {
background: var(--app-success-soft);
}
</style>