feat(short-drama-agent-front): 完善质量规则确认与中文交互
This commit is contained in:
1 parent
190333d4f9
commit
c4b43b9725
85 files changed
+2059
-480
No files matched your search
@@ -7,8 +7,9 @@ import WorkspaceExportButton from '../../components/ui/WorkspaceExportButton.vue
|
||||
import { NScrollbar, NButton, NCheckbox, NCollapse, NCollapseItem, NInputNumber, NTab, NTable, NTabs } from 'naive-ui'
|
||||
import { computed, h, nextTick, onScopeDispose, ref, watch } from 'vue'
|
||||
import { useActionMessage } from '../../components/ui/useActionMessage'
|
||||
import { CircleAlert, Layers, LoaderCircle, Settings2 } from '@lucide/vue'
|
||||
import { EmptyState, StatusBadge, WorkspaceTools } from '../../components/ui'
|
||||
import { CircleAlert, Layers, LoaderCircle, Settings2, ShieldCheck } from '@lucide/vue'
|
||||
import { AppDialog, EmptyState, StatusBadge, WorkspaceTools } from '../../components/ui'
|
||||
import QualityPolicySettings from '../generation-config/components/QualityPolicySettings.vue'
|
||||
import { useProjectContext } from '../projects/context'
|
||||
import { breakdownApi } from './api'
|
||||
import type { BreakdownAction, BreakdownInput, BreakdownModule, BreakdownPreview, ShotValidation } from './types'
|
||||
@@ -24,7 +25,9 @@ import BreakdownCandidatePanel from './components/BreakdownCandidatePanel.vue'
|
||||
import StoryboardQualityRepair from './components/StoryboardQualityRepair.vue'
|
||||
import BreakdownIssuesDialog from './components/BreakdownIssuesDialog.vue'
|
||||
import CandidateRepairs from './components/CandidateRepairs.vue'
|
||||
import ActionExceptionRepair from './components/ActionExceptionRepair.vue'
|
||||
import { useBreakdownQuality } from './useBreakdownQuality'
|
||||
import { useBreakdownStartPolicy } from './useBreakdownStartPolicy'
|
||||
import type { DiagnosisLocation } from './diagnosis'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
import { downloadText } from '../../lib/format'
|
||||
@@ -41,6 +44,8 @@ const tab = ref('character')
|
||||
const toolsOpen = ref(false)
|
||||
/** 问题查看、人工修订和阶段恢复共用独立窗口。 */
|
||||
const issuesOpen = ref(false)
|
||||
/** 动作例外真实写入期间锁定问题抽屉的关闭,普通查询不锁定。 */
|
||||
const exceptionSaving = ref(false)
|
||||
/** 从设置切换时等待关闭动画结束,避免两层弹窗同时显示。 */
|
||||
const pendingIssues = ref(false)
|
||||
/** 问题入口统一使用红色文字、图标和柔和底色,交互时保持错误语义。 */
|
||||
@@ -343,6 +348,42 @@ const canStart = computed(
|
||||
!error.value &&
|
||||
(!records.value.length || taskStopped.value)
|
||||
)
|
||||
/** 质量确认始终绑定本次真实预览输入,修改设置后立即撤销未完成启动。 */
|
||||
const startScope = computed(() => JSON.stringify(input.value))
|
||||
/** 首次及规则变化时确认,已确认的相同内容不重复弹出规则表单。 */
|
||||
const startPolicy = useBreakdownStartPolicy(projectId, startScope, canStart)
|
||||
/** 复用全局质量表单的完整校验和独立草稿。 */
|
||||
const qualityForm = ref<InstanceType<typeof QualityPolicySettings> | null>(null)
|
||||
/** 仅由用户明确勾选形成规则确认,不能把默认配置当作已确认。 */
|
||||
const rulesAcknowledged = ref(false)
|
||||
/** 每次真实模型启动仍需核对后台任务是否停止。 */
|
||||
const startAcknowledged = ref(false)
|
||||
/** 规则、目标或步骤变化后重新确认,不沿用旧勾选。 */
|
||||
watch([startPolicy.reviewOpen, startPolicy.editorKey, startScope], () => { rulesAcknowledged.value = false })
|
||||
watch(startPolicy.startOpen, () => { startAcknowledged.value = false })
|
||||
/** 关闭整个设置时中断只读确认,不能在关闭后打开迟到的弹窗。 */
|
||||
watch(toolsOpen, shown => { if (!shown) startPolicy.cancel() }, { flush: 'sync' })
|
||||
|
||||
/** 校验用户编辑的规则,成功后进入普通启动确认;此步骤不运行模型。 */
|
||||
async function confirmStartRules() {
|
||||
if (!rulesAcknowledged.value) return
|
||||
const draft = qualityForm.value?.validatedDraft()
|
||||
if (draft) await startPolicy.confirmRules(draft)
|
||||
}
|
||||
|
||||
/** 最终确认费用与任务范围后重新读取规则,再消费本次启动许可。 */
|
||||
async function confirmStart() {
|
||||
if (records.value.length > 0 && !startAcknowledged.value) return
|
||||
if (await startPolicy.verifyStart()) await run('start')
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通启动弹窗只读核对期间仍允许用户取消。
|
||||
* @param shown 弹窗目标显隐状态
|
||||
*/
|
||||
function updateStartOpen(shown: boolean) {
|
||||
if (!shown) startPolicy.cancel()
|
||||
}
|
||||
let previewController: AbortController | undefined
|
||||
let previewVersion = 0
|
||||
|
||||
@@ -395,7 +436,7 @@ async function loadPreview() {
|
||||
async function run(action: BreakdownAction) {
|
||||
if (project.value?.status !== 'completed' || operation.value.pending || error.value) return
|
||||
if (breakdownBusy.value || backgroundExecution.discovering.value || backgroundExecution.discoveryError.value) return
|
||||
if (action === 'start' && !canStart.value) return
|
||||
if (action === 'start' && (!canStart.value || !startPolicy.consumePermit())) return
|
||||
const labels: Record<BreakdownAction, string> = {
|
||||
start: '正在拆解剧本',
|
||||
retry: '正在重试失败抽取',
|
||||
@@ -477,12 +518,29 @@ const rules = {
|
||||
:pending="operation.pending"
|
||||
:pending-label="operation.label"
|
||||
v-model:open="toolsOpen"
|
||||
title="拆解设置"
|
||||
:title="startPolicy.reviewOpen.value ? '拆解前确认质量规则' : '拆解设置'"
|
||||
label="拆解设置"
|
||||
:busy="startPolicy.saving.value"
|
||||
fullscreen
|
||||
@closed="finishOpeningIssues"
|
||||
>
|
||||
<section class="panel workspace-panel breakdown-settings-panel">
|
||||
<!-- 以下是在同一全屏抽屉内核对真实质量规则的模块,不叠加第二个抽屉 -->
|
||||
<div v-if="startPolicy.reviewOpen.value && startPolicy.policy.value" class="breakdown-policy-review">
|
||||
<p class="text-sm leading-6 text-muted">请核对动作与物理规则,修改将在继续时保存。当前浏览器会记住确认,规则未变时不再重复提醒。</p>
|
||||
<QualityPolicySettings
|
||||
ref="qualityForm"
|
||||
:key="startPolicy.editorKey.value"
|
||||
:project-id="projectId"
|
||||
:initial-policy="startPolicy.policy.value"
|
||||
:disabled="!canStart || startPolicy.busy.value"
|
||||
/>
|
||||
<NCheckbox v-model:checked="rulesAcknowledged" :disabled="startPolicy.busy.value || !canStart" class="mt-5">
|
||||
我已核对本次拆解使用的质量规则
|
||||
</NCheckbox>
|
||||
<p v-if="startPolicy.error.value" role="alert" class="mt-4 text-sm text-danger">{{ startPolicy.error.value }}</p>
|
||||
</div>
|
||||
<!-- 以下是拆解分组设置模块,规则确认时保留已有预览和草稿 -->
|
||||
<section v-show="!startPolicy.reviewOpen.value" class="panel workspace-panel breakdown-settings-panel">
|
||||
<p
|
||||
v-if="backgroundExecution.discoveryError.value"
|
||||
class="mb-4 text-xs leading-6 text-danger"
|
||||
@@ -583,22 +641,16 @@ const rules = {
|
||||
<span class="mx-2 text-faint">/</span>
|
||||
<strong>{{ preview.estimatedTaskCount }}</strong> 个抽取任务
|
||||
</p>
|
||||
<ConfirmAction
|
||||
<NButton
|
||||
:loading="
|
||||
startPolicy.reading.value ||
|
||||
isOperationRunning(operation, '正在拆解剧本') ||
|
||||
backgroundExecution.active.value
|
||||
"
|
||||
:label="candidateOnly ? '生成拆解候选' : '开始拆解'"
|
||||
:description="
|
||||
candidateOnly
|
||||
? '将按当前分组调用模型生成主体、形态与分镜候选,可能产生模型费用。现有正式数据会保留,候选需经独立确认后才提交。'
|
||||
: '将按当前预览配置启动完整的 剧本拆解流程。抽取结束后仍需完成主体整理、分镜生成与入库。'
|
||||
"
|
||||
:acknowledgement="records.length > 0"
|
||||
primary
|
||||
:disabled="!canStart"
|
||||
@confirm="run('start')"
|
||||
/>
|
||||
type="primary"
|
||||
:disabled="!canStart || startPolicy.busy.value"
|
||||
@click="startPolicy.prepare"
|
||||
><template #icon><ShieldCheck :size="16" aria-hidden="true" /></template>{{ candidateOnly ? '生成拆解候选' : '开始拆解' }}</NButton>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<div v-for="group in preview.groups" :key="group.groupId" class="group-chip">
|
||||
@@ -607,6 +659,7 @@ const rules = {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="startPolicy.error.value && !startPolicy.startOpen.value" role="alert" class="mt-4 text-sm text-danger">{{ startPolicy.error.value }}</p>
|
||||
<p v-if="project.status === 'generating'" class="mt-4 text-xs text-danger">
|
||||
剧本仍在生成,暂不允许启动拆解,避免读取到不完整的剧集。
|
||||
</p>
|
||||
@@ -618,6 +671,7 @@ const rules = {
|
||||
</p>
|
||||
</section>
|
||||
<BreakdownCandidatePanel
|
||||
v-show="!startPolicy.reviewOpen.value"
|
||||
:project-id="projectId"
|
||||
:state="qualityObservation.source.value.state || undefined"
|
||||
:quality="quality"
|
||||
@@ -626,7 +680,7 @@ const rules = {
|
||||
@refresh="refreshCandidate"
|
||||
/>
|
||||
<!-- 以下是明确标记的历史执行回执,旧任务结论不表示当前候选质量 -->
|
||||
<component :is="executionHistorical ? NCollapse : 'div'" v-if="backgroundExecution.executionId.value" :class="{ 'breakdown-execution-history': executionHistorical }">
|
||||
<component :is="executionHistorical ? NCollapse : 'div'" v-if="backgroundExecution.executionId.value" v-show="!startPolicy.reviewOpen.value" :class="{ 'breakdown-execution-history': executionHistorical }">
|
||||
<component :is="executionHistorical ? NCollapseItem : 'div'" :name="executionHistorical ? 'history' : undefined" :title="executionHistorical ? '历史拆解执行记录(不代表当前质量)' : undefined">
|
||||
<WorkflowExecutionPanel
|
||||
v-if="backgroundExecution.executionId.value"
|
||||
@@ -641,14 +695,34 @@ const rules = {
|
||||
/>
|
||||
</component>
|
||||
</component>
|
||||
<!-- 以下是固定的规则确认底栏,返回不记录确认,继续不会直接调用模型 -->
|
||||
<template v-if="startPolicy.reviewOpen.value" #footer>
|
||||
<NButton :disabled="startPolicy.saving.value" @click="startPolicy.cancel">取消</NButton>
|
||||
<NButton type="primary" :loading="startPolicy.busy.value" :disabled="!rulesAcknowledged || !qualityForm?.canSave || startPolicy.busy.value || !canStart" @click="confirmStartRules"><template #icon><ShieldCheck :size="16" aria-hidden="true" /></template>确认规则并继续</NButton>
|
||||
</template>
|
||||
</WorkspaceTools>
|
||||
<!-- 以下是每次真实模型调用前的费用与任务确认,规则未变时直接进入此步骤 -->
|
||||
<AppDialog
|
||||
:open="startPolicy.startOpen.value"
|
||||
:title="candidateOnly ? '生成拆解候选' : '开始拆解'"
|
||||
:description="candidateOnly ? '将按当前分组调用模型生成主体、形态与分镜候选,可能产生模型费用。现有正式数据会保留,候选需经独立确认后才提交。' : '将按当前预览启动完整拆解并调用模型,可能产生模型费用。抽取结束后仍需完成主体整理、分镜生成与入库。'"
|
||||
:busy="operation.pending"
|
||||
@update:open="updateStartOpen"
|
||||
>
|
||||
<NCheckbox v-if="records.length > 0" v-model:checked="startAcknowledged" :disabled="startPolicy.busy.value">我已确认后台任务停止,当前没有同项目的生成或拆解任务在运行。</NCheckbox>
|
||||
<p v-if="startPolicy.error.value" role="alert" class="mt-4 text-sm text-danger">{{ startPolicy.error.value }}</p>
|
||||
<template #footer>
|
||||
<NButton :disabled="operation.pending" @click="startPolicy.cancel">取消</NButton>
|
||||
<NButton type="primary" :loading="startPolicy.reading.value" :disabled="!canStart || startPolicy.busy.value || (records.length > 0 && !startAcknowledged)" @click="confirmStart"><template #icon><ShieldCheck :size="16" aria-hidden="true" /></template>确认{{ candidateOnly ? '生成拆解候选' : '开始拆解' }}</NButton>
|
||||
</template>
|
||||
</AppDialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<NScrollbar v-if="!project?.episodes.length" class="panel-scroll panel">
|
||||
<EmptyState
|
||||
title="还没有可拆解的剧集"
|
||||
description="先完成剧本创作。拆解会读取数据库中的正式剧集,不需要上传 checkpoint。"
|
||||
description="先完成剧本创作。拆解会使用已保存的正式剧集,无需重新上传。"
|
||||
/>
|
||||
</NScrollbar>
|
||||
<template v-else>
|
||||
@@ -799,6 +873,7 @@ const rules = {
|
||||
v-model:open="issuesOpen"
|
||||
:issues="storyboardIssues"
|
||||
:quality="quality"
|
||||
:busy="exceptionSaving"
|
||||
:workflow-error="currentWorkflowError"
|
||||
:locatable="!breakdownBusy && !!shots.length"
|
||||
@locate="locateIssue"
|
||||
@@ -816,6 +891,17 @@ const rules = {
|
||||
>
|
||||
任务状态或结果尚未确认,请先重新读取状态与结果。
|
||||
</p>
|
||||
<!-- 以下是从当前动作冲突带入角色和动作的例外入口,独立保存规则且保留旧例外 -->
|
||||
<ActionExceptionRepair
|
||||
v-if="issuesOpen && qualityObservation.source.value.state && quality.source !== 'history' && quality.actionBlocks.some(block => [...block.blockingCodes, ...block.warningCodes].includes('action_resource_conflict'))"
|
||||
:project-id="projectId"
|
||||
:checkpoint-id="latestCheckpoint?.checkpointId || ''"
|
||||
:state="qualityObservation.source.value.state"
|
||||
:quality="quality"
|
||||
:disabled="issueActionsDisabled"
|
||||
@busy="exceptionSaving = $event"
|
||||
@refresh="refreshCandidate"
|
||||
/>
|
||||
<CandidateRepairs
|
||||
v-if="issuesOpen && quality.isCandidate && snapshot"
|
||||
:project-id="projectId"
|
||||
@@ -840,21 +926,21 @@ const rules = {
|
||||
<ConfirmAction
|
||||
:loading="isOperationRunning(operation, '正在重试失败抽取')"
|
||||
label="重试失败抽取"
|
||||
description="只重试 character / scene / prop 抽取任务中的失败项。不能用于镜头阶段失败。"
|
||||
description="只重新提取失败的人物、场景或道具,不重做已完成内容。镜头问题请使用对应修复操作。"
|
||||
acknowledgement
|
||||
:disabled="issueActionsDisabled || !recovery.retry"
|
||||
@confirm="run('retry')"
|
||||
/><ConfirmAction
|
||||
:loading="isOperationRunning(operation, '正在补齐镜头')"
|
||||
label="补齐缺失镜头"
|
||||
description="复用已完成剧集的镜头,仅生成尚未完成的 Episode Shot,再进行校验与入库。"
|
||||
description="保留已经完成的镜头,只补齐缺失的镜头,然后检查并保存。"
|
||||
acknowledgement
|
||||
:disabled="issueActionsDisabled || !recovery.shots"
|
||||
@confirm="run('resume-shots')"
|
||||
/><ConfirmAction
|
||||
:loading="isOperationRunning(operation, '正在修复分镜绑定')"
|
||||
label="修复分镜绑定"
|
||||
description="复用已有镜头,修复 SubjectRef 与视觉 Form 绑定,再校验并保存。"
|
||||
description="保留已有镜头,补齐人物、场景、道具及其形态的对应关系,然后检查并保存。"
|
||||
acknowledgement
|
||||
:disabled="issueActionsDisabled || !recovery.storyboard"
|
||||
@confirm="run('resume-storyboard')"
|
||||
@@ -891,6 +977,10 @@ const rules = {
|
||||
.breakdown-settings-panel {
|
||||
container: breakdown-settings / inline-size;
|
||||
}
|
||||
/* 同一抽屉切换步骤时首个可见模块不继承隐藏设置区域的兄弟间距。 */
|
||||
.workspace-tools-body > .breakdown-policy-review + .breakdown-settings-panel {
|
||||
margin-top: 0;
|
||||
}
|
||||
/* 说明与表单留出 16px,避免移除来源标签后紧贴首个字段。 */
|
||||
.breakdown-settings-form {
|
||||
margin-top: 16px;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import type { ActionResource } from '../projects/types'
|
||||
import { actionResourceOptions } from '../projects/quality-policy'
|
||||
import type { BreakdownState } from './types'
|
||||
import type { BreakdownQuality } from './quality'
|
||||
import type { CandidateShotLocation } from './candidate.types'
|
||||
|
||||
/** 从当前镜头真实占用证据带入的例外目标,不将自由文本当作角色或动作编号。 */
|
||||
export interface ActionExceptionTarget extends CandidateShotLocation {
|
||||
/** 镜头、阶段、主体与部位组成的稳定标识。 */
|
||||
key: string
|
||||
/** 实际冲突发生的阶段。 */
|
||||
phaseNo: number
|
||||
/** 当前镜头标题。 */
|
||||
shotTitle: string
|
||||
/** 后端镜头已有的主体引用。 */
|
||||
ownerRef: string
|
||||
/** 已有主体名称,缺失时直接显示真实编号。 */
|
||||
ownerName: string
|
||||
/** 同阶段重复占用的资源。 */
|
||||
resource: ActionResource
|
||||
/** 实际冲突动作的可读描述。 */
|
||||
actions: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅在当前审核明确指出资源冲突时,从同版本镜头证据提取角色与冲突动作。
|
||||
* @param state 当前版本的完整镜头与主体
|
||||
* @param quality 与当前检查点一致的审核
|
||||
* @returns 可添加精确例外的真实目标;历史、缺失或无效证据不产生目标
|
||||
*/
|
||||
export function actionExceptionTargets(state: BreakdownState, quality: BreakdownQuality): ActionExceptionTarget[] {
|
||||
if (!['candidate', 'formal'].includes(quality.source) || quality.loading || quality.needsRefresh || quality.error) return []
|
||||
const targets = new Map<string, ActionExceptionTarget>()
|
||||
for (const block of quality.actionBlocks) {
|
||||
if (![...block.blockingCodes, ...block.warningCodes].includes('action_resource_conflict')) continue
|
||||
const shot = state.storyboardEpisodeShots?.find(episode => episode.episodeNo === block.episodeNo)
|
||||
?.beatShots.find(beat => beat.beatNo === block.beatNo)?.shots.find(item => item.shotNo === block.shotNo)
|
||||
if (!shot?.requiredActions?.length || !shot.durationPlanning) continue
|
||||
for (const [index, phase] of shot.durationPlanning.phases.entries()) {
|
||||
// 与后端审计一致:只接受本阶段、已存在动作及镜头主体的明确占用证据。
|
||||
const resources = (phase.resourceOccupancy ?? []).filter(item =>
|
||||
shot.subjectRefs.includes(item.ownerRef) && phase.actionIds?.includes(item.actionId) &&
|
||||
shot.requiredActions!.some(action => action.id === item.actionId) &&
|
||||
actionResourceOptions.some(option => option.value === item.resource))
|
||||
for (const [leftIndex, left] of resources.entries()) {
|
||||
for (const right of resources.slice(leftIndex + 1)) {
|
||||
if (left.ownerRef !== right.ownerRef || left.resource !== right.resource || left.actionId === right.actionId) continue
|
||||
if (left.shareable && right.shareable && !['support', 'move'].includes(left.usage) && !['support', 'move'].includes(right.usage)) continue
|
||||
const key = `${block.episodeNo}/${block.beatNo}/${block.shotNo}/${index + 1}/${left.ownerRef}/${left.resource}`
|
||||
const target = targets.get(key) ?? {
|
||||
key, episodeNo: block.episodeNo, beatNo: block.beatNo, shotNo: block.shotNo,
|
||||
phaseNo: index + 1, shotTitle: shot.title, ownerRef: left.ownerRef, resource: left.resource,
|
||||
ownerName: state.subjectCandidates?.find(subject => subject.ref === left.ownerRef)?.name || left.ownerRef,
|
||||
actions: []
|
||||
}
|
||||
for (const actionId of [left.actionId, right.actionId]) {
|
||||
const description = shot.requiredActions.find(action => action.id === actionId)!.description
|
||||
if (!target.actions.includes(description)) target.actions.push(description)
|
||||
}
|
||||
targets.set(key, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return [...targets.values()]
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onScopeDispose, ref, watch } from 'vue'
|
||||
import { NButton, NFormItem, NInput } from 'naive-ui'
|
||||
import { Plus } from '@lucide/vue'
|
||||
import WorkspaceSectionHeading from '../../../components/ui/WorkspaceSectionHeading.vue'
|
||||
import QualityPolicyExceptions from '../../generation-config/components/QualityPolicyExceptions.vue'
|
||||
import { projectsApi } from '../../projects/api'
|
||||
import { actionResourceOptions, policyDraft } from '../../projects/quality-policy'
|
||||
import { invalidateQualityPolicyConfirmation, qualityPolicySignature } from '../../projects/quality-policy-confirmation'
|
||||
import type { ProjectQualityPolicyResult } from '../../projects/types'
|
||||
import { getOperation, runOperation } from '../../workflows/operations'
|
||||
import { actionExceptionTargets, type ActionExceptionTarget } from '../action-exceptions'
|
||||
import type { BreakdownState } from '../types'
|
||||
import type { BreakdownQuality } from '../quality'
|
||||
import { errorMessage } from '../../../lib/http'
|
||||
|
||||
/** 例外仅从当前版本的具体动作问题添加,不修改镜头、不调用模型。 */
|
||||
const props = defineProps<{
|
||||
/** 当前正式项目。 */
|
||||
projectId: string
|
||||
/** 当前最新检查点,切换后撤销旧问题草稿。 */
|
||||
checkpointId: string
|
||||
/** 同一检查点中的完整主体与镜头。 */
|
||||
state: BreakdownState
|
||||
/** 当前审核,不能使用历史通过或历史问题。 */
|
||||
quality: BreakdownQuality
|
||||
/** 项目活动任务、读错或未确认状态下禁止写入。 */
|
||||
disabled: boolean
|
||||
}>()
|
||||
/** 真实写入期间锁定父抽屉,保存后重新读取服务端审核。 */
|
||||
const emit = defineEmits<{ busy: [value: boolean]; refresh: [] }>()
|
||||
/** 当前后端保存的规则,失败时不使用默认值。 */
|
||||
const receipt = ref<ProjectQualityPolicyResult | null>(null)
|
||||
/** 只读加载允许关闭,不把查询当作不可取消提交。 */
|
||||
const loading = ref(false)
|
||||
/** 最终保存前的规则合并查询,阻止重复点击。 */
|
||||
const checking = ref(false)
|
||||
/** 真正写入规则的状态。 */
|
||||
const writing = ref(false)
|
||||
/** 用户当前选中的完整问题目标。 */
|
||||
const selected = ref<ActionExceptionTarget | null>(null)
|
||||
/** 用户明确填写的允许原因,不自动代填确认依据。 */
|
||||
const reason = ref('')
|
||||
/** 仅在用户点击保存时展示的字段校验。 */
|
||||
const issue = ref('')
|
||||
/** 实际接口错误,失败后保留草稿。 */
|
||||
const error = ref('')
|
||||
/** 保存成功仅说明规则已保存,不暗示质量已经通过。 */
|
||||
const notice = ref('')
|
||||
/** 项目级写操作锁。 */
|
||||
const operation = computed(() => getOperation(props.projectId))
|
||||
/** 当前审核与原始数据必须属于同一项目和最新检查点。 */
|
||||
const current = computed(() => !!props.checkpointId && props.quality.checkpointId === props.checkpointId &&
|
||||
(!props.state.projectId || props.state.projectId === props.projectId) && ['candidate', 'formal'].includes(props.quality.source))
|
||||
/** 只从真实审核和阶段证据生成目标。 */
|
||||
const targets = computed(() => current.value ? actionExceptionTargets(props.state, props.quality) : [])
|
||||
/** 已有例外原样展示,保存新项不会删除或替换它们。 */
|
||||
const exceptions = computed(() => receipt.value?.policy.actionExceptions ?? [])
|
||||
/** 用户可以提交的时机,所有外部活动锁都需要满足。 */
|
||||
const writable = computed(() => current.value && !!receipt.value && !props.disabled && !operation.value.pending && !loading.value && !checking.value && !writing.value)
|
||||
/** 失效代次与可取消的只读请求。 */
|
||||
let generation = 0
|
||||
/** 当前规则查询的取消控制器。 */
|
||||
let controller: AbortController | undefined
|
||||
|
||||
/**
|
||||
* 使用真实项目规则,验证项目及完整性后创建独立副本。
|
||||
* @param id 目标项目
|
||||
* @param signal 只读请求的取消信号
|
||||
* @returns 已验证的完整规则
|
||||
*/
|
||||
async function read(id: string, signal: AbortSignal): Promise<ProjectQualityPolicyResult> {
|
||||
const result = await projectsApi.qualityPolicy(id, signal)
|
||||
if (result.projectId !== id) throw new Error('规则所属项目不一致,请重新读取。')
|
||||
qualityPolicySignature(result.policy)
|
||||
return { projectId: id, policy: policyDraft(result.policy) }
|
||||
}
|
||||
|
||||
/** 按需读取已有规则;无真实拆解结果时不创建例外。 */
|
||||
async function load() {
|
||||
if (loading.value || !current.value) return
|
||||
const version = ++generation
|
||||
const id = props.projectId
|
||||
controller?.abort()
|
||||
controller = new AbortController()
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await read(id, controller.signal)
|
||||
if (version === generation) receipt.value = result
|
||||
} catch (cause) { if (version === generation) error.value = errorMessage(cause) }
|
||||
finally { if (version === generation) loading.value = false }
|
||||
}
|
||||
|
||||
/**
|
||||
* 同一角色及部位已有例外时禁止重复添加,适用范围遵循后端项目级契约。
|
||||
* @param target 真实动作冲突目标
|
||||
* @returns 是否已经保存对应例外
|
||||
*/
|
||||
function exists(target: ActionExceptionTarget): boolean {
|
||||
return exceptions.value.some(item => item.code === 'action_resource_conflict' && item.ownerRef === target.ownerRef && item.resource === target.resource)
|
||||
}
|
||||
|
||||
/**
|
||||
* 带入只读角色、部位及动作,用户只填写允许原因。
|
||||
* @param target 被用户选中的真实问题
|
||||
*/
|
||||
function select(target: ActionExceptionTarget) {
|
||||
if (!writable.value || exists(target)) return
|
||||
selected.value = target
|
||||
reason.value = ''
|
||||
issue.value = ''
|
||||
error.value = ''
|
||||
notice.value = ''
|
||||
}
|
||||
|
||||
/** 取消当前例外草稿,同时撤销尚未完成的只读请求。 */
|
||||
function cancel() {
|
||||
if (writing.value) return
|
||||
generation++
|
||||
controller?.abort()
|
||||
checking.value = false
|
||||
selected.value = null
|
||||
reason.value = ''
|
||||
issue.value = ''
|
||||
}
|
||||
|
||||
/** 最终提交前重读并追加到最新完整规则,绝不覆盖已有例外或伪造审核通过。 */
|
||||
async function save() {
|
||||
if (!writable.value || !selected.value) return
|
||||
issue.value = reason.value.trim() ? '' : '请填写允许原因,说明剧本为什么允许这样做。'
|
||||
if (issue.value) return
|
||||
const target = selected.value
|
||||
const targetSignature = JSON.stringify(target)
|
||||
const id = props.projectId
|
||||
const version = ++generation
|
||||
controller?.abort()
|
||||
controller = new AbortController()
|
||||
checking.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const latest = await read(id, controller.signal)
|
||||
if (version !== generation || props.disabled || operation.value.pending || !current.value ||
|
||||
!targets.value.some(item => JSON.stringify(item) === targetSignature)) return
|
||||
receipt.value = latest
|
||||
if (exists(target)) { notice.value = '这个角色的对应部位已有例外,已保留现有设置。'; selected.value = null; return }
|
||||
if (exceptions.value.length >= 30) throw new Error('动作例外最多 30 项,当前不能继续添加。')
|
||||
const input = policyDraft(latest.policy)
|
||||
input.actionExceptions = [...(input.actionExceptions ?? []), {
|
||||
code: 'action_resource_conflict', ownerRef: target.ownerRef, resource: target.resource, reason: reason.value.trim()
|
||||
}]
|
||||
const signature = qualityPolicySignature(input)
|
||||
writing.value = true
|
||||
const success = await runOperation(id, '正在保存动作例外', async () => {
|
||||
const result = await projectsApi.saveQualityPolicy(id, input)
|
||||
invalidateQualityPolicyConfirmation(id)
|
||||
if (result.projectId !== id || qualityPolicySignature(result.policy) !== signature)
|
||||
throw new Error('规则保存回执与提交内容不一致,请重新读取确认。')
|
||||
if (version === generation) receipt.value = { projectId: id, policy: policyDraft(result.policy) }
|
||||
}, { type: 'info', content: '动作例外已保存,当前分镜仍需审核,不会自动放行提交。' })
|
||||
if (version !== generation) return
|
||||
if (success) {
|
||||
selected.value = null
|
||||
reason.value = ''
|
||||
notice.value = '动作例外已保存。当前分镜仍需审核,不会自动标记通过或修改正式结果。'
|
||||
emit('refresh')
|
||||
} else error.value = operation.value.error
|
||||
} catch (cause) { if (version === generation) error.value = errorMessage(cause) }
|
||||
finally { if (version === generation) { checking.value = false; writing.value = false } }
|
||||
}
|
||||
|
||||
/** 修改原因时清除旧校验,打开空白草稿不提前报错。 */
|
||||
watch(reason, () => { issue.value = '' })
|
||||
/** 当前问题的动作证据变化后撤销旧草稿,不能把旧动作的确认套到新动作。 */
|
||||
watch(targets, items => {
|
||||
if (selected.value && !items.some(item => JSON.stringify(item) === JSON.stringify(selected.value))) cancel()
|
||||
}, { flush: 'sync' })
|
||||
/** 切换版本后清空旧草稿和读取,迟到响应不得回填或提交。 */
|
||||
watch(() => [props.projectId, props.checkpointId], () => {
|
||||
generation++
|
||||
controller?.abort()
|
||||
receipt.value = null
|
||||
selected.value = null
|
||||
reason.value = ''
|
||||
issue.value = ''
|
||||
notice.value = ''
|
||||
error.value = ''
|
||||
loading.value = false
|
||||
checking.value = false
|
||||
writing.value = false
|
||||
void load()
|
||||
}, { immediate: true, flush: 'sync' })
|
||||
/** 父抽屉只在真实写入期间锁定,普通读取仍可关闭。 */
|
||||
watch(writing, value => emit('busy', value), { flush: 'sync' })
|
||||
onScopeDispose(() => { generation++; controller?.abort(); emit('busy', false) })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是拆解后从具体冲突添加动作例外的模块,角色和动作均不可自由输入 -->
|
||||
<section class="workspace-panel space-y-4" aria-label="动作例外修订">
|
||||
<WorkspaceSectionHeading title="动作例外" description="只为剧本明确允许的特殊动作添加例外。角色、部位和动作从当前问题自动带入,你只需填写允许原因。" />
|
||||
<p v-if="loading" role="status" class="text-xs text-muted">正在读取已有动作例外…</p>
|
||||
<div v-if="error" role="alert" class="space-y-2 text-sm text-danger"><p>{{ error }}</p><NButton v-if="!receipt" :disabled="loading" @click="load">重新读取规则</NButton></div>
|
||||
<QualityPolicyExceptions :exceptions="exceptions" />
|
||||
<p v-if="!targets.length && !loading" class="text-xs leading-6 text-muted">当前没有能准确带入角色与动作的冲突。缺少动作证据或其他结构错误时,请先使用人工修订。</p>
|
||||
<article v-for="target in targets" :key="target.key" class="space-y-3" :data-exception-target="target.key">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<p class="text-sm">第 {{ target.episodeNo }} 集 · 节拍 {{ target.beatNo }} · 镜头 {{ target.shotNo }} · 阶段 {{ target.phaseNo }}</p>
|
||||
<NButton v-if="selected?.key !== target.key" :disabled="!writable || exists(target)" @click="select(target)"><template #icon><Plus :size="15" aria-hidden="true" /></template>{{ exists(target) ? '已有例外' : '添加例外' }}</NButton>
|
||||
</div>
|
||||
<p class="text-sm">{{ target.ownerName }}({{ target.ownerRef }}) · {{ actionResourceOptions.find(option => option.value === target.resource)?.label }}</p>
|
||||
<ul class="space-y-1 pl-5 text-xs leading-6 text-muted list-disc"><li v-for="action in target.actions" :key="action">{{ action }}</li></ul>
|
||||
<!-- 以下是只填写原因的例外草稿,后端实际范围是同一角色的对应部位 -->
|
||||
<div v-if="selected?.key === target.key" class="space-y-3">
|
||||
<p class="text-xs leading-6 text-muted">此例外按项目保存,同一角色或物品在其他镜头中的同类占用冲突也会受影响;其他错误仍会检查。</p>
|
||||
<NFormItem label="允许原因"><NInput v-model:value="reason" type="textarea" aria-label="动作例外允许原因" placeholder="填写剧本中明确允许这样做的设定" :autosize="{ minRows: 2, maxRows: 6 }" :disabled="disabled || checking || writing" /></NFormItem>
|
||||
<p v-if="issue" role="alert" class="text-xs text-danger">{{ issue }}</p>
|
||||
<div class="flex flex-wrap justify-end gap-2"><NButton :disabled="writing" @click="cancel">取消</NButton><NButton type="primary" :disabled="!writable" :loading="checking || writing" @click="save"><template #icon><Plus :size="15" aria-hidden="true" /></template>保存动作例外</NButton></div>
|
||||
</div>
|
||||
</article>
|
||||
<p v-if="notice" role="status" class="text-xs leading-6 text-muted">{{ notice }}</p>
|
||||
</section>
|
||||
</template>
|
||||
@@ -143,7 +143,7 @@ async function commit() {
|
||||
<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="将替换正式主体、形态与分镜。提交时后端仍会在事务内重新检查剧本版本和下游资产。">
|
||||
<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>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { userFacingText } from '../../../lib/user-facing-text'
|
||||
import { qualityIssueLabel } from '../repair'
|
||||
import { computed, ref } from 'vue'
|
||||
import { NButton, NCollapse, NCollapseItem } from 'naive-ui'
|
||||
import { AppDrawer } from '../../../components/ui'
|
||||
@@ -25,6 +27,8 @@ const props = defineProps<{
|
||||
locatable: boolean
|
||||
/** 当前版本统一审核,历史问题与当前问题分开。 */
|
||||
quality?: BreakdownQuality
|
||||
/** 真实写入例外期间禁止关闭和定位,普通读取不锁定。 */
|
||||
busy?: boolean
|
||||
}>()
|
||||
/** 独立问题抽屉显隐。 */
|
||||
const open = defineModel<boolean>('open', { default: false })
|
||||
@@ -56,7 +60,7 @@ const pendingLocation = ref<ShotValidation['issues'][number] | null>(null)
|
||||
* @param issue 后端提供的问题位置
|
||||
*/
|
||||
function locate(issue: ShotValidation['issues'][number]) {
|
||||
if (!props.locatable) return
|
||||
if (!props.locatable || props.busy) return
|
||||
pendingLocation.value = { ...issue }
|
||||
open.value = false
|
||||
}
|
||||
@@ -72,7 +76,7 @@ function finish() {
|
||||
|
||||
<template>
|
||||
<!-- 以下是全屏展示的拆解执行错误与分镜校验问题模块 -->
|
||||
<AppDrawer v-model:open="open" title="拆解问题" class="breakdown-issues-drawer" @closed="finish">
|
||||
<AppDrawer v-model:open="open" title="拆解问题" :busy="busy" class="breakdown-issues-drawer" @closed="finish">
|
||||
<template #description
|
||||
><span v-if="quality">{{ quality.isCandidate ? '当前候选' : quality.source === 'history' ? '历史结果(当前质量未确认)' : '当前正式结果' }} · 结构 {{ quality.structuralCount }} 项 · 动作 {{ quality.actionBlocks.length }} 镜</span
|
||||
><span v-else-if="count">{{ count }} 项校验问题 · {{ groups.length }} 个位置</span
|
||||
@@ -87,18 +91,18 @@ function finish() {
|
||||
<h3 class="text-sm font-medium">{{ group.label }} · {{ group.items.length }}</h3>
|
||||
<article v-for="item in group.items" :key="item.key" class="workspace-panel problem-surface space-y-3 break-words" :data-problem-type="item.type">
|
||||
<div v-if="item.location" class="flex flex-wrap items-center justify-between gap-3"><p class="text-sm">第 {{ item.location.episodeNo }} 集<span v-if="item.location.beatNo"> · 节拍 {{ item.location.beatNo }}</span><span v-if="item.location.shotNo"> · 镜头 {{ item.location.shotNo }}</span><span class="ml-3 text-xs text-muted">待处理</span></p><NButton v-if="locatable" text size="small" @click="locate(item.location)">{{ item.location.beatNo ? '定位分镜' : '查看本集' }}</NButton></div>
|
||||
<p class="text-sm leading-6">{{ item.message }}</p><p v-if="item.codes.length" class="text-xs text-muted break-all">阻断代码:{{ item.codes.join('、') }}</p>
|
||||
<p class="text-sm leading-6">{{ userFacingText(item.message) }}</p><p v-if="item.codes.length" class="text-xs text-muted break-all">需要处理:{{ item.codes.map(qualityIssueLabel).join('、') }}</p>
|
||||
</article>
|
||||
</section>
|
||||
<p v-if="!quality.issueCount && !workflowError" class="text-sm text-muted">当前版本没有待处理的质量问题。</p>
|
||||
<!-- 以下是使用 Naive 折叠组件的历史记录,默认收起且不计入当前问题 -->
|
||||
<NCollapse v-if="quality.historyIssues.length" class="text-xs text-muted" data-history-issues><NCollapseItem name="history" :title="`历史审核记录 · ${quality.historyIssues.length} 项(不计入当前问题)`"><p v-for="(item, index) in quality.historyIssues" :key="index" class="mt-3 break-words">第 {{ item.episodeNo }} 集 · {{ item.message }}</p></NCollapseItem></NCollapse>
|
||||
<NCollapse v-if="quality.historyIssues.length" class="text-xs text-muted" data-history-issues><NCollapseItem name="history" :title="`历史审核记录 · ${quality.historyIssues.length} 项(不计入当前问题)`"><p v-for="(item, index) in quality.historyIssues" :key="index" class="mt-3 break-words">第 {{ item.episodeNo }} 集 · {{ userFacingText(item.message) }}</p></NCollapseItem></NCollapse>
|
||||
</template>
|
||||
</div>
|
||||
<div class="space-y-4">
|
||||
<section v-if="workflowError" class="workspace-panel problem-surface space-y-3" aria-label="执行异常">
|
||||
<h3 class="text-sm font-medium">执行异常</h3>
|
||||
<p class="whitespace-pre-wrap break-words text-sm leading-6">{{ workflowError }}</p>
|
||||
<p class="whitespace-pre-wrap break-words text-sm leading-6">{{ userFacingText(workflowError) }}</p>
|
||||
</section>
|
||||
<article
|
||||
v-for="group in quality ? [] : groups"
|
||||
@@ -116,7 +120,7 @@ function finish() {
|
||||
}}</NButton>
|
||||
</div>
|
||||
<p v-for="message in group.messages" :key="message" class="break-words text-sm leading-6">
|
||||
{{ message }}
|
||||
{{ userFacingText(message) }}
|
||||
</p>
|
||||
</article>
|
||||
<p v-if="!quality && !groups.length && !workflowError" class="py-5 text-sm text-muted">
|
||||
@@ -126,7 +130,7 @@ function finish() {
|
||||
<!-- 以下是独立的问题修订与阶段恢复模块,不承载生成配置或候选提交 -->
|
||||
<div v-if="$slots.repair" class="mt-6 space-y-5" aria-label="问题修订与恢复"><slot name="repair" /></div>
|
||||
<!-- 以下是灰底关闭操作,绿色主按钮仅用于提交或执行任务 -->
|
||||
<template #footer><NButton type="default" @click="open = false">关闭</NButton></template>
|
||||
<template #footer><NButton type="default" :disabled="busy" @click="open = false">关闭</NButton></template>
|
||||
</AppDrawer>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ async function repairActions() {
|
||||
<article v-for="draft in actionDrafts" :key="draft.key" class="candidate-action-draft space-y-3 p-4" :data-action-id="draft.actionId">
|
||||
<NCheckbox v-model:checked="draft.selected" :disabled="!writable">第 {{ draft.episodeNo }} 集 · 节拍 {{ draft.beatNo }} · 镜头 {{ draft.shotNo }} · {{ draft.title }} · {{ draft.actionId }}</NCheckbox>
|
||||
<p class="text-xs leading-6 text-muted">原始状态:{{ draft.original }}</p>
|
||||
<p v-if="draft.parallel" class="text-xs text-danger">该动作处于并行阶段,后端可能拒绝覆盖,需核对同阶段其他动作。</p>
|
||||
<p v-if="draft.parallel" class="text-xs text-danger">这个动作与其他动作同时发生。请先核对它们的关系,避免修改后互相冲突。</p>
|
||||
<NInput v-model:value="draft.description" type="textarea" :disabled="!writable || !draft.selected" :input-props="{ 'aria-label': `动作 ${draft.key} 修订描述` }" placeholder="请人工填写动作如何发生,不能只把结果状态改名" :autosize="{ minRows: 3, maxRows: 8 }" />
|
||||
</article>
|
||||
<p v-if="repairs.length" class="text-xs leading-6 text-muted break-words" aria-label="批量修复摘要">{{ actionSummary }}</p>
|
||||
|
||||
@@ -222,7 +222,7 @@ onScopeDispose(() => {
|
||||
<AppDialog
|
||||
v-model:open="open"
|
||||
:title="targetLabel"
|
||||
description="修订完整动作与阶段证据;保存前后端会重新审核当前镜头。此操作不调用模型。"
|
||||
description="调整镜头中的动作和先后顺序,保存时会重新检查这个镜头。此操作不调用模型。"
|
||||
:busy="operation.pending"
|
||||
wide
|
||||
>
|
||||
@@ -245,7 +245,7 @@ onScopeDispose(() => {
|
||||
><ConfirmAction
|
||||
:key="draftVersion"
|
||||
label="保存人工修订"
|
||||
description="将保存当前完整动作与阶段证据。若版本变化或质量审核仍不通过,后端会拒绝保存。保存成功后仍需恢复拆解与正式提交。"
|
||||
description="保存当前镜头的动作安排。如果内容版本已变化或检查仍未通过,需要先处理问题。保存后还需继续拆解并提交正式结果。"
|
||||
:disabled="disabled || operation.pending || !current || !!issue"
|
||||
@confirm="save"
|
||||
/></template>
|
||||
|
||||
@@ -27,7 +27,7 @@ export function qualityIssueLabel(code: string): string {
|
||||
hand_action_not_in_phase: '手部动作不属于当前阶段',
|
||||
invalid_hand_character_ref: '手部主体引用无效'
|
||||
}
|
||||
return labels[code] ?? `待复核问题(${code})`
|
||||
return labels[code] ?? '其他待复核问题'
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
import { computed, onScopeDispose, ref, watch, type Ref } from 'vue'
|
||||
import { projectsApi } from '../projects/api'
|
||||
import { policyDraft } from '../projects/quality-policy'
|
||||
import type { ProjectQualityPolicy, ProjectQualityPolicyResult } from '../projects/types'
|
||||
import {
|
||||
qualityPolicyConfirmationEpoch, qualityPolicySignature,
|
||||
readQualityPolicyConfirmation, rememberQualityPolicyConfirmation
|
||||
} from '../projects/quality-policy-confirmation'
|
||||
import { errorMessage } from '../../lib/http'
|
||||
import { showActionFeedback, useActionMessage } from '../../components/ui/useActionMessage'
|
||||
|
||||
/** 一次性启动许可只在前端内使用,不作为后端权限或提交参数。 */
|
||||
interface StartPermit {
|
||||
/** 当前项目。 */
|
||||
projectId: string
|
||||
/** 当前拆解输入。 */
|
||||
scope: string
|
||||
/** 本次重新读取并确认的质量规则。 */
|
||||
signature: string
|
||||
}
|
||||
|
||||
/** 存储受限时仅在当前页面有效的确认,规则变更后通过代次撤销。 */
|
||||
interface SessionConfirmation extends StartPermit {
|
||||
/** 当前项目在本页面的规则失效代次。 */
|
||||
epoch: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取真实规则并验证所属项目和内容完整性。
|
||||
* @param id 请求项目
|
||||
* @param signal 只读请求取消信号
|
||||
* @returns 已验证的真实规则回执
|
||||
*/
|
||||
async function read(id: string, signal: AbortSignal): Promise<ProjectQualityPolicyResult> {
|
||||
const result = await projectsApi.qualityPolicy(id, signal)
|
||||
if (result.projectId !== id) throw new Error('质量规则所属项目不一致,请重新读取。')
|
||||
qualityPolicySignature(result.policy)
|
||||
return { projectId: id, policy: policyDraft(result.policy) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动拆解前读取并确认规则,内容未变时跳过规则弹窗,保留每次模型启动确认。
|
||||
* @param projectId 当前项目
|
||||
* @param scope 当前预览对应的拆解配置
|
||||
* @param allowed 当前是否允许启动
|
||||
* @returns 规则确认、普通启动确认及一次性启动许可
|
||||
*/
|
||||
export function useBreakdownStartPolicy(projectId: Ref<string>, scope: Ref<string>, allowed: Ref<boolean>) {
|
||||
/** 已读取的服务端规则,编辑器不能自行使用本地默认值代替。 */
|
||||
const policy = ref<ProjectQualityPolicyResult | null>(null)
|
||||
/** 在现有拆解抽屉中切换到规则确认,不叠加第二个全屏抽屉。 */
|
||||
const reviewOpen = ref(false)
|
||||
/** 普通模型启动确认,规则已确认时直接进入此步骤。 */
|
||||
const startOpen = ref(false)
|
||||
/** 只读请求加载状态,允许用户取消。 */
|
||||
const reading = ref(false)
|
||||
/** 真实保存期间禁止重复操作和意外关闭。 */
|
||||
const saving = ref(false)
|
||||
/** 当前按钮请求是否正在执行。 */
|
||||
const busy = computed(() => reading.value || saving.value)
|
||||
/** 用户可重试的错误反馈。 */
|
||||
const error = ref('')
|
||||
/** 编辑器只在服务端版本变化时重建,失败保留草稿。 */
|
||||
const editorKey = computed(() => policy.value ? `${policy.value.projectId}:${qualityPolicySignature(policy.value.policy)}` : '')
|
||||
/** 应用统一消息层。 */
|
||||
const message = useActionMessage()
|
||||
/** 取消项目或配置变更前的旧请求。 */
|
||||
let controller: AbortController | undefined
|
||||
/** 旧响应隔离代次。 */
|
||||
let generation = 0
|
||||
/** 普通启动弹窗对应的规则内容。 */
|
||||
let preparedSignature = ''
|
||||
/** 存储不可写时,仅本次页面会话使用的确认。 */
|
||||
let fallback: SessionConfirmation | null = null
|
||||
/** 成功重读后才能消费的一次性启动许可。 */
|
||||
let permit: StartPermit | null = null
|
||||
|
||||
/**
|
||||
* 判断规则内容是否经过本浏览器明确确认。
|
||||
* @param id 当前项目
|
||||
* @param signature 最新服务端内容
|
||||
* @returns 是否允许跳过规则确认界面
|
||||
*/
|
||||
function confirmed(id: string, signature: string): boolean {
|
||||
return readQualityPolicyConfirmation(id) === signature ||
|
||||
(fallback?.projectId === id && fallback.signature === signature &&
|
||||
fallback.epoch === qualityPolicyConfirmationEpoch(id))
|
||||
}
|
||||
|
||||
/** 撤销未完成请求和启动许可,不撤销用户已经完成的规则确认。 */
|
||||
function reset() {
|
||||
generation++
|
||||
controller?.abort()
|
||||
reading.value = false
|
||||
saving.value = false
|
||||
reviewOpen.value = false
|
||||
startOpen.value = false
|
||||
policy.value = null
|
||||
preparedSignature = ''
|
||||
permit = null
|
||||
error.value = ''
|
||||
}
|
||||
|
||||
/** 用户点击生成时读取规则,不在页面进入或定时器中请求。 */
|
||||
async function prepare() {
|
||||
if (!allowed.value || busy.value) return
|
||||
reset()
|
||||
const current = generation
|
||||
const id = projectId.value
|
||||
controller = new AbortController()
|
||||
reading.value = true
|
||||
try {
|
||||
const result = await read(id, controller.signal)
|
||||
if (current !== generation || !allowed.value) return
|
||||
policy.value = result
|
||||
const signature = qualityPolicySignature(result.policy)
|
||||
if (confirmed(id, signature)) {
|
||||
preparedSignature = signature
|
||||
startOpen.value = true
|
||||
} else reviewOpen.value = true
|
||||
} catch (cause) {
|
||||
if (current === generation) {
|
||||
error.value = errorMessage(cause)
|
||||
showActionFeedback(message, error.value, 'error')
|
||||
}
|
||||
} finally { if (current === generation) reading.value = false }
|
||||
}
|
||||
|
||||
/**
|
||||
* 明确确认完整规则,修改过的草稿先保存并核对;无变化时不重复写入。
|
||||
* @param draft 表单完整校验后的用户草稿
|
||||
* @returns 是否已进入普通启动确认,不会自动执行模型任务
|
||||
*/
|
||||
async function confirmRules(draft: ProjectQualityPolicy): Promise<boolean> {
|
||||
if (!allowed.value || busy.value || !reviewOpen.value || !policy.value) return false
|
||||
const id = projectId.value
|
||||
const current = ++generation
|
||||
const expected = qualityPolicySignature(policy.value.policy)
|
||||
controller?.abort()
|
||||
controller = new AbortController()
|
||||
const signal = controller.signal
|
||||
reading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const draftSignature = qualityPolicySignature(draft)
|
||||
let result = await read(id, signal)
|
||||
if (current !== generation || !allowed.value) return false
|
||||
if (qualityPolicySignature(result.policy) !== expected) {
|
||||
policy.value = result
|
||||
showActionFeedback(message, '质量规则已在其他位置更新,请重新核对后确认。', 'warning')
|
||||
return false
|
||||
}
|
||||
if (draftSignature !== expected) {
|
||||
reading.value = false
|
||||
saving.value = true
|
||||
const saved = await projectsApi.saveQualityPolicy(id, policyDraft(draft))
|
||||
if (current !== generation || !allowed.value) return false
|
||||
if (saved.projectId !== id || qualityPolicySignature(saved.policy) !== draftSignature)
|
||||
throw new Error('质量规则保存结果与草稿不一致,请重新读取。')
|
||||
saving.value = false
|
||||
reading.value = true
|
||||
result = await read(id, signal)
|
||||
if (current !== generation || !allowed.value) return false
|
||||
if (qualityPolicySignature(result.policy) !== draftSignature) {
|
||||
policy.value = result
|
||||
showActionFeedback(message, '质量规则保存后又有更新,请重新核对。', 'warning')
|
||||
return false
|
||||
}
|
||||
}
|
||||
const signature = qualityPolicySignature(result.policy)
|
||||
const persisted = rememberQualityPolicyConfirmation(id, signature)
|
||||
fallback = persisted ? null : { projectId: id, scope: scope.value, signature, epoch: qualityPolicyConfirmationEpoch(id) }
|
||||
if (!persisted) showActionFeedback(message, '当前浏览器未能记住确认,下次进入时可能再次提醒。', 'info')
|
||||
policy.value = result
|
||||
preparedSignature = signature
|
||||
reviewOpen.value = false
|
||||
startOpen.value = true
|
||||
return true
|
||||
} catch (cause) {
|
||||
if (current === generation) {
|
||||
error.value = errorMessage(cause)
|
||||
showActionFeedback(message, error.value, 'error')
|
||||
}
|
||||
return false
|
||||
} finally {
|
||||
if (current === generation) { reading.value = false; saving.value = false }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 最终启动前再次读取,弹窗期间规则变化时返回确认,绝不直接调用模型。
|
||||
* @returns 是否取得本次启动许可
|
||||
*/
|
||||
async function verifyStart(): Promise<boolean> {
|
||||
if (!allowed.value || busy.value || !startOpen.value || !preparedSignature) return false
|
||||
const id = projectId.value
|
||||
const current = ++generation
|
||||
const currentScope = scope.value
|
||||
controller?.abort()
|
||||
controller = new AbortController()
|
||||
reading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await read(id, controller.signal)
|
||||
if (current !== generation || !allowed.value) return false
|
||||
const signature = qualityPolicySignature(result.policy)
|
||||
if (signature !== preparedSignature || !confirmed(id, signature)) {
|
||||
policy.value = result
|
||||
preparedSignature = ''
|
||||
startOpen.value = false
|
||||
reviewOpen.value = true
|
||||
showActionFeedback(message, '质量规则已变化,请重新确认后再启动拆解。', 'warning')
|
||||
return false
|
||||
}
|
||||
permit = { projectId: id, scope: currentScope, signature }
|
||||
startOpen.value = false
|
||||
return true
|
||||
} catch (cause) {
|
||||
if (current === generation) {
|
||||
error.value = errorMessage(cause)
|
||||
showActionFeedback(message, error.value, 'error')
|
||||
}
|
||||
return false
|
||||
} finally { if (current === generation) reading.value = false }
|
||||
}
|
||||
|
||||
/**
|
||||
* 消费同项目、同预览范围的本地一次性启动许可;后端仍需要独立门禁。
|
||||
* @returns 是否允许本次提交
|
||||
*/
|
||||
function consumePermit(): boolean {
|
||||
const current = permit
|
||||
permit = null
|
||||
return !!current && allowed.value && current.projectId === projectId.value &&
|
||||
current.scope === scope.value && confirmed(current.projectId, current.signature)
|
||||
}
|
||||
|
||||
/** 用户取消只读确认时撤销未完成请求,保存请求进行中禁止重复取消。 */
|
||||
function cancel() {
|
||||
if (!saving.value) reset()
|
||||
}
|
||||
watch([projectId, scope], reset, { flush: 'sync' })
|
||||
watch(allowed, value => { if (!value) reset() }, { flush: 'sync' })
|
||||
onScopeDispose(reset)
|
||||
return { policy, reviewOpen, startOpen, reading, saving, busy, error, editorKey, prepare, confirmRules, verifyStart, consumePermit, cancel }
|
||||
}
|
||||
Reference in new issue
Block a user