feat(short-drama-agent-front): 优化项目查询与工作区界面

This commit is contained in:
GJ committed 2026-09-21 19:36:47 +08:00
1 parent 227db5450d
commit e6d02a20a7
33 files changed
+439 -513

No files matched your search

+19 -51
View File
@@ -1,32 +1,31 @@
<script setup lang="ts">
import { computed, inject, onScopeDispose, provide, ref, watchEffect } from 'vue'
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 { NScrollbar, NAlert, NButton, NSpin } 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 isGallery = computed(() => route.path.replace(/\/+$/, '').endsWith('/subject-images'))
const context = useProjectData(
id,
computed(() => (isGallery.value ? false : 6000))
)
/** 项目数据仅在进入、切换项目或显式刷新时读取。 */
const context = useProjectData(id)
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'))
@@ -38,19 +37,11 @@ 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"
@@ -74,12 +65,10 @@ onScopeDispose(() => {
v-else-if="context.project.value?.id === id"
class="project-access-gate"
title="请先完成剧本创作"
:description="`剧本完成后,才能使用拆解、视觉风格、主体身份、形态图片、分镜设计与镜头生产。${isGallery ? '请手动刷新项目状态。' : '状态会自动更新。'}`"
description="剧本完成后,才能使用拆解、视觉风格、主体身份、形态图片、分镜设计与镜头生产。请手动刷新项目状态。"
>
<NButton type="primary" @click="router.push(`/projects/${id}/create-drama`)">返回剧本创作</NButton>
<NButton v-if="isGallery" class="ml-3" :loading="context.loading.value" @click="context.refresh"
>刷新项目状态</NButton
>
<NButton class="ml-3" :loading="context.loading.value" @click="context.refresh">刷新项目状态</NButton>
</EmptyState>
<NSpin
v-else-if="context.loading.value"
@@ -96,16 +85,6 @@ 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;
}
@@ -118,21 +97,10 @@ onScopeDispose(() => {
.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;
}
}
</style>
+2 -2
View File
@@ -13,7 +13,7 @@ import {
} from 'naive-ui'
import { RefreshCw, Search } from '@lucide/vue'
import WorkspacePage from '../../components/ui/WorkspacePage.vue'
import { usePolling } from '../../composables/usePolling'
import { useQuery } from '../../composables/useQuery'
import { StatusBadge } from '../../components/ui'
import { formatDate } from '../../lib/format'
import { projectsApi } from './api'
@@ -23,7 +23,7 @@ import CreateProjectDialog from './components/CreateProjectDialog.vue'
/** 项目表格使用固定表头与独立滚动;搜索筛选仍作用于真实接口数据。 */
const router = useRouter()
/** 列表已有刷新按钮,只在进入和手动刷新时读取;筛选在完整结果中进行。 */
const query = usePolling(ref('projects'), (_, signal) => projectsApi.list(signal), false)
const query = useQuery(ref('projects'), (_, signal) => projectsApi.list(signal))
const search = ref('')
const filter = ref('all')
/** 接口暂未分页:对完整查询结果分批展示,滚动时追加而非切换页码。 */
+10 -14
View File
@@ -1,23 +1,19 @@
import { computed, inject, type InjectionKey, type MaybeRefOrGetter } from 'vue'
import { usePolling } from '../../composables/usePolling'
import { computed, inject, type InjectionKey } from 'vue'
import { useQuery } from '../../composables/useQuery'
import { projectsApi } from './api'
import type { ProjectDetail } from './types'
import type { Checkpoint } from '../workflows/types'
import type { Ref } from 'vue'
/** 同一项目的各个 graph 共用一份查询,避免每个面板重复请求。 */
export function useProjectData(id: Ref<string>, interval: MaybeRefOrGetter<number | false> = 6000) {
const query = usePolling(
id,
async (projectId, signal) => {
const [project, checkpoints] = await Promise.all([
projectsApi.detail(projectId, signal),
projectsApi.checkpoints(projectId, signal)
])
return { project, checkpoints }
},
interval
)
export function useProjectData(id: Ref<string>) {
const query = useQuery(id, async (projectId, signal) => {
const [project, checkpoints] = await Promise.all([
projectsApi.detail(projectId, signal),
projectsApi.checkpoints(projectId, signal)
])
return { project, checkpoints }
})
const project = computed<ProjectDetail | null>(() => query.data.value?.project ?? null)
const checkpoints = computed<Checkpoint[]>(() => query.data.value?.checkpoints ?? [])
return { ...query, project, checkpoints }