feat: 增加操作步骤引导与错误修复入口

This commit is contained in:
GouJ committed 2026-09-22 21:40:58 +08:00
1 parent be06caaa9f
commit 1c5b1e448a
8 files changed
+374 -122

No files matched your search

+113 -20
View File
@@ -1,34 +1,80 @@
<script setup lang="ts">
import { computed, inject, onScopeDispose, provide, watchEffect } from 'vue'
import { computed, inject, onScopeDispose, provide, ref, watchEffect } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { NScrollbar, NAlert, NButton, NSpin } from 'naive-ui'
import { NScrollbar, NAlert, NButton, NPageHeader, NSpin, NEllipsis } from 'naive-ui'
import { EmptyState } from '../../components/ui'
import { buildDocumentTitle } from '../../lib/document-title'
import { projectContextKey, useProjectData } from './context'
import { getOperation } from '../workflows/operations'
import { isProjectComplete, projectAccessKey, type ProjectAccess } from './access'
/** 下游工作区在剧本完成前不挂载,直接链接也无法越过限制。 */
/** 项目标题只保留名称;下游工作区在剧本完成前不挂载,直接链接也无法越过限制。 */
const route = useRoute()
const router = useRouter()
/** 当前路由中的项目 ID。 */
const id = computed(() => String(route.params.projectId))
/** 移动端标题只截断,不弹悬浮提示;跟随视口变化并在卸载时清理监听。 */
const mobileMedia = window.matchMedia('(max-width: 760px)')
const isMobile = ref(mobileMedia.matches)
function syncMobile() {
isMobile.value = mobileMedia.matches
}
mobileMedia.addEventListener('change', syncMobile)
onScopeDispose(() => mobileMedia.removeEventListener('change', syncMobile))
/** 项目数据仅在进入、切换项目或显式刷新时读取。 */
const context = useProjectData(id)
// 图库使用手动刷新,父布局也停止轮询,避免浏览素材时被周期性更新打断。
const isGallery = computed(() => {
const path = route.path.replace(/\/+$/, '')
return path.endsWith('/subject-images') || path.endsWith('/assets')
})
const context = useProjectData(
id,
computed(() => (isGallery.value ? false : 6000))
)
provide(projectContextKey, context)
/** 当前项目名称,仅使用与路由项目 ID 匹配的数据,避免切换项目时短暂显示旧标题。 */
const projectTitle = computed(() => {
const project = context.project.value
return project?.id === id.value ? project.title || project.topic : ''
})
/** 项目数据或子页面变化时同步浏览器标签标题。 */
watchEffect(() => {
document.title = buildDocumentTitle(route.meta.title, projectTitle.value)
})
const operation = computed(() => getOperation(id.value))
const complete = computed(() => isProjectComplete(context.project.value, id.value))
const isCreation = computed(() => route.path.replace(/\/+$/, '').endsWith('/create-drama'))
type OperationGuide = { title: string; description: string; action?: string; target?: 'profile' | 'style' | 'identity' }
const operationGuide = computed<OperationGuide | null>(() => {
const error = operation.value.error?.trim()
if (!error) return null
const normalized = error.toLowerCase()
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 === '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(() => {
@@ -37,11 +83,19 @@ watchEffect(() => {
})
onScopeDispose(() => {
if (access?.value === published) access.value = null
document.title = buildDocumentTitle(route.meta.title)
})
</script>
<template>
<section class="project-frame">
<header class="project-header">
<NPageHeader @back="router.push('/projects')">
<template #title
><NEllipsis :key="isMobile ? 'mobile' : 'desktop'" class="project-title" :tooltip="!isMobile">{{
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"
@@ -56,7 +110,17 @@ onScopeDispose(() => {
<NAlert v-if="operation.pending" :show-icon="false" role="status"
>{{ operation.label }}。可切换页面查看结果,请勿重复提交。</NAlert
>
<NAlert v-if="operation.error" type="error" :show-icon="false">{{ operation.error }}</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>
<div class="project-view">
@@ -65,10 +129,12 @@ onScopeDispose(() => {
v-else-if="context.project.value?.id === id"
class="project-access-gate"
title="请先完成剧本创作"
description="剧本完成后,才能使用拆解、视觉风格、主体身份、形态图片、资产库、分镜设计与镜头生产。请手动刷新项目状态。"
:description="`剧本完成后,才能使用拆解、视觉风格、主体身份、形态图片、资产库、分镜设计与镜头生产。${isGallery ? '请手动刷新项目状态。' : '状态会自动更新。'}`"
>
<NButton type="primary" @click="router.push(`/projects/${id}/create-drama`)">返回剧本创作</NButton>
<NButton class="ml-3" :loading="context.loading.value" @click="context.refresh">刷新项目状态</NButton>
<NButton v-if="isGallery" class="ml-3" :loading="context.loading.value" @click="context.refresh"
>刷新项目状态</NButton
>
</EmptyState>
<NSpin
v-else-if="context.loading.value"
@@ -85,6 +151,16 @@ onScopeDispose(() => {
.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;
}
@@ -94,13 +170,30 @@ onScopeDispose(() => {
.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>