Files
short-drama-agent-front/src/features/projects/ProjectLayout.vue
T

242 lines
10 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 { computed, inject, onScopeDispose, provide, watchEffect } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { NScrollbar, NAlert, NButton, NPageHeader, NSpin, NEllipsis } from 'naive-ui'
import { EmptyState } from '../../components/ui'
import { projectContextKey, useProjectData } from './context'
import { getOperation } from '../workflows/operations'
import { projectAccessKey, projectSectionFromPath, type ProjectAccess } from './access'
import { useProjectStageAccess } from './useProjectStageAccess'
import { useWorkflowExecution } from '../workflows/execution'
import WorkflowExecutionPanel from '../workflows/WorkflowExecutionPanel.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 operation = computed(() => getOperation(id.value))
const createDramaExecution = useWorkflowExecution(id, 'create-drama')
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')
type OperationGuide = {
title: string
description: string
action?: string
target?: 'profile' | 'style' | 'identity' | 'keyframe'
}
const operationGuide = computed<OperationGuide | null>(() => {
const error = operation.value.error?.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 (error.includes('身份') || normalized.includes('identity'))
return {
title: '主体身份尚未就绪',
description: '先按主体身份页的步骤补齐文本、母版并完成锁定。',
action: '处理主体身份',
target: 'identity'
}
return { title: '操作未完成', description: error }
})
/** 已知前置条件直接送达对应工作区;保留当前页面,修复后可继续原操作。 */
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') {
const onIdentityPage = route.path.replace(/\/+$/, '').endsWith('/subject-identity')
void router.push({
path: onIdentityPage ? route.path : `/projects/${id.value}/production`,
query: { ...route.query, configure: 'profile' }
})
}
}
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
><NEllipsis class="project-title" :tooltip="false">{{
context.project.value?.title || context.project.value?.topic || '读取项目'
}}</NEllipsis></template
>
</NPageHeader>
</header>
<NScrollbar
v-if="context.error.value || operation.pending || operation.error || operation.notice"
class="project-notices"
content-class="project-notices-content"
>
<NAlert 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
></NAlert
>
<NAlert v-if="operation.pending" :show-icon="false" role="status"
>{{ operation.label }}。可切换页面查看结果,请勿重复提交。</NAlert
>
<NAlert v-if="operationGuide" type="error" :show-icon="false" class="operation-guide">
<div class="operation-guide-content">
<div>
<strong>{{ operationGuide.title }}</strong>
<span class="ml-2">{{ operationGuide.description }}</span>
</div>
<NButton v-if="operationGuide.action" size="small" type="primary" @click="resolveOperationError">{{
operationGuide.action
}}</NButton>
</div>
</NAlert>
<NAlert v-if="operation.notice" :show-icon="false" role="status">{{ operation.notice }}</NAlert>
</NScrollbar>
<WorkflowExecutionPanel
v-if="isCreation && createDramaExecution.executionId.value"
class="project-workflow-status"
title="剧本创作后台任务"
:execution="createDramaExecution.query.data.value"
:loading="createDramaExecution.query.loading.value"
:error="createDramaExecution.query.error.value"
@refresh="createDramaExecution.query.refresh"
@dismiss="createDramaExecution.dismiss"
/>
<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
>
<NButton v-if="isGallery" class="ml-3" :loading="context.loading.value" @click="context.refresh"
>刷新项目状态</NButton
>
</EmptyState>
<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] px-5 bg-(--app-surface);
}
.project-header .n-page-header__main,
.project-header .n-page-header__title {
@apply min-w-0 overflow-hidden;
}
.project-title {
@apply max-w-full text-base font-semibold;
}
.project-notices.n-scrollbar {
@apply shrink-0 h-auto max-h-[100px] overflow-hidden;
}
.project-notices-content {
@apply py-2 px-6 grid gap-[5px];
}
.project-notices .n-alert {
@apply py-[7px] px-3 text-xs;
}
.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 px-3;
}
.project-title {
@apply text-sm;
}
.operation-guide-content {
@apply items-start flex-col gap-2;
}
}
</style>