Files
short-drama-agent-front/src/features/production/components/ShotProductionAssets.vue
T

917 lines
43 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 ProviderInputInspector from './ProviderInputInspector.vue'
import { NAlert, NButton, NCollapse, NCollapseItem, NSelect, NTag } from 'naive-ui'
import { computed, onMounted, ref, watch } from 'vue'
import { ExternalLink, ImagePlus, RefreshCw } from '@lucide/vue'
import { AssetImage, StatusBadge } from '../../../components/ui'
import { usePolling } from '../../../composables/usePolling'
import { mediaAssetUrl } from '../../../lib/assets'
import { errorMessage } from '../../../lib/http'
import { formatDate } from '../../../lib/format'
import type { DesignedShot } from '../../storyboard/types'
import { storyboardApi } from '../../storyboard/api'
import ConfirmAction from '../../workflows/ConfirmAction.vue'
import { runOperation } from '../../workflows/operations'
import { productionApi } from '../api'
import {
isActiveVideo,
issueLabel,
primaryKeyframe,
primaryVideo,
productionStatusLabel,
videoQualityStatusLabel
} from '../model'
import type {
GenerateKeyframeInput,
KeyframeReadinessItem,
KeyframeSpec,
PromptReadinessItem,
VideoGenerationSpec,
VideoReadinessItem
} from '../types'
import KeyframeDialog from './KeyframeDialog.vue'
import KeyframeCard from './KeyframeCard.vue'
import QualityDialog from './QualityDialog.vue'
import ActionMenu from '../../../components/ui/ActionMenu.vue'
import { AppDialog } from '../../../components/ui'
import ModelCapabilities from './ModelCapabilities.vue'
import type { QualityTarget } from '../quality.types'
import { sessionKeyframePassed, sessionVideoValidation } from '../quality'
import { generationConfigApi } from '../../generation-config/api'
import type {
CreativeProfileAspectRatio,
GenerationModelCatalog,
GenerationOptions
} from '../../generation-config/types'
import GenerationModelControls from '../../generation-config/components/GenerationModelControls.vue'
/** 单镜头生产面板只负责正式资产,不修改上游导演设计与即时状态。 */
const props = defineProps<{
projectId: string
shot: DesignedShot
promptReadiness?: PromptReadinessItem
keyframeReadiness?: KeyframeReadinessItem
videoReadiness?: VideoReadinessItem
openKeyframe?: boolean
disabled: boolean
}>()
const emit = defineEmits<{ changed: [] }>()
const key = computed(() => props.shot.shotId)
/** 仅当前镜头存在后台首帧或视频任务时临时轮询,终态后自动停止。 */
let query!: ReturnType<typeof usePolling<{
keyframes: Awaited<ReturnType<typeof productionApi.listKeyframes>>
videos: Awaited<ReturnType<typeof productionApi.listVideos>>
qualityStatus: Awaited<ReturnType<typeof productionApi.videoQualityStatus>> | null
qualityStatusError: string
inputPlan: Awaited<ReturnType<typeof productionApi.videoInputPlan>> | null
inputPlanError: string
}>>
const assetPollInterval = computed(() => {
const data = query?.data.value
if (!data) return false
const keyframeRunning = data.keyframes.some(item => ['pending', 'generating'].includes(item.status))
const videoRunning = data.videos.some(isActiveVideo)
return keyframeRunning || videoRunning ? 5000 : false
})
query = usePolling(
key,
async (shotId, signal) => {
const [keyframes, videos, qualityState, inputPlanState] = await Promise.all([
productionApi.listKeyframes(shotId, signal),
productionApi.listVideos(shotId, signal),
productionApi
.videoQualityStatus(shotId, signal)
.then(data => ({ data, error: '' }))
.catch(cause => ({ data: null, error: errorMessage(cause) })),
productionApi
.videoInputPlan(shotId, signal)
.then(data => ({ data, error: '' }))
.catch(cause => ({ data: null, error: errorMessage(cause) }))
])
if (keyframes.some(item => item.shotId !== shotId) || videos.some(item => item.shotId !== shotId))
throw new Error('资产记录与当前镜头不匹配,请刷新后重试。')
const qualityStatus = qualityState.data?.shotId === shotId ? qualityState.data : null
const inputPlan = inputPlanState.data?.shotId === shotId ? inputPlanState.data : null
return {
keyframes,
videos,
qualityStatus,
qualityStatusError: qualityState.error,
inputPlan,
inputPlanError: inputPlanState.error
}
},
assetPollInterval
)
/** 单独读取已保存的提示词,查询失败不影响首帧和视频资产展示。 */
const promptQuery = usePolling(key, (shotId, signal) => storyboardApi.videoPrompt(shotId, signal), false)
const savedPrompt = computed(() => (promptQuery.data.value?.shotId === key.value ? promptQuery.data.value : null))
/** 当前视频生成规格的首帧和主体参考图,独立查询避免影响资产列表。 */
const videoInputQuery = usePolling(key, (shotId, signal) => productionApi.videoGenerationSpec(shotId, signal), false)
const currentVideoInput = computed(() =>
videoInputQuery.data.value?.shotId === key.value ? videoInputQuery.data.value : null
)
const keyframes = computed(() => query.data.value?.keyframes ?? [])
const videos = computed(() => query.data.value?.videos ?? [])
const videoQualityStatus = computed(() => query.data.value?.qualityStatus ?? null)
const videoInputPlan = computed(() => query.data.value?.inputPlan ?? null)
const currentKeyframe = computed(() => primaryKeyframe(keyframes.value))
const currentVideo = computed(() => primaryVideo(videos.value))
const activeVideo = computed(() => videos.value.find(isActiveVideo))
const assetBlocked = computed(() => props.disabled || !!query.error.value)
/**
* 项目级 operation 只用于防止同一批量命令重复提交,不应锁住其它 Shot 的单资产操作。
* 当前 Shot 的图片/视频重复提交分别由本镜头持久化资产状态约束。
*/
const keyframeOpen = ref(false)
watch(
() => props.openKeyframe,
requested => {
if (requested) keyframeOpen.value = true
},
{ immediate: true }
)
const qualityOpen = ref(false)
const candidatesOpen = ref(false)
const qualityTarget = ref<QualityTarget | null>(null)
const specsOpen = ref(false)
const generationCatalog = ref<GenerationModelCatalog | null>(null)
const generationCatalogError = ref('')
const videoProvider = ref('')
const videoGenerationOptions = ref<GenerationOptions>({})
const videoInputModeOverride = ref<'auto' | 'first_frame' | 'omni_reference'>('auto')
const projectAspectRatio = ref<CreativeProfileAspectRatio>('9:16')
/** 单镜手动生成默认继承项目配置,用户修改只作用于本次请求。 */
onMounted(async () => {
try {
const [catalog, profile] = await Promise.all([
generationConfigApi.catalog(),
generationConfigApi.profile(props.projectId)
])
generationCatalog.value = catalog
projectAspectRatio.value = profile?.aspectRatio ?? '9:16'
videoProvider.value = profile?.videoProvider || catalog.defaults.videoProvider
const selected = catalog.videos.find(item => item.provider === videoProvider.value)
videoGenerationOptions.value = {
...selected?.defaults,
...profile?.videoOptions
}
} catch (cause) {
generationCatalogError.value = errorMessage(cause)
}
})
/** 从实际候选打开质量面板,保留单镜头主操作。 */
function openQuality(kind: 'keyframe' | 'video', assetId: string) {
candidatesOpen.value = false
qualityTarget.value = {
kind,
shotId: props.shot.shotId,
assetId,
title: `${props.shot.title} · ${kind === 'keyframe' ? '首帧' : '视频'}`
}
qualityOpen.value = true
}
const confirmingKeyframe = ref('')
const confirmingVideo = ref('')
const inspecting = ref(false)
const specError = ref('')
const keyframeSpec = ref<KeyframeSpec | null>(null)
const videoSpec = ref<VideoGenerationSpec | null>(null)
const canGeneratePrompt = computed(
() => !assetBlocked.value && !!props.promptReadiness && props.promptReadiness.issues.length === 0
)
const canGenerateKeyframe = computed(
() =>
!assetBlocked.value &&
!keyframes.value.some(item => ['pending', 'generating'].includes(item.status)) &&
!!props.keyframeReadiness &&
props.keyframeReadiness.issues.length === 0
)
const canGenerateVideo = computed(
() =>
!assetBlocked.value &&
!activeVideo.value &&
!!props.videoReadiness &&
props.videoReadiness.issues.length === 0 &&
(!currentKeyframe.value || keyframePassed(currentKeyframe.value.id) !== false)
)
const keyframeStale = computed(() => !!props.keyframeReadiness?.primaryKeyframeStale)
const keyframeCandidates = computed(() => keyframes.value.filter(item => item.id !== currentKeyframe.value?.id))
/** 质量历史尚无 GET;只消费当前会话中该候选的真实校验结果。 */
function keyframePassed(assetId: string) {
return sessionKeyframePassed(props.projectId, props.shot.shotId, assetId)
}
const videoStale = computed(() => !!props.videoReadiness?.primaryVideoStale)
watch(key, () => {
qualityOpen.value = false
qualityTarget.value = null
specsOpen.value = false
confirmingKeyframe.value = ''
confirmingVideo.value = ''
keyframeSpec.value = null
videoSpec.value = null
specError.value = ''
})
/** 只返回通过协议和 /storage 限制的视频地址。 */
function safeVideoUrl(value: string | null): string | null {
return value ? mediaAssetUrl(value) : null
}
/** 重新读取单镜头资产,并通知父页刷新项目就绪状态。 */
async function refreshAll() {
await Promise.all([query.refresh(), promptQuery.refresh(), videoInputQuery.refresh()])
emit('changed')
}
/** 单镜头提示词根据现有状态决定是否 force 覆盖。 */
async function generatePrompt() {
if (!canGeneratePrompt.value) return
const shotId = props.shot.shotId
const overwrite = props.promptReadiness?.status === 'skipped'
await runOperation(props.projectId, `生成镜头 ${props.shot.shotNo} 视频提示词`, async () => {
const result = await storyboardApi.generatePrompt(shotId, overwrite)
if (!result || result.shotId !== shotId || !result.videoPrompt) throw new Error('接口未返回有效视频提示词。')
})
await refreshAll()
}
/** 调用图片模型生成单镜头首帧;成功后重新读取候选和主图。 */
async function generateKeyframe(input: GenerateKeyframeInput) {
if (!canGenerateKeyframe.value) return
const shotId = props.shot.shotId
await runOperation(props.projectId, `生成镜头 ${props.shot.shotNo} 首帧`, async () => {
const result = await productionApi.generateKeyframe(shotId, input)
if (!result || result.shotId !== shotId) throw new Error('接口未确认首帧生成结果。')
})
await refreshAll()
}
/** 切换主首帧不调用模型,但会改变后续视频生成输入。 */
async function setPrimaryKeyframe() {
const keyframeId = confirmingKeyframe.value
if (
assetBlocked.value ||
!keyframeId ||
keyframePassed(keyframeId) !== true ||
keyframes.value.find(item => item.id === keyframeId)?.source === 'provider_variant'
)
return
const shotId = props.shot.shotId
confirmingKeyframe.value = ''
await runOperation(props.projectId, `设置镜头 ${props.shot.shotNo} 主首帧`, async () => {
const result = await productionApi.setPrimaryKeyframe(shotId, keyframeId)
if (!result || result.id !== keyframeId || !result.isPrimary || result.status !== 'completed')
throw new Error('接口未确认主首帧切换。')
})
await refreshAll()
}
/** 创建单镜头严格质量候选;后端完成生成后自动校验、有限修复并按结果晋升。 */
async function generateVideo() {
if (!canGenerateVideo.value) return
const shotId = props.shot.shotId
await runOperation(props.projectId, `提交镜头 ${props.shot.shotNo} 视频质量任务`, async () => {
const result = await productionApi.generateQualityVideo(shotId, {
provider: videoProvider.value || undefined,
inputMode:
videoInputModeOverride.value === 'auto'
? videoInputPlan.value?.inputMode
: videoInputModeOverride.value,
generationOptions: videoGenerationOptions.value,
maxRepairAttempts: 2,
allowedTexts: []
})
if (!result || result.shotId !== shotId || !result.candidate || !isActiveVideo(result.candidate))
throw new Error('接口未返回有效的视频质量候选任务。')
})
await refreshAll()
}
/** 手动向 Provider 查询活动视频状态,终态任务不重复查询。 */
async function refreshActiveVideo() {
const video = activeVideo.value
if (!video || assetBlocked.value) return
await runOperation(props.projectId, `刷新镜头 ${props.shot.shotNo} 视频状态`, async () => {
const result = await productionApi.refreshVideo(video.id)
if (!result || result.id !== video.id) throw new Error('接口未返回当前视频任务状态。')
})
await refreshAll()
}
/** 切换主视频只接受已完成并具有持久化地址的候选。 */
async function setPrimaryVideo() {
const videoId = confirmingVideo.value
if (assetBlocked.value || !videoId) return
const video = videos.value.find(item => item.id === videoId)
if (
!video ||
video.status !== 'completed' ||
!video.videoUrl ||
sessionVideoValidation(props.projectId, video.shotId, video.id)?.passed !== true
)
return
const shotId = props.shot.shotId
confirmingVideo.value = ''
await runOperation(props.projectId, `设置镜头 ${props.shot.shotNo} 主视频`, async () => {
const result = await productionApi.setPrimaryVideo(shotId, videoId)
if (!result || result.id !== videoId || !result.isPrimary || result.status !== 'completed')
throw new Error('接口未确认主视频切换。')
})
await refreshAll()
}
/** 显式检查两份确定性生成规格;某一阶段未就绪时保留另一份可读结果。 */
async function inspectSpecs() {
specsOpen.value = true
inspecting.value = true
specError.value = ''
const shotId = props.shot.shotId
const [keyframeResult, videoResult] = await Promise.allSettled([
productionApi.keyframeSpec(shotId),
productionApi.videoGenerationSpec(shotId)
])
if (props.shot.shotId !== shotId) {
inspecting.value = false
return
}
keyframeSpec.value = keyframeResult.status === 'fulfilled' ? keyframeResult.value : null
videoSpec.value = videoResult.status === 'fulfilled' ? videoResult.value : null
const errors = [keyframeResult, videoResult]
.filter(result => result.status === 'rejected')
.map(result => errorMessage(result.reason))
specError.value = [...new Set(errors)].join(' ')
inspecting.value = false
}
</script>
<template>
<section class="production-assets">
<div class="flex flex-wrap items-center justify-between gap-3">
<div>
<h4 class="text-sm font-semibold">镜头生产资产</h4>
</div>
<div class="flex gap-3">
<ActionMenu
label="镜头资产更多操作"
:items="[{ key: 'specs', label: '检查生成规格与模型限制', disabled: inspecting }]"
@select="inspectSpecs"
/>
<NButton
:disabled="query.loading.value"
@click="refreshAll"
quaternary
class="icon-button"
aria-label="刷新资产"
title="刷新资产"
><RefreshCw :size="16" :class="{ 'animate-spin': query.loading.value }" />
</NButton>
</div>
</div>
<NAlert v-if="query.error.value" role="alert" type="error" :show-icon="false" class="mt-4"
>{{ query.error.value }} 当前保留上次成功读取的资产,操作已暂停。
</NAlert>
<div class="production-stage mt-5">
<div class="production-stage-heading">
<div>
<h5 class="text-sm font-medium">01 · 视频提示词</h5>
</div>
<StatusBadge
v-if="promptReadiness"
:status="promptReadiness.status"
:label="productionStatusLabel(promptReadiness.status)"
/>
</div>
<ul v-if="promptReadiness?.issues.length" class="mt-3 space-y-2 text-xs text-danger">
<li v-for="issue in promptReadiness.issues" :key="issue.code">
{{ issueLabel(issue.code) }}:{{ issue.reason }}
</li>
</ul>
<div v-if="savedPrompt?.videoPrompt" class="surface-inset mt-4 p-4" aria-label="本镜视频提示词">
<p class="text-xs font-medium">本镜视频提示词</p>
<p class="mt-3 whitespace-pre-wrap break-words text-sm leading-6">{{ savedPrompt.videoPrompt }}</p>
<template v-if="savedPrompt.negativePrompt">
<p class="mt-4 text-xs font-medium">负向提示词</p>
<p class="mt-2 whitespace-pre-wrap break-words text-xs leading-6 text-muted">
{{ savedPrompt.negativePrompt }}
</p>
</template>
<p v-if="promptReadiness?.stalePrompt" class="mt-3 text-xs text-danger">
此提示词已过期,请重新生成后再制作视频。
</p>
</div>
<p v-else-if="promptQuery.loading.value" role="status" class="mt-4 text-xs text-muted">
正在读取视频提示词…
</p>
<p v-else-if="!promptQuery.error.value" class="mt-4 text-xs text-muted">尚未生成本镜视频提示词。</p>
<NAlert v-if="promptQuery.error.value" role="alert" type="warning" :show-icon="false" class="mt-4 text-xs">
提示词读取失败:{{ promptQuery.error.value }}
<NButton text size="small" @click="promptQuery.refresh">重试</NButton>
</NAlert>
<div class="production-stage-actions">
<ConfirmAction
:label="promptReadiness?.status === 'skipped' ? '重新生成本镜提示词' : '生成本镜提示词'"
:disabled="!canGeneratePrompt"
acknowledgement
:description="
promptReadiness?.status === 'skipped'
? '依据当前 GenerationSpec 与参考图重写本镜提示词。旧提示词会被覆盖,已有首帧和视频不会自动更新。'
: '依据当前 GenerationSpec 与参考图生成本镜视频提示词。'
"
@confirm="generatePrompt"
/>
</div>
</div>
<div class="production-stage">
<div class="production-stage-heading">
<div>
<h5 class="text-sm font-medium">02 · 首帧</h5>
</div>
<StatusBadge
v-if="keyframeReadiness"
:status="keyframeReadiness.status"
:label="keyframeStale ? '主首帧已过期' : productionStatusLabel(keyframeReadiness.status)"
/>
</div>
<NAlert v-if="keyframeStale" role="status" type="info" :show-icon="false" class="mt-3 text-xs">
当前主首帧使用的主体参考资产已经变化,旧图仍保留但不会继续进入视频生成。请重新生成主首帧。
</NAlert>
<ul v-if="keyframeReadiness?.issues.length" class="mt-3 space-y-2 text-xs text-danger">
<li v-for="issue in keyframeReadiness.issues" :key="issue.code">
{{ issueLabel(issue.code) }}:{{ issue.reason }}
</li>
</ul>
<div v-if="currentKeyframe" class="keyframe-grid mt-4">
<KeyframeCard
:item="currentKeyframe"
:shot-no="shot.shotNo"
:stale="keyframeStale"
:blocked="assetBlocked"
:validation-passed="keyframePassed(currentKeyframe.id)"
:confirming="false"
@quality="openQuality('keyframe', currentKeyframe.id)"
/>
</div>
<p v-else class="mt-4 text-xs text-muted">尚无已确认主首帧。请生成候选,完成质量检查后再设为主首帧。</p>
<NAlert
v-if="currentKeyframe && keyframePassed(currentKeyframe.id) === false"
type="error"
:show-icon="false"
class="mt-3 text-xs"
>
当前主首帧在本次质量检查中未通过,已阻止继续生成视频。请从候选中选择质量通过的图片。
</NAlert>
<NAlert v-if="query.data.value?.qualityStatusError" type="warning" :show-icon="false" class="mt-3 text-xs">
视频质量链状态暂时无法读取;视频资产仍可查看。请稍后刷新。
</NAlert>
<div class="production-stage-actions">
<NButton v-if="keyframeCandidates.length" @click="candidatesOpen = true">
管理候选({{ keyframeCandidates.length }})
</NButton>
<NButton :disabled="!canGenerateKeyframe" @click="keyframeOpen = true"
><ImagePlus :size="14" />{{
keyframeStale ? '生成替代候选' : currentKeyframe ? '再生成一张候选' : '生成首帧候选'
}}</NButton
>
</div>
</div>
<div class="production-stage">
<div class="production-stage-heading">
<div>
<h5 class="text-sm font-medium">03 · 视频</h5>
</div>
<StatusBadge
v-if="videoReadiness"
:status="videoReadiness.status"
:label="videoStale ? '主视频已过期' : productionStatusLabel(videoReadiness.status)"
/>
</div>
<div v-if="videoInputPlan" class="mt-3 flex flex-wrap items-center gap-2 text-xs">
<NTag size="small" :bordered="false" type="info">
{{ videoInputPlan.inputMode === 'omni_reference' ? '全模态参考' : '首帧模式' }}
</NTag>
<span class="text-muted">{{ videoInputPlan.reasons.join(';') }}</span>
</div>
<NAlert v-else-if="query.data.value?.inputPlanError" type="warning" :show-icon="false" class="mt-3 text-xs">
当前镜头输入规划暂不可用;请先处理视频就绪问题后刷新。
</NAlert>
<NAlert v-if="videoStale" role="status" type="info" :show-icon="false" class="mt-3 text-xs">
当前主视频使用的主首帧或主体参考图已经变化。旧视频仍保留;重新生成完成后,新视频会自动接替过期主视频。
</NAlert>
<ul v-if="videoReadiness?.issues.length" class="mt-3 space-y-2 text-xs text-danger">
<li v-for="issue in videoReadiness.issues" :key="issue.code">
{{ issueLabel(issue.code) }}:{{ issue.reason }}
</li>
</ul>
<section class="surface-inset mt-4 p-4" aria-label="当前视频生成素材引用">
<div class="flex flex-wrap items-center justify-between gap-2">
<h6 class="text-xs font-medium">当前视频生成素材引用</h6>
<span v-if="currentVideoInput" class="text-[11px] text-muted">
主首帧 1 张 · 主体参考图 {{ currentVideoInput.references.length }} 张
</span>
</div>
<p class="mt-2 text-xs text-muted">以下是当前镜头的生成输入;已生成的视频可能使用更早的素材。</p>
<div v-if="currentVideoInput" class="video-input-grid mt-4">
<article class="video-input-card">
<div class="video-input-image">
<AssetImage
:src="currentVideoInput.providerInputKeyframe.imageUrl"
:alt="`镜头 ${shot.shotNo} 视频输入首帧`"
preview
object-fit="cover"
/>
</div>
<div class="min-w-0 p-2 text-center text-xs">
<p class="font-medium">视频输入首帧</p>
<p class="mt-1 text-[11px] text-muted">
{{
currentVideoInput.providerInputKeyframe.source === 'provider_variant'
? '模型专用变体'
: '当前主首帧'
}}
</p>
</div>
</article>
<article
v-for="reference in currentVideoInput.references"
:key="`${reference.subjectId}:${reference.imageId}`"
class="video-input-card"
>
<div class="video-input-image">
<AssetImage
:src="reference.imageUrl"
:alt="`${reference.subjectName} ${reference.subjectFormName} 参考图`"
preview
object-fit="cover"
/>
</div>
<div class="min-w-0 p-2 text-center text-xs">
<p class="truncate font-medium" :title="reference.subjectName">
{{ reference.subjectName }}
</p>
<p class="mt-1 truncate text-[11px] text-muted" :title="reference.subjectFormName">
{{ reference.subjectFormName }}
</p>
</div>
</article>
</div>
<p v-else-if="videoInputQuery.loading.value" role="status" class="mt-4 text-xs text-muted">
正在读取视频生成素材…
</p>
<div v-else class="mt-4 text-xs text-muted">
<p>当前生成规格尚未就绪,请检查视频提示词、主首帧与主体参考图。</p>
<p v-if="videoInputQuery.error.value" class="mt-2 break-words">{{ videoInputQuery.error.value }}</p>
<NButton
v-if="videoInputQuery.error.value"
text
size="small"
class="mt-2"
@click="videoInputQuery.refresh"
>重新读取</NButton
>
</div>
</section>
<NAlert
v-if="videoQualityStatus && videoQualityStatus.status !== 'not_started'"
:type="
videoQualityStatus.status === 'passed'
? 'success'
: videoQualityStatus.status === 'exhausted'
? 'error'
: 'info'
"
:show-icon="false"
class="mt-3 text-xs"
>
{{ videoQualityStatusLabel(videoQualityStatus.status) }}
<template v-if="videoQualityStatus.maxRepairAttempts !== null">
· 修复 {{ videoQualityStatus.repairAttempt }} / {{ videoQualityStatus.maxRepairAttempts }}
</template>
<template v-if="videoQualityStatus.status === 'exhausted'">
。请检查候选视频和校验结果,调整提示词或参考资产后再重新生成。
</template>
</NAlert>
<div v-if="videos.length" class="video-grid mt-4">
<article v-for="item in videos" :key="item.id" class="video-record">
<video
v-if="item.status === 'completed' && safeVideoUrl(item.videoUrl)"
:src="safeVideoUrl(item.videoUrl) || undefined"
controls
preload="metadata"
class="production-video"
></video>
<div class="min-w-0 p-3">
<div class="flex flex-wrap items-center gap-2">
<StatusBadge :status="item.status" :label="productionStatusLabel(item.status)" />
<NTag v-if="item.isPrimary" size="small" :bordered="false">主视频</NTag>
<NTag v-if="!item.isPrimary" size="small" :bordered="false">候选视频</NTag>
<NTag v-if="item.isPrimary && videoStale" size="small" :bordered="false">已过期</NTag>
<span class="text-[10px] text-muted"
>{{ item.durationSeconds || shot.durationSeconds || '—' }}s</span
>
</div>
<NAlert v-if="item.error" role="alert" type="error" :show-icon="false" class="mt-3">{{
item.error
}}</NAlert>
<p class="mt-3 break-all text-[10px] text-muted">
{{ item.provider }} · {{ item.model }} · {{ formatDate(item.createdAt) }}
</p>
<div class="mt-3 flex flex-wrap gap-3">
<NButton
v-if="item.status === 'completed' && item.videoUrl"
text
size="small"
@click="openQuality('video', item.id)"
>质量检查<template v-if="sessionVideoValidation(projectId, item.shotId, item.id)">
·
{{
sessionVideoValidation(projectId, item.shotId, item.id)?.passed
? '曾通过'
: '未通过'
}}</template
></NButton
>
<a
v-if="safeVideoUrl(item.videoUrl)"
:href="safeVideoUrl(item.videoUrl) || undefined"
target="_blank"
rel="noopener noreferrer"
class="text-button"
>打开视频<ExternalLink :size="12"
/></a>
<NButton
v-if="
item.status === 'completed' &&
item.videoUrl &&
!item.isPrimary &&
sessionVideoValidation(projectId, item.shotId, item.id)?.passed === true
"
:disabled="assetBlocked"
@click="confirmingVideo = item.id"
text
size="small"
>
设为主视频
</NButton>
</div>
<NAlert v-if="confirmingVideo === item.id" type="info" :show-icon="false" class="mt-3 text-xs"
><p>确认把此候选设为当前镜头主视频?旧成片仍会保留。</p>
<div class="mt-2 flex gap-3">
<NButton @click="setPrimaryVideo" type="primary">确认切换</NButton>
<NButton @click="confirmingVideo = ''" text size="small">取消</NButton>
</div></NAlert
>
</div>
</article>
</div>
<p v-else class="mt-4 text-xs text-muted">尚无视频任务记录。</p>
<p v-if="videos.some(item => !item.isPrimary)" class="mt-3 text-xs text-muted">
质量链状态来自后端持久化记录;手动晋升候选仍需在当前页面完成一次视觉校验。自动质量任务通过后会直接更新主视频。
</p>
<section
v-if="generationCatalog"
class="generation-settings-panel surface-inset mt-4"
aria-label="本次视频生成模型设置"
>
<div class="generation-settings-content">
<div>
<h6 class="text-sm font-medium">本次生成设置</h6>
<p class="mt-1 text-[11px] leading-5 text-muted">
仅覆盖当前镜头本次生成,不修改项目默认模型。
</p>
</div>
<GenerationModelControls
class="mt-5"
type="video"
:catalog="generationCatalog"
:provider="videoProvider"
:options="videoGenerationOptions"
:aspect-ratio="projectAspectRatio"
:disabled="assetBlocked"
@update:provider="videoProvider = $event"
@update:options="videoGenerationOptions = $event"
/>
<div class="generation-input-mode">
<p class="generation-input-mode-label">输入模式</p>
<NSelect
:value="videoInputModeOverride"
:disabled="assetBlocked"
:options="[
{
label: `自动(推荐:${videoInputPlan?.inputMode === 'omni_reference' ? '全模态参考' : '首帧模式'})`,
value: 'auto'
},
{ label: '首帧模式', value: 'first_frame' },
{ label: '全模态参考', value: 'omni_reference' }
]"
@update:value="videoInputModeOverride = $event"
/>
<p class="mt-1.5 text-[11px] leading-5 text-muted">
自动模式遵循后端 Planner;手动选择只影响当前镜头本次生成。
</p>
</div>
</div>
</section>
<NAlert v-else-if="generationCatalogError" type="warning" :show-icon="false" class="mt-4 text-xs">
生成模型目录读取失败:{{ generationCatalogError }}
</NAlert>
<div class="production-stage-actions">
<ConfirmAction
:label="
videoStale ? '重新生成质量视频' : currentVideo ? '再生成一个质量候选' : '提交本镜视频质量任务'
"
:disabled="!canGenerateVideo"
acknowledgement
:description="
videoStale
? '使用当前视频提示词、主首帧和主体参考图启动严格质量流水线;最多自动修复 2 次,通过后才接替当前过期主视频。'
: currentVideo
? '新增一个严格质量候选;后端会自动校验并最多修复 2 次,通过后才替换主视频。'
: '启动严格视频质量流水线;任务在后台生成、校验并有限修复,通过后才晋升主视频。'
"
primary
@confirm="generateVideo"
/>
<NButton v-if="activeVideo" :disabled="assetBlocked" @click="refreshActiveVideo"
><RefreshCw :size="14" />刷新任务状态
</NButton>
</div>
</div>
<AppDialog v-model:open="specsOpen" title="生成规格与模型限制" description="只读检查,不调用生成模型。" wide>
<NAlert v-if="specError" role="alert" type="error" :show-icon="false" class="mt-4">{{ specError }}</NAlert>
<p v-if="inspecting" role="status" class="mt-4 text-xs text-muted">正在读取生成规格…</p>
<ModelCapabilities :shot-id="shot.shotId" />
<ProviderInputInspector :shot-id="shot.shotId" />
<NCollapse v-if="keyframeSpec || videoSpec" class="mt-5 pt-4 text-xs" :default-expanded-names="['details']"
><NCollapseItem name="details"
><template #header>本镜确定性生成规格</template>
<div class="mt-4 grid gap-5 lg:grid-cols-2">
<div v-if="keyframeSpec">
<h5 class="font-medium">首帧 Prompt · {{ keyframeSpec.references.length }} 张参考图</h5>
<p class="mt-3 whitespace-pre-wrap leading-6 text-muted">{{ keyframeSpec.prompt }}</p>
<ul v-if="keyframeSpec.references.length" class="mt-3 space-y-1 text-[11px] text-muted">
<li
v-for="reference in keyframeSpec.references"
:key="`${reference.role}:${reference.imageId}`"
>
{{ reference.subjectRef }} ·
{{ reference.role === 'identity-anchor' ? '演员身份母版' : '形态主图' }} ·
<code>{{ reference.imageId }}</code>
</li>
</ul>
</div>
<div v-if="videoSpec">
<h5 class="font-medium">视频 Prompt · {{ videoSpec.durationSeconds }}s</h5>
<p class="mt-3 whitespace-pre-wrap leading-6 text-muted">{{ videoSpec.videoPrompt }}</p>
<p v-if="videoSpec.negativePrompt" class="mt-3 whitespace-pre-wrap leading-6 text-muted">
Negative prompt: {{ videoSpec.negativePrompt }}
</p>
<p class="mt-3 break-all font-mono text-[10px] text-muted">
业务主首帧 ID · {{ videoSpec.keyframe.id }}
</p>
<p v-if="videoSpec.providerInputKeyframe" class="mt-2 break-all text-[10px] text-muted">
通用规格首帧 ID(未指定模型) · {{ videoSpec.providerInputKeyframe.id }}
{{
videoSpec.providerInputKeyframe.source === 'provider_variant'
? '(专用变体)'
: '(业务主首帧)'
}}
</p>
</div>
</div></NCollapseItem
></NCollapse
>
</AppDialog>
<QualityDialog
v-model:open="qualityOpen"
:project-id="projectId"
:target="qualityTarget"
:disabled="assetBlocked"
@changed="refreshAll"
/>
<AppDialog
v-model:open="candidatesOpen"
title="首帧候选管理"
description="先完成质量检查;只有本会话校验通过的候选才能设为主首帧。"
wide
>
<div v-if="keyframeCandidates.length" class="keyframe-grid mt-4">
<KeyframeCard
v-for="item in keyframeCandidates"
:key="item.id"
:item="item"
:shot-no="shot.shotNo"
:stale="false"
:blocked="assetBlocked"
:validation-passed="keyframePassed(item.id)"
:confirming="confirmingKeyframe === item.id"
@quality="openQuality('keyframe', item.id)"
@select="confirmingKeyframe = item.id"
@confirm="setPrimaryKeyframe"
@cancel="confirmingKeyframe = ''"
/>
</div>
<p v-else class="text-xs text-muted">暂无其它首帧候选。</p>
</AppDialog>
<KeyframeDialog
v-model:open="keyframeOpen"
:shot-id="shot.shotId"
:shot-title="shot.title"
:project-id="projectId"
:replace-primary="keyframeStale"
:disabled="!canGenerateKeyframe"
@generate="generateKeyframe"
/>
</section>
</template>
<style>
/* 本组件专属布局与 Naive 内部结构覆盖。 */
@reference "../../../styles/styles.css";
.production-stage {
@apply py-5 px-0;
}
.production-stage:first-of-type {
@apply border-t-0;
}
.production-stage-heading {
@apply flex items-start justify-between gap-4;
}
.production-stage-actions {
@apply mt-4 flex min-h-[34px] flex-wrap items-center gap-3;
}
.keyframe-grid {
@apply grid gap-3;
grid-template-columns: repeat(auto-fill, minmax(180px, 220px));
}
.keyframe-card {
@apply relative overflow-hidden rounded-none bg-(--app-subtle);
}
.keyframe-card .asset-image {
@apply aspect-square rounded-none;
}
.keyframe-image {
@apply relative;
}
.primary-keyframe-mark {
@apply absolute top-2 left-2 z-1 flex size-7 items-center justify-center;
color: var(--app-on-accent);
background: var(--app-button-primary);
box-shadow:
0 0 0 1px rgb(0 0 0 / 55%),
0 2px 8px rgb(0 0 0 / 35%);
}
.video-input-grid,
.video-grid {
@apply grid gap-3;
grid-template-columns: repeat(auto-fill, minmax(180px, 220px));
}
.video-input-grid .asset-image {
@apply aspect-square rounded-none;
}
.video-input-card {
@apply flex min-w-0 flex-col overflow-hidden bg-(--app-control);
}
.video-input-image {
@apply aspect-square w-full overflow-hidden bg-(--app-subtle);
}
.video-input-image .asset-image {
@apply h-full w-full aspect-auto;
}
.video-record {
@apply min-w-0 overflow-hidden rounded-none bg-(--app-subtle);
}
.production-video {
@apply block w-full aspect-square bg-[#080808] object-contain;
}
.generation-settings-panel {
@apply p-5;
}
.generation-settings-content {
@apply w-full max-w-[1120px];
}
.generation-input-mode {
@apply mt-5 w-full max-w-[550px];
}
.generation-input-mode-label {
@apply mb-[7px] text-xs font-medium leading-5;
}
@media (max-width: 760px) {
.keyframe-grid,
.video-input-grid,
.video-grid {
@apply grid-cols-[repeat(2,_minmax(0,_1fr))];
}
.generation-settings-panel {
@apply p-4;
}
}
</style>