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

143 lines
8.7 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 { 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'
import type { ShotValidation } from '../types'
import type { BreakdownQuality } from '../quality'
/** 同一剧集、节拍和镜头的校验问题分组。 */
interface BreakdownIssueGroup {
/** 稳定的位置键。 */
key: string
/** 后端提供的原始位置。 */
location: ShotValidation['issues'][number]
/** 去重后的原始错误描述。 */
messages: string[]
}
/** 拆解问题及调用方提供的修订、恢复操作使用独立全屏抽屉展示。 */
const props = defineProps<{
/** 后端分镜校验问题,保留原始描述和位置。 */
issues: ShotValidation['issues']
/** 工作流执行异常,空值表示没有执行异常。 */
workflowError?: string
/** 当前结果是否允许定位到分镜正文。 */
locatable: boolean
/** 当前版本统一审核,历史问题与当前问题分开。 */
quality?: BreakdownQuality
/** 真实写入例外期间禁止关闭和定位,普通读取不锁定。 */
busy?: boolean
}>()
/** 独立问题抽屉显隐。 */
const open = defineModel<boolean>('open', { default: false })
/** 抽屉关闭后再定位正文,避免焦点陷阱阻止定位。 */
const emit = defineEmits<{ locate: [issue: ShotValidation['issues'][number]]; refresh: [] }>()
/** 问题类型统一分类,缺失精确坐标时只提供剧集查看。 */
const problemGroups = computed(() => ([
['subject', '主体引用缺失'], ['binding', '形态绑定异常'], ['structure', '分镜结构校验'],
['action', '动作质量阻断'], ['pending', '待审核剧集'], ['workflow', '当前执行异常']
] as const).map(([type, label]) => ({ type, label, items: props.quality?.problems.filter(item => item.type === type) ?? [] })).filter(group => group.items.length))
/** 相同镜头的问题合并为一组,重复消息不重复显示。 */
const groups = computed(() => {
const result = new Map<string, BreakdownIssueGroup>()
for (const issue of props.issues) {
const key = `${issue.episodeNo}:${issue.beatNo ?? ''}:${issue.shotNo ?? ''}`
const group = result.get(key) ?? { key, location: issue, messages: [] }
if (!group.messages.includes(issue.message)) group.messages.push(issue.message)
result.set(key, group)
}
return [...result.values()]
})
/** 当前去重后的问题总数,不把多个位置合为一个错误。 */
const count = computed(() => groups.value.reduce((total, group) => total + group.messages.length, 0))
/** 等待离场后执行的定位。 */
const pendingLocation = ref<ShotValidation['issues'][number] | null>(null)
/**
* 关闭问题抽屉后定位到对应剧集、节拍或镜头。
* @param issue 后端提供的问题位置
*/
function locate(issue: ShotValidation['issues'][number]) {
if (!props.locatable || props.busy) return
pendingLocation.value = { ...issue }
open.value = false
}
/** 离场动画结束后再交接焦点。 */
function finish() {
if (pendingLocation.value) {
const issue = pendingLocation.value
pendingLocation.value = null
emit('locate', issue)
}
}
</script>
<template>
<!-- 以下是全屏展示的拆解执行错误与分镜校验问题模块 -->
<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
><span v-else>查看最近保存结果中的问题</span></template
>
<!-- 以下是当前版本的分类问题,历史错误不会混入当前问题数量 -->
<div v-if="quality" class="space-y-5" :aria-busy="quality.loading">
<p v-if="quality.loading" class="text-sm text-muted" role="status">正在读取当前候选审核…</p>
<div v-else-if="quality.error" class="problem-surface p-5 space-y-3"><p class="text-sm break-words">{{ quality.error }}</p><NButton @click="emit('refresh')">重新读取审核</NButton></div>
<template v-else>
<section v-for="group in problemGroups" :key="group.type" class="space-y-3" :aria-label="group.label">
<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">{{ 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 }} 集 · {{ 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">{{ userFacingText(workflowError) }}</p>
</section>
<article
v-for="group in quality ? [] : groups"
:key="group.key"
class="workspace-panel problem-surface breakdown-issue-group space-y-3"
>
<div class="flex flex-wrap items-center justify-between gap-3">
<h3 class="text-sm font-medium">
第 {{ group.location.episodeNo }} 集<span v-if="group.location.beatNo">
· 节拍 {{ group.location.beatNo }}</span
><span v-if="group.location.shotNo"> · 镜头 {{ group.location.shotNo }}</span>
</h3>
<NButton v-if="locatable" size="small" text @click="locate(group.location)">{{
group.location.beatNo ? '定位分镜' : '查看本集'
}}</NButton>
</div>
<p v-for="message in group.messages" :key="message" class="break-words text-sm leading-6">
{{ userFacingText(message) }}
</p>
</article>
<p v-if="!quality && !groups.length && !workflowError" class="py-5 text-sm text-muted">
当前没有具体错误描述,可读取修复清单确认待处理镜头。
</p>
</div>
<!-- 以下是独立的问题修订与阶段恢复模块,不承载生成配置或候选提交 -->
<div v-if="$slots.repair" class="mt-6 space-y-5" aria-label="问题修订与恢复"><slot name="repair" /></div>
<!-- 以下是灰底关闭操作,绿色主按钮仅用于提交或执行任务 -->
<template #footer><NButton type="default" :disabled="busy" @click="open = false">关闭</NButton></template>
</AppDrawer>
</template>
<style>
/* 问题正文可滚动,滚动轨道隐藏;公共抽屉继续固定标题与底部关闭操作。 */
.breakdown-issues-drawer .n-scrollbar-rail {
display: none;
}
</style>