101 lines
4.6 KiB
TypeScript
101 lines
4.6 KiB
TypeScript
import type { ShotActionDraft } from './repair.types'
|
||
import { actionResourceOptions } from '../projects/quality-policy'
|
||
|
||
/**
|
||
* 将后端质量代码转为页面可理解的问题描述。
|
||
* @param code 后端质量原因码
|
||
* @returns 中文原因,未知问题保留代码便于定位
|
||
*/
|
||
export function qualityIssueLabel(code: string): string {
|
||
const labels: Record<string, string> = {
|
||
duplicate_action_id: '动作编号重复',
|
||
invalid_state_execution: '静态状态被要求执行',
|
||
invalid_duration_phase: '动作阶段无效',
|
||
missing_action_phase: '动作缺少对应阶段',
|
||
unknown_phase_action_id: '阶段引用了未知动作',
|
||
state_used_as_action_phase: '静态状态被用作动作阶段',
|
||
duration_phase_sum_mismatch: '阶段时长合计不一致',
|
||
unknown_resource_action_id: '资源引用了未知动作',
|
||
resource_action_not_in_phase: '资源动作不属于当前阶段',
|
||
invalid_resource_owner_ref: '资源主体引用无效',
|
||
action_resource_conflict: '动作资源占用冲突',
|
||
hand_occupancy_conflict: '手部占用冲突',
|
||
missing_required_actions: '缺少必需动作',
|
||
missing_duration_planning: '缺少时长规划',
|
||
insufficient_action_duration: '动作执行时间不足',
|
||
unknown_hand_action_id: '手部证据引用了未知动作',
|
||
hand_action_not_in_phase: '手部动作不属于当前阶段',
|
||
invalid_hand_character_ref: '手部主体引用无效'
|
||
}
|
||
return labels[code] ?? `待复核问题(${code})`
|
||
}
|
||
|
||
/**
|
||
* 深复制实际动作与全部证据,缺失字段保留待人工填写。
|
||
* @param shot 原始镜头中的可编辑字段
|
||
* @returns 独立的完整修订草稿
|
||
*/
|
||
export function actionDraft(shot: Partial<ShotActionDraft>): ShotActionDraft {
|
||
return JSON.parse(
|
||
JSON.stringify({
|
||
requiredActions: shot.requiredActions ?? [],
|
||
durationPlanning: shot.durationPlanning ?? {
|
||
complexity: 'low',
|
||
phases: [],
|
||
transitionSeconds: 0,
|
||
recommendedDurationSeconds: 0,
|
||
reason: ''
|
||
}
|
||
})
|
||
) as ShotActionDraft
|
||
}
|
||
|
||
/**
|
||
* 校验动作编号、阶段时长与证据引用,不替代后端质量审核。
|
||
* @param draft 当前人工编辑草稿
|
||
* @returns 首项问题,空字符串表示可以提交审核
|
||
*/
|
||
export function actionDraftIssue(draft: ShotActionDraft): string {
|
||
const ids = draft.requiredActions.map(item => item.id.trim())
|
||
if (!ids.length || ids.some(item => !item) || new Set(ids).size !== ids.length) return '请填写不重复的动作编号。'
|
||
if (draft.requiredActions.some(item => !item.description.trim() || !['action', 'state'].includes(item.kind)))
|
||
return '请补齐动作描述与类型。'
|
||
const planning = draft.durationPlanning
|
||
if (!planning.phases.length) return '请至少添加一个动作阶段。'
|
||
if (!['low', 'medium', 'high'].includes(planning.complexity) || !planning.reason.trim())
|
||
return '请补齐复杂度与时长依据。'
|
||
if (
|
||
!Number.isFinite(planning.transitionSeconds) ||
|
||
planning.transitionSeconds < 0 ||
|
||
!Number.isFinite(planning.recommendedDurationSeconds) ||
|
||
planning.recommendedDurationSeconds <= 0
|
||
)
|
||
return '阶段衔接与建议时长需填写有效秒数。'
|
||
for (const phase of planning.phases) {
|
||
if (!phase.action.trim()) return '请填写每个阶段的动作描述。'
|
||
if (!Number.isFinite(phase.estimatedSeconds) || phase.estimatedSeconds <= 0) return '阶段时长必须大于 0 秒。'
|
||
const references = [
|
||
...(phase.actionIds ?? []),
|
||
...(phase.handOccupancy?.map(item => item.actionId) ?? []),
|
||
...(phase.resourceOccupancy?.map(item => item.actionId) ?? [])
|
||
]
|
||
if (references.some(id => !ids.includes(id))) return '阶段证据引用了不存在的动作编号,请重新选择。'
|
||
if (
|
||
phase.handOccupancy?.some(
|
||
item => !item.characterRef.trim() || !['left', 'right', 'both'].includes(item.hands)
|
||
)
|
||
)
|
||
return '手部证据需填写主体引用和使用的手。'
|
||
if (
|
||
phase.resourceOccupancy?.some(
|
||
item =>
|
||
!item.ownerRef.trim() ||
|
||
!actionResourceOptions.some(option => option.value === item.resource) ||
|
||
!['support', 'hold', 'move', 'interact', 'other'].includes(item.usage)
|
||
)
|
||
)
|
||
return '资源证据需填写主体引用、资源和用途。'
|
||
}
|
||
return ''
|
||
}
|