474 lines
21 KiB
Vue
474 lines
21 KiB
Vue
<script setup lang="ts">
|
||
import ContextNotice from '../../components/ui/ContextNotice.vue'
|
||
import WorkspaceActionTooltip from '../../components/ui/WorkspaceActionTooltip.vue'
|
||
|
||
import { computed, h, inject, onScopeDispose, provide, ref, watch, watchEffect } from 'vue'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import { Settings2 } from '@lucide/vue'
|
||
import { NScrollbar, NButton, NPageHeader, NSpin, NEllipsis, NSkeleton } from 'naive-ui'
|
||
import { EmptyState, WorkspaceRefreshButton } from '../../components/ui'
|
||
import { projectContextKey, useProjectData } from './context'
|
||
import { getOperation, operationErrorText } from '../workflows/operations'
|
||
import { projectAccessKey, projectSectionFromPath, type ProjectAccess } from './access'
|
||
import { useProjectStageAccess } from './useProjectStageAccess'
|
||
import { useWorkflowExecution } from '../workflows/execution'
|
||
import { clearEpisodeSourceInvalidations, invalidateEpisodeSource } from '../storyboard/model'
|
||
import { useActionMessage } from '../../components/ui/useActionMessage'
|
||
import { productionMessage } from '../production/production-messages'
|
||
import StoryboardPreparation from '../storyboard-preparation/StoryboardPreparation.vue'
|
||
import ProjectSettingsDialog from '../generation-config/components/ProjectSettingsDialog.vue'
|
||
import { projectGenerationRevisionKey, projectSettingsOpenKey } from '../generation-config/context'
|
||
import type { ProjectSettingsTab } from '../generation-config/context'
|
||
import CreateDramaSkeleton from '../create-drama/CreateDramaSkeleton.vue'
|
||
import BreakdownSkeleton from '../breakdown/BreakdownSkeleton.vue'
|
||
import VisualStyleSkeleton from '../visual-style/VisualStyleSkeleton.vue'
|
||
import SubjectIdentitySkeleton from '../subject-identity/SubjectIdentitySkeleton.vue'
|
||
|
||
/** 项目标题只保留名称;下游工作区在剧本完成前不挂载,直接链接也无法越过限制。 */
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
const id = computed(() => String(route.params.projectId))
|
||
// 图库使用手动刷新,父布局也停止轮询,避免浏览素材时被周期性更新打断。
|
||
const isGallery = computed(() => {
|
||
const path = route.path.replace(/\/+$/, '')
|
||
return path.endsWith('/subject-images') || path.endsWith('/assets')
|
||
})
|
||
const context = useProjectData(id)
|
||
provide(projectContextKey, context)
|
||
/** 项目全局配置保存后更新已挂载生成表单。 */
|
||
const generationRevision = ref(0)
|
||
provide(projectGenerationRevisionKey, generationRevision)
|
||
/** 项目标题栏共用配置弹窗开关。 */
|
||
const settingsOpen = ref(false)
|
||
/** 本次项目配置打开的指定分类,不改变当前工作区路由。 */
|
||
const settingsTab = ref<ProjectSettingsTab>('generation')
|
||
/**
|
||
* 打开标题栏已有配置抽屉,保留当前镜头与工作区。
|
||
* @param tab 本次需要定位的配置分类
|
||
*/
|
||
function openProjectSettings(tab: ProjectSettingsTab = 'generation') {
|
||
settingsTab.value = tab
|
||
settingsOpen.value = true
|
||
}
|
||
provide(projectSettingsOpenKey, openProjectSettings)
|
||
/** 既有配置恢复链接打开同一个全局弹窗,不切换工作区。 */
|
||
watch(
|
||
() => route.query.configure,
|
||
value => {
|
||
if (value === 'profile') openProjectSettings()
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
/** 关闭弹窗清除仅用于打开配置的参数,保留镜头与其它地址信息。 */
|
||
watch(settingsOpen, shown => {
|
||
if (!shown && route.query.configure === 'profile') {
|
||
const query = { ...route.query }
|
||
delete query.configure
|
||
void router.replace({ path: route.path, query, hash: route.hash })
|
||
}
|
||
})
|
||
/** 切项目时关闭旧配置,禁止把草稿带入其它项目。 */
|
||
watch(id, () => {
|
||
settingsOpen.value = false
|
||
generationRevision.value = 0
|
||
})
|
||
const operation = computed(() => getOperation(id.value))
|
||
/** 从服务端发现创作任务,刷新或换浏览器后也能继续观察故事规划等节点。 */
|
||
const createDramaExecution = useWorkflowExecution(id, 'create-drama', { discover: true })
|
||
/** 项目内跨页面继续观察首帧后台任务,维持活动锁并在真实终态后释放。 */
|
||
useWorkflowExecution(id, 'keyframe-quality')
|
||
/** 既有生成入口在跨页面时继续观察,保持项目活动锁。 */
|
||
for (const workflowName of [
|
||
'storyboard-direction',
|
||
'storyboard-visual-state',
|
||
'video-prompt',
|
||
'keyframe-generation',
|
||
'video-quality'
|
||
]) {
|
||
useWorkflowExecution(id, workflowName)
|
||
}
|
||
/** 即使直接刷新到生产页,也按真实重生成任务恢复旧剧情快照的失效标记。 */
|
||
const breakdownExecution = useWorkflowExecution(id, 'breakdown', { discover: true })
|
||
/** 只有后端确认有效的新分镜才废弃旧正文,不推测未完成或失败任务。 */
|
||
watchEffect(() => {
|
||
const record = breakdownExecution.query.data.value
|
||
if (!record || record.projectId !== id.value || record.status !== 'completed') return
|
||
if (record.metadata?.action !== 'regenerate-storyboard-episode') {
|
||
if (record.metadata?.action === 'start') clearEpisodeSourceInvalidations(record.projectId)
|
||
return
|
||
}
|
||
const number = record.metadata.episodeNo
|
||
const validation = record.result?.storyboardShotValidation
|
||
if (
|
||
typeof number === 'number' &&
|
||
validation &&
|
||
typeof validation === 'object' &&
|
||
'valid' in validation &&
|
||
validation.valid === true
|
||
)
|
||
invalidateEpisodeSource(record.projectId, number)
|
||
})
|
||
watchEffect(() => {
|
||
const status = createDramaExecution.query.data.value?.status
|
||
if ((status === 'completed' || status === 'failed') && context.project.value?.status === 'generating') {
|
||
void context.refresh()
|
||
}
|
||
})
|
||
const stageAccess = useProjectStageAccess(id, context.stageReadiness)
|
||
const complete = stageAccess.scriptReady
|
||
const currentSection = computed(() => projectSectionFromPath(route.path))
|
||
const currentAccess = computed(() => {
|
||
const section = currentSection.value
|
||
return section ? stageAccess.sections.value[section] : null
|
||
})
|
||
const isCreation = computed(() => currentSection.value === 'create-drama')
|
||
/** 各工作区共用首次读取判定;切换项目显示占位,刷新已有项目保留内容。 */
|
||
const isProjectInitialLoading = computed(() => context.loading.value && context.project.value?.id !== id.value)
|
||
type OperationGuide = {
|
||
title: string
|
||
description: string
|
||
action?: string
|
||
target?: 'profile' | 'style' | 'identity' | 'keyframe'
|
||
}
|
||
/** 仅为明确缺失的前置条件提供恢复入口,不把同页生成失败变成无效跳转。 */
|
||
const operationGuide = computed<OperationGuide | null>(() => {
|
||
const error = operationErrorText(operation.value).trim()
|
||
if (!error) return null
|
||
const normalized = error.toLowerCase()
|
||
if (normalized.includes('primary keyframe') || error.includes('主首帧'))
|
||
return {
|
||
title: '缺少镜头主首帧',
|
||
description: '视频提示词需要主首帧完成起点校验。请先生成并确认主首帧,再返回分镜页读取/生成提示词。',
|
||
action: '先生成主首帧',
|
||
target: 'keyframe'
|
||
}
|
||
if (normalized.includes('creative profile'))
|
||
return {
|
||
title: '缺少项目生成配置',
|
||
description: '先选择图片和视频生成模型,保存后再继续当前操作。',
|
||
action: '配置生成模型',
|
||
target: 'profile'
|
||
}
|
||
if (error.includes('视觉风格') || normalized.includes('visual style'))
|
||
return {
|
||
title: '缺少项目视觉风格',
|
||
description: '先完成视觉风格,再回来继续生成。',
|
||
action: '设置视觉风格',
|
||
target: 'style'
|
||
}
|
||
if (
|
||
currentSection.value !== 'subject-identity' &&
|
||
(error.includes('身份') || normalized.includes('identity')) &&
|
||
/缺少|缺失|未就绪|未锁定|尚未|未确认|missing|not ready|not locked|not found|unconfirmed/i.test(error)
|
||
)
|
||
return {
|
||
title: '主体身份尚未就绪',
|
||
description: '先按主体身份页的步骤补齐文本、母版并完成锁定。',
|
||
action: '处理主体身份',
|
||
target: 'identity'
|
||
}
|
||
return { title: '操作未完成', description: error }
|
||
})
|
||
|
||
/** 操作结果只在当前项目收到新响应后通知,不在进入工作区时重放旧提示。 */
|
||
const actionMessage = useActionMessage()
|
||
/** 只通知仍在当前项目的真实新结果,不把任务提交当作素材生成完成。 */
|
||
watch(
|
||
() => [id.value, operation.value.error, operation.value.notice] as const,
|
||
([projectId, error, notice], [previousProject, previousError, previousNotice]) => {
|
||
if (projectId !== previousProject) return
|
||
if (error && error !== previousError) {
|
||
const guide = operationGuide.value
|
||
const content =
|
||
currentSection.value === 'subject-identity'
|
||
? `${operation.value.label || '主体身份操作'}失败:${productionMessage(error)}`
|
||
: productionMessage(error)
|
||
actionMessage?.error(
|
||
() =>
|
||
h('div', { class: 'flex max-w-[min(600px,calc(100vw-48px))] flex-wrap items-center gap-3' }, [
|
||
h('span', content),
|
||
guide?.action
|
||
? h(
|
||
NButton,
|
||
{
|
||
text: true,
|
||
size: 'small',
|
||
onClick: () => {
|
||
if (id.value === projectId && operation.value.error === error)
|
||
resolveOperationError()
|
||
}
|
||
},
|
||
() => guide.action
|
||
)
|
||
: null
|
||
]),
|
||
{ duration: 8000, closable: true }
|
||
)
|
||
} else if (notice && notice !== previousNotice) {
|
||
if (operation.value.noticeType)
|
||
actionMessage?.[operation.value.noticeType](notice, {
|
||
duration: operation.value.noticeType === 'warning' ? 8000 : 4000,
|
||
closable: true
|
||
})
|
||
else if (operation.value.label === 'AI 生成主体身份')
|
||
actionMessage?.success('身份文本已生成并保存。', { duration: 3000, closable: true })
|
||
else if (operation.value.label === '保存主体身份')
|
||
actionMessage?.success('主体身份已保存。', { duration: 3000, closable: true })
|
||
else if (/刷新|读取|查询|预览/.test(operation.value.label)) {
|
||
// 成功的只读刷新由当前位置恢复内容反馈,不额外弹成功消息。
|
||
} else if (/生成|提交/.test(operation.value.label))
|
||
actionMessage?.info('任务已提交,完成后会显示结果。', { duration: 4000 })
|
||
else actionMessage?.success('操作已完成。', { duration: 3000 })
|
||
// 身份页已消费的反馈立即清除,切换主体或其它工作区都不会遗留旧横幅。
|
||
if (currentSection.value === 'subject-identity') {
|
||
operation.value.notice = ''
|
||
operation.value.noticeType = null
|
||
}
|
||
}
|
||
},
|
||
{ flush: 'post' }
|
||
)
|
||
|
||
/** 已知前置条件直接送达对应工作区;保留当前页面,修复后可继续原操作。 */
|
||
function resolveOperationError() {
|
||
const target = operationGuide.value?.target
|
||
if (target === 'keyframe') {
|
||
const recovery = operation.value.recovery?.target === 'keyframe' ? operation.value.recovery : null
|
||
const query = recovery
|
||
? {
|
||
...(recovery.episodeNo ? { episodeNo: String(recovery.episodeNo) } : {}),
|
||
shotId: recovery.shotId,
|
||
action: 'keyframe'
|
||
}
|
||
: { action: 'keyframe' }
|
||
operation.value.error = ''
|
||
void router.push({ path: `/projects/${id.value}/production`, query })
|
||
} else if (target === 'style') void router.push(`/projects/${id.value}/visual-style`)
|
||
else if (target === 'identity') void router.push(`/projects/${id.value}/subject-identity`)
|
||
else if (target === 'profile') settingsOpen.value = true
|
||
}
|
||
/** 配置真实保存后更新当前项目的就绪门禁并解除配置缺失提示。 */
|
||
function projectSettingsSaved() {
|
||
if (operationGuide.value?.target === 'profile') operation.value.error = ''
|
||
void context.refreshStageReadiness()
|
||
}
|
||
const access = inject(projectAccessKey, undefined)
|
||
let published: ProjectAccess | null = null
|
||
watchEffect(() => {
|
||
published = { projectId: id.value, completed: complete.value, sections: stageAccess.sections.value }
|
||
if (access) access.value = published
|
||
})
|
||
onScopeDispose(() => {
|
||
if (access?.value === published) access.value = null
|
||
})
|
||
</script>
|
||
<template>
|
||
<section class="project-frame">
|
||
<header class="project-header">
|
||
<!-- 以下是项目标题与全局配置入口模块,首次读取保留标题及两个操作的真实占位 -->
|
||
<NPageHeader @back="router.push('/projects')">
|
||
<template #title>
|
||
<div v-if="isProjectInitialLoading" class="project-title project-title-loading" aria-hidden="true">
|
||
<NSkeleton :height="16" />
|
||
</div>
|
||
<NEllipsis v-else class="project-title" :tooltip="false">{{
|
||
context.project.value?.title || context.project.value?.topic || ''
|
||
}}</NEllipsis>
|
||
</template>
|
||
<template #extra>
|
||
<!-- 以下是制作前检查入口,后续页面受限时仍可完成正式分镜审核 -->
|
||
<div class="project-header-actions flex items-center gap-2">
|
||
<template v-if="isProjectInitialLoading">
|
||
<NSkeleton class="project-header-action-placeholder" aria-hidden="true" />
|
||
<NSkeleton
|
||
class="project-header-action-placeholder project-header-config-placeholder"
|
||
aria-hidden="true"
|
||
/>
|
||
</template>
|
||
<template v-else>
|
||
<StoryboardPreparation
|
||
v-if="context.project.value?.id === id"
|
||
:key="id"
|
||
:project-id="id"
|
||
:disabled="!!context.error.value"
|
||
@changed="context.refresh()"
|
||
/>
|
||
<WorkspaceActionTooltip label="项目配置" mobile-only>
|
||
<NButton
|
||
class="workspace-action-button"
|
||
size="small"
|
||
aria-label="项目配置"
|
||
:disabled="!context.project.value"
|
||
@click="openProjectSettings()"
|
||
><template #icon><Settings2 :size="15" aria-hidden="true" /></template
|
||
><span class="project-config-label">项目配置</span></NButton
|
||
>
|
||
</WorkspaceActionTooltip>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
</NPageHeader>
|
||
</header>
|
||
<NScrollbar v-if="context.error.value" class="project-notices" content-class="project-notices-content">
|
||
<ContextNotice v-if="context.error.value" type="error" :show-icon="false"
|
||
>{{ context.error.value }}<span v-if="context.project.value"> 当前保留上次成功读取的数据。</span>
|
||
<NButton text class="ml-3" :loading="context.loading.value" @click="context.refresh"
|
||
>重试读取</NButton
|
||
></ContextNotice
|
||
>
|
||
</NScrollbar>
|
||
<!-- 以下是当前项目图片与视频配置弹窗模块 -->
|
||
<ProjectSettingsDialog
|
||
:key="id"
|
||
v-if="context.project.value?.id === id"
|
||
v-model:open="settingsOpen"
|
||
:initial-tab="settingsTab"
|
||
:project-id="id"
|
||
:disabled="operation.pending"
|
||
@saved="projectSettingsSaved"
|
||
@quality-saved="context.refresh()"
|
||
/>
|
||
<div class="project-view">
|
||
<RouterView v-if="context.project.value?.id === id && currentAccess?.enabled" :key="id" />
|
||
<EmptyState
|
||
v-else-if="context.project.value?.id === id"
|
||
class="project-access-gate"
|
||
:title="currentAccess?.reason || '当前步骤还不能开始'"
|
||
:description="`完成前面的制作步骤后,这里会自动开放。${isGallery ? '如刚完成操作,请刷新项目状态。' : ''}`"
|
||
>
|
||
<NButton
|
||
v-if="currentAccess?.nextPath"
|
||
type="primary"
|
||
@click="router.push(`/projects/${id}/${currentAccess.nextPath}`)"
|
||
>{{ currentAccess.nextLabel || '前往上一步' }}</NButton
|
||
>
|
||
<!-- 以下是手动刷新项目状态模块,图标位常驻以保持加载前后的按钮尺寸 -->
|
||
<WorkspaceRefreshButton
|
||
v-if="isGallery"
|
||
label="刷新项目状态"
|
||
:loading="context.loading.value"
|
||
@refresh="context.refresh"
|
||
/>
|
||
</EmptyState>
|
||
<!-- 以下是剧本创作首次读取的骨架屏模块 -->
|
||
<CreateDramaSkeleton v-else-if="isProjectInitialLoading && isCreation" />
|
||
<!-- 以下是剧本拆解首次读取的骨架屏模块 -->
|
||
<BreakdownSkeleton v-else-if="isProjectInitialLoading && currentSection === 'breakdown'" />
|
||
<!-- 以下是视觉风格项目首次读取的骨架屏模块 -->
|
||
<VisualStyleSkeleton v-else-if="isProjectInitialLoading && currentSection === 'visual-style'" />
|
||
<!-- 以下是主体身份项目首次读取的骨架屏模块 -->
|
||
<SubjectIdentitySkeleton v-else-if="isProjectInitialLoading && currentSection === 'subject-identity'" />
|
||
<NSpin v-else-if="context.loading.value" class="workspace-loading" description="正在读取项目内容…" />
|
||
</div>
|
||
</section>
|
||
</template>
|
||
|
||
<style>
|
||
/* 本组件专属布局与 Naive 内部结构覆盖。 */
|
||
@reference "../../styles/styles.css";
|
||
.project-frame {
|
||
@apply flex flex-col h-full min-h-0 overflow-hidden;
|
||
}
|
||
.project-header {
|
||
@apply shrink-0 py-[9px] bg-(--app-surface);
|
||
padding-inline: var(--app-content-padding);
|
||
}
|
||
.project-header .n-page-header__main,
|
||
.project-header .n-page-header__title {
|
||
@apply min-w-0 overflow-hidden;
|
||
}
|
||
/* 标题和配置入口使用同一垂直中心,消除省略文本的行内基线留白。 */
|
||
.project-header .n-page-header__title,
|
||
.project-header .n-page-header__extra {
|
||
@apply flex items-center;
|
||
}
|
||
.project-title {
|
||
@apply block max-w-full text-base font-semibold leading-normal;
|
||
}
|
||
/* 首次读取只显示装饰性骨架,不展示未知项目名称或可点击的设置入口。 */
|
||
.project-title-loading {
|
||
display: flex;
|
||
align-items: center;
|
||
width: min(128px, 30vw);
|
||
min-height: 1.5em;
|
||
}
|
||
.project-header-action-placeholder {
|
||
width: 120px;
|
||
height: 34px;
|
||
flex-shrink: 0;
|
||
}
|
||
.project-header-config-placeholder {
|
||
width: 104px;
|
||
}
|
||
.project-notices.n-scrollbar {
|
||
@apply shrink-0 h-auto max-h-[min(24dvh,160px)] overflow-hidden;
|
||
}
|
||
.project-notices-content {
|
||
@apply grid;
|
||
padding: var(--app-content-padding) var(--app-content-padding) 0;
|
||
gap: var(--app-content-gap);
|
||
}
|
||
.operation-guide-content {
|
||
@apply flex items-center justify-between gap-4;
|
||
}
|
||
.project-view {
|
||
@apply flex-1 min-h-0 overflow-hidden;
|
||
}
|
||
.project-header .n-page-header-wrapper {
|
||
@apply min-w-0;
|
||
}
|
||
.project-access-gate {
|
||
@apply h-full;
|
||
}
|
||
.workspace-loading {
|
||
@apply grid place-content-center h-full;
|
||
}
|
||
@media (max-width: 760px) {
|
||
.project-header {
|
||
@apply py-2;
|
||
}
|
||
.project-title {
|
||
@apply text-sm;
|
||
}
|
||
.operation-guide-content {
|
||
@apply items-start flex-col gap-2;
|
||
}
|
||
}
|
||
/* 手机端隐藏文字后,两个项目入口共用方形点击区域并将图标居中。 */
|
||
@media (max-width: 639px) {
|
||
.project-frame {
|
||
/* 顶部入口与标签栏图标共用紧凑尺寸。 */
|
||
--app-toolbar-icon-size: 32px;
|
||
}
|
||
.project-header-actions > .n-button.workspace-action-button {
|
||
width: var(--app-toolbar-icon-size);
|
||
min-width: var(--app-toolbar-icon-size);
|
||
height: var(--app-toolbar-icon-size);
|
||
min-height: var(--app-toolbar-icon-size);
|
||
padding: 0;
|
||
flex-shrink: 0;
|
||
}
|
||
.project-header-action-placeholder {
|
||
width: var(--app-toolbar-icon-size);
|
||
height: var(--app-toolbar-icon-size);
|
||
}
|
||
.project-header-actions > .n-button .n-button__icon {
|
||
margin: 0;
|
||
}
|
||
}
|
||
@media (prefers-reduced-motion: reduce) {
|
||
.project-header .n-skeleton {
|
||
animation: none;
|
||
}
|
||
}
|
||
</style>
|
||
|
||
<style scoped>
|
||
/* 窄屏的两个项目操作统一显示图标,保留按钮的完整可访问名称。 */
|
||
@media (max-width: 639px) {
|
||
.project-config-label {
|
||
display: none;
|
||
}
|
||
}
|
||
</style>
|