139 lines
5.6 KiB
TypeScript
139 lines
5.6 KiB
TypeScript
import { reactive } from 'vue'
|
|
import type { ProductionIssueCode, ProductionSession, ShotKeyframe, ShotVideo, ShotVideoQualityStatus } from './types'
|
|
|
|
/**
|
|
* 为没有独立名称字段的首帧生成展示名称,按原创建时间编号,不随列表倒序或主图切换改名。
|
|
* @param items 同一镜头的完整图片记录
|
|
* @param shotTitle 当前镜头名称
|
|
* @param shotNo 镜头序号,用于名称缺失时说明归属
|
|
* @returns 图片ID与只用于展示的名称,不写回资产
|
|
*/
|
|
export function keyframeDisplayNames(items: readonly ShotKeyframe[], shotTitle: string, shotNo: number) {
|
|
const title = shotTitle.trim() || `镜头 ${shotNo}`
|
|
return new Map(
|
|
items
|
|
.toSorted((a, b) => (a.createdAt ?? '').localeCompare(b.createdAt ?? '') || a.id.localeCompare(b.id))
|
|
.map((item, index) => [item.id, `${title} · 图片 ${String(index + 1).padStart(2, '0')}`])
|
|
)
|
|
}
|
|
|
|
/** 按项目隔离生产回执,切换页面后仍能查看上一次批量操作结果。 */
|
|
const sessions = reactive<Record<string, ProductionSession>>({})
|
|
|
|
/** 取得项目的生产页会话容器。 */
|
|
export function getProductionSession(projectId: string): ProductionSession {
|
|
return (sessions[projectId] ??= { receipt: null })
|
|
}
|
|
|
|
/** 生成规格尺寸必须成对留空或成对填写正整数。 */
|
|
export function validOptionalSize(width: number | '', height: number | ''): boolean {
|
|
if (width === '' && height === '') return true
|
|
return (
|
|
Number.isSafeInteger(width) &&
|
|
Number.isSafeInteger(height) &&
|
|
typeof width === 'number' &&
|
|
typeof height === 'number' &&
|
|
width > 0 &&
|
|
height > 0
|
|
)
|
|
}
|
|
|
|
/** 返回当前成功主首帧;异常的重复主图只取最新列表中的第一条。 */
|
|
export function primaryKeyframe(items: ShotKeyframe[]): ShotKeyframe | undefined {
|
|
return items.find(
|
|
item => item.isPrimary && item.source !== 'provider_variant' && item.status === 'completed' && item.imageUrl
|
|
)
|
|
}
|
|
|
|
/** 返回当前成功主视频。 */
|
|
export function primaryVideo(items: ShotVideo[]): ShotVideo | undefined {
|
|
return items.find(item => item.isPrimary && item.status === 'completed' && item.videoUrl)
|
|
}
|
|
|
|
/**
|
|
* 只读取指定镜头与视频的持久化检查结论,不用流程整体状态代替单个视频结果。
|
|
* @param qualityStatus 镜头质量流程记录,读取失败时为空
|
|
* @param shotId 当前镜头 ID
|
|
* @param videoId 当前视频 ID
|
|
* @returns 对应视频的检查结论,没有记录或尚未检查时返回 null
|
|
*/
|
|
export function videoRecordedValidation(
|
|
qualityStatus: ShotVideoQualityStatus | null,
|
|
shotId: string,
|
|
videoId: string
|
|
): boolean | null {
|
|
if (qualityStatus?.shotId !== shotId) return null
|
|
return qualityStatus.chain.find(item => item.videoId === videoId)?.validationPassed ?? null
|
|
}
|
|
|
|
/** 活动视频状态与后端重复任务保护保持一致。 */
|
|
export function isActiveVideo(item: ShotVideo): boolean {
|
|
return ['pending', 'queued', 'running'].includes(item.status)
|
|
}
|
|
|
|
/**
|
|
* 就绪问题转为可直接理解的中文短标签,未知问题仍显示明确提示。
|
|
* @param code 后端就绪问题码
|
|
* @returns 页面显示的中文问题标签
|
|
*/
|
|
export function issueLabel(code: ProductionIssueCode): string {
|
|
const labels: Record<ProductionIssueCode, string> = {
|
|
continuity_review_required: '连续性审核尚未解决',
|
|
invalid_generation_spec: '生成规格不完整',
|
|
missing_visual_style: '缺少视觉风格',
|
|
missing_reference: '缺少主体参考图',
|
|
missing_primary_keyframe: '缺少可用首帧',
|
|
missing_identity: '缺少角色身份',
|
|
missing_identity_anchor: '缺少演员母版',
|
|
quality_failed: '主体图片质量未通过',
|
|
quality_stale: '主体图片审核需更新',
|
|
identity_unlocked: '演员身份未锁定',
|
|
missing_prompt: '缺少视频提示词',
|
|
stale_prompt: '视频提示词需要更新',
|
|
provider_input_recovery: '视频模型输入需要处理',
|
|
missing_keyframe: '缺少主首帧',
|
|
stale_keyframe: '主首帧已过期',
|
|
failed_keyframe_quality: '首帧画面检查未通过'
|
|
}
|
|
return labels[code] ?? '生成条件需要完善'
|
|
}
|
|
|
|
/**
|
|
* 将生产任务状态转换为中文标签,包含首帧与视频的生成中状态。
|
|
* @param status 后端返回的生产任务状态
|
|
* @returns 状态对应的中文名称,未知状态显示待确认
|
|
*/
|
|
export function productionStatusLabel(status: string): string {
|
|
const labels: Record<string, string> = {
|
|
ready: '已就绪',
|
|
skipped: '已有结果',
|
|
in_progress: '任务进行中',
|
|
blocked: '前置条件不足',
|
|
pending: '等待提交',
|
|
queued: '排队中',
|
|
running: '生成中',
|
|
generating: '生成中',
|
|
completed: '已完成',
|
|
failed: '失败',
|
|
cancelled: '已取消',
|
|
submitted: '已提交',
|
|
processing: '处理中',
|
|
not_started: '未开始'
|
|
}
|
|
return labels[status] ?? '待确认'
|
|
}
|
|
|
|
/** 视频质量链状态标签与后端状态机保持一致。 */
|
|
export function videoQualityStatusLabel(status: string): string {
|
|
const labels: Record<string, string> = {
|
|
not_started: '尚未开始质量流程',
|
|
generating: '正在生成候选视频',
|
|
validating: '正在执行质量校验',
|
|
repairing: '正在自动修复',
|
|
passed: '质量校验通过',
|
|
exhausted: '自动修复次数已用完',
|
|
stale_motion_plan: '动作版本过期,质量流程已停止'
|
|
}
|
|
return labels[status] ?? '待确认'
|
|
}
|