perf(short-drama-agent-front): 优化记录加载与工作区体验
This commit is contained in:
1 parent
d0264c08ce
commit
db9aea1694
111 files changed
+1680
-1290
No files matched your search
@@ -7,7 +7,7 @@ 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 { projectContextKey, useProjectData, type CheckpointWorkflow } from './context'
|
||||
import { getOperation, operationErrorText } from '../workflows/operations'
|
||||
import { projectAccessKey, projectSectionFromPath, type ProjectAccess, type ProjectSectionAccess } from './access'
|
||||
import { useProjectStageAccess } from './useProjectStageAccess'
|
||||
@@ -22,12 +22,13 @@ 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 ProjectWorkspaceSkeleton from './components/ProjectWorkspaceSkeleton.vue'
|
||||
import SubjectIdentitySkeleton from '../subject-identity/SubjectIdentitySkeleton.vue'
|
||||
|
||||
/** 项目标题只保留名称;下游工作区在剧本完成前不挂载,直接链接也无法越过限制。 */
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const id = computed(() => String(route.params.projectId))
|
||||
const id = computed(() => String(route.params.projectId ?? ''))
|
||||
const context = useProjectData(id)
|
||||
provide(projectContextKey, context)
|
||||
/** 项目全局配置保存后更新已挂载生成表单。 */
|
||||
@@ -68,10 +69,43 @@ watch(id, () => {
|
||||
generationRevision.value = 0
|
||||
})
|
||||
const operation = computed(() => getOperation(id.value))
|
||||
/**
|
||||
* 跨页面观察真实终态并刷新对应数据,不因读取历史终态重复刷新。
|
||||
* @param observer 已挂载的后台观察器
|
||||
* @param workflow 需要刷新的正文所属工作流
|
||||
*/
|
||||
function refreshOnTerminal(observer: ReturnType<typeof useWorkflowExecution>, workflow: CheckpointWorkflow | null) {
|
||||
watch(
|
||||
() => observer.query.data.value,
|
||||
(record, previous) => {
|
||||
if (
|
||||
!record ||
|
||||
record.projectId !== id.value ||
|
||||
previous?.id !== record.id ||
|
||||
!['pending', 'running'].includes(previous.status) ||
|
||||
!['completed', 'failed'].includes(record.status)
|
||||
)
|
||||
return
|
||||
void context.refreshWorkflow(workflow, record.projectId, record.id + ':' + record.status)
|
||||
if (workflow === 'create-drama' && currentSection.value !== 'create-drama') {
|
||||
void context.refreshProject()
|
||||
void context.refreshStageReadiness()
|
||||
} else if (
|
||||
workflow === 'breakdown' &&
|
||||
currentSection.value !== 'breakdown' &&
|
||||
currentSection.value !== 'storyboard'
|
||||
) {
|
||||
void context.refreshStageReadiness()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/** 从服务端发现创作任务,刷新或换浏览器后也能继续观察故事规划等节点。 */
|
||||
const createDramaExecution = useWorkflowExecution(id, 'create-drama', { discover: true })
|
||||
refreshOnTerminal(createDramaExecution, 'create-drama')
|
||||
/** 项目内跨页面继续观察首帧后台任务,维持活动锁并在真实终态后释放。 */
|
||||
useWorkflowExecution(id, 'keyframe-quality')
|
||||
refreshOnTerminal(useWorkflowExecution(id, 'keyframe-quality'), null)
|
||||
/** 派生设计从服务端发现新任务;其它既有入口继续观察已知任务,保持项目活动锁。 */
|
||||
for (const workflowName of [
|
||||
'storyboard-direction',
|
||||
@@ -80,12 +114,16 @@ for (const workflowName of [
|
||||
'keyframe-generation',
|
||||
'video-quality'
|
||||
]) {
|
||||
useWorkflowExecution(id, workflowName, {
|
||||
discover: ['storyboard-direction', 'storyboard-visual-state'].includes(workflowName)
|
||||
})
|
||||
refreshOnTerminal(
|
||||
useWorkflowExecution(id, workflowName, {
|
||||
discover: ['storyboard-direction', 'storyboard-visual-state'].includes(workflowName)
|
||||
}),
|
||||
null
|
||||
)
|
||||
}
|
||||
/** 即使直接刷新到生产页,也按真实重生成任务恢复旧剧情快照的失效标记。 */
|
||||
const breakdownExecution = useWorkflowExecution(id, 'breakdown', { discover: true })
|
||||
refreshOnTerminal(breakdownExecution, 'breakdown')
|
||||
/** 只有后端确认有效的新分镜才废弃旧正文,不推测未完成或失败任务。 */
|
||||
watchEffect(() => {
|
||||
const record = breakdownExecution.query.data.value
|
||||
@@ -105,12 +143,6 @@ watchEffect(() => {
|
||||
)
|
||||
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
|
||||
/** 当前路由所属的制作步骤;项目素材不是制作步骤。 */
|
||||
@@ -127,7 +159,14 @@ const currentAccess = computed<ProjectSectionAccess | null>(() => {
|
||||
})
|
||||
const isCreation = computed(() => currentSection.value === 'create-drama')
|
||||
/** 各工作区共用首次读取判定;切换项目显示占位,刷新已有项目保留内容。 */
|
||||
const isProjectInitialLoading = computed(() => context.loading.value && context.project.value?.id !== id.value)
|
||||
const isProjectInitialLoading = computed(
|
||||
() =>
|
||||
(context.projectQuery.loading.value && !context.project.value) ||
|
||||
(!isCreation.value &&
|
||||
!isProjectAssets.value &&
|
||||
context.readinessQuery.loading.value &&
|
||||
!context.stageReadiness.value)
|
||||
)
|
||||
type OperationGuide = {
|
||||
title: string
|
||||
description: string
|
||||
@@ -295,7 +334,9 @@ onScopeDispose(() => {
|
||||
:key="id"
|
||||
:project-id="id"
|
||||
:disabled="!!context.error.value"
|
||||
:can-open-storyboard="stageAccess.sections.value.storyboard.enabled"
|
||||
@changed="context.refresh()"
|
||||
@open-storyboard="router.push(`/projects/${id}/storyboard`)"
|
||||
/>
|
||||
<WorkspaceActionTooltip label="项目配置" mobile-only>
|
||||
<NButton
|
||||
@@ -335,10 +376,9 @@ onScopeDispose(() => {
|
||||
<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"
|
||||
v-else-if="context.project.value?.id === id && !isProjectInitialLoading"
|
||||
class="project-access-gate"
|
||||
:title="currentAccess?.reason || '当前步骤还不能开始'"
|
||||
description="如刚完成前置步骤,请刷新项目状态。正式分镜的复检详情可在「制作前检查」查看。"
|
||||
>
|
||||
<NButton
|
||||
v-if="currentAccess?.nextPath"
|
||||
@@ -362,6 +402,13 @@ onScopeDispose(() => {
|
||||
<VisualStyleSkeleton v-else-if="isProjectInitialLoading && currentSection === 'visual-style'" />
|
||||
<!-- 以下是主体身份项目首次读取的骨架屏模块 -->
|
||||
<SubjectIdentitySkeleton v-else-if="isProjectInitialLoading && currentSection === 'subject-identity'" />
|
||||
<!-- 以下是项目首次进入图库和分镜时的骨架,项目门禁返回后再显示正文 -->
|
||||
<ProjectWorkspaceSkeleton
|
||||
v-else-if="
|
||||
isProjectInitialLoading && (currentSection === 'subject-images' || currentSection === 'storyboard')
|
||||
"
|
||||
:variant="currentSection"
|
||||
/>
|
||||
<NSpin v-else-if="context.loading.value" class="workspace-loading" description="正在读取项目内容…" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { request, optionalResource } from '../../lib/http'
|
||||
import type { Checkpoint } from '../workflows/types'
|
||||
import type { Checkpoint, CheckpointSummary } from '../workflows/types'
|
||||
import type { WorkflowExecutionStart } from '../workflows/execution.types'
|
||||
import type {
|
||||
CreateProjectInput,
|
||||
@@ -71,8 +71,57 @@ export const projectsApi = {
|
||||
request<{ id: string; deleted: boolean }>(`/projects/${encodeURIComponent(id)}`, { method: 'DELETE' }),
|
||||
state: (id: string, signal?: AbortSignal) =>
|
||||
optionalResource(request<DramaState>(`/projects/${encodeURIComponent(id)}/state`, { signal })),
|
||||
checkpoints: (id: string, signal?: AbortSignal) =>
|
||||
request<Checkpoint[]>(`/projects/${encodeURIComponent(id)}/checkpoints`, { signal }),
|
||||
/**
|
||||
* 读取每个工作流最新的执行状态,供导航与操作门禁使用。
|
||||
* @param id 当前项目
|
||||
* @param signal 请求取消信号
|
||||
* @returns 最新保存记录摘要
|
||||
*/
|
||||
async checkpointSummaries(id: string, signal?: AbortSignal) {
|
||||
const rows = await request<CheckpointSummary[]>(
|
||||
`/projects/${encodeURIComponent(id)}/checkpoints?view=summary`,
|
||||
{ signal }
|
||||
)
|
||||
if (
|
||||
!Array.isArray(rows) ||
|
||||
rows.some(
|
||||
row =>
|
||||
!row?.workflowName ||
|
||||
!row.checkpointId ||
|
||||
!row.createdAt ||
|
||||
!row.updatedAt ||
|
||||
!row.state ||
|
||||
typeof row.state !== 'object' ||
|
||||
Array.isArray(row.state) ||
|
||||
Object.keys(row.state).some(key => key !== 'workflowExecution') ||
|
||||
(row.state.workflowExecution !== undefined &&
|
||||
typeof row.state.workflowExecution?.status !== 'string')
|
||||
) ||
|
||||
new Set(rows.map(row => row.workflowName)).size !== rows.length
|
||||
)
|
||||
throw new Error('任务摘要无法核对,请刷新后再试。')
|
||||
return rows
|
||||
},
|
||||
/**
|
||||
* 读取完整记录,页面按实际需要指定工作流。
|
||||
* @param id 当前项目
|
||||
* @param signal 请求取消信号
|
||||
* @param workflowName 完整记录所属的工作流
|
||||
* @returns 保留历史顺序及来源信息的完整记录
|
||||
*/
|
||||
async checkpoints(id: string, signal?: AbortSignal, workflowName?: string) {
|
||||
const rows = await request<Checkpoint[]>(
|
||||
`/projects/${encodeURIComponent(id)}/checkpoints` +
|
||||
(workflowName === undefined ? '' : `?${new URLSearchParams({ workflowName })}`),
|
||||
{ signal }
|
||||
)
|
||||
if (
|
||||
!Array.isArray(rows) ||
|
||||
(workflowName !== undefined && rows.some(row => row?.workflowName !== workflowName))
|
||||
)
|
||||
throw new Error('工作流记录无法核对,请刷新后再试。')
|
||||
return rows
|
||||
},
|
||||
/**
|
||||
* 用户确认后恢复创作;改写明确携带服务端要求的确认标记。
|
||||
* @param id 当前项目编号
|
||||
|
||||
@@ -134,13 +134,7 @@ const rules = computed(() => ({
|
||||
<template>
|
||||
<!-- 以下是新建剧本入口与从右侧展开的全屏抽屉模块 -->
|
||||
<NButton @click="open = true" type="primary"><Plus :size="16" />新建剧本</NButton>
|
||||
<AppDrawer
|
||||
v-model:open="open"
|
||||
title="新建剧本"
|
||||
description="从一个故事想法开始。提交后,先规划全剧故事,再编写分集剧本、生成角色设定与世界观,最后审核。"
|
||||
:busy="busy"
|
||||
class="create-project-drawer"
|
||||
>
|
||||
<AppDrawer v-model:open="open" title="新建剧本" :busy="busy" class="create-project-drawer">
|
||||
<AppForm
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
|
||||
@@ -64,7 +64,7 @@ async function remove() {
|
||||
<!-- 删除范围与后台任务状态属于同组,保持 8px 间距 -->
|
||||
<div class="space-y-2">
|
||||
<ContextNotice type="error" :show-icon="false">
|
||||
会永久删除这个项目的剧本、人物、场景、道具、形态、分镜、首帧、视频和制作记录,以及上传或生成的素材文件。
|
||||
永久删除项目及其剧本、分镜、素材、视频和任务记录。
|
||||
</ContextNotice>
|
||||
<ContextNotice v-if="readinessPending" type="info" :show-icon="false"
|
||||
>正在检查项目后台任务…</ContextNotice
|
||||
|
||||
@@ -73,7 +73,6 @@ async function save() {
|
||||
<AppDrawer
|
||||
v-model:open="open"
|
||||
:title="`编辑项目 · ${project?.title || project?.topic || ''}`"
|
||||
description="仅更新项目基础信息,不自动重生成剧本或制作资产。"
|
||||
:busy="state.pending"
|
||||
>
|
||||
<!-- 以下是保存失败提示模块 -->
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
<script setup lang="ts">
|
||||
import { NSkeleton } from 'naive-ui'
|
||||
import WorkspacePage from '../../../components/ui/WorkspacePage.vue'
|
||||
|
||||
/** 骨架与页面共用图库列宽和分镜分栏,可独立用于正文加载。 */
|
||||
defineProps<{
|
||||
/** 对应侧栏的当前工作区。 */
|
||||
variant: 'subject-images' | 'storyboard'
|
||||
/** 切换剧集时保留已有工具栏,只占满正文。 */
|
||||
bodyOnly?: boolean
|
||||
}>()
|
||||
|
||||
/** 用四条等高线表示卡片文字和操作。 */
|
||||
const galleryCaptionWidths = ['38%', '64%', '80%', '48%'] as const
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 以下是工具栏和正文的加载占位 -->
|
||||
<component
|
||||
:is="bodyOnly ? 'div' : WorkspacePage"
|
||||
v-bind="bodyOnly ? {} : { split: true, compact: true }"
|
||||
class="project-workspace-skeleton"
|
||||
:class="{ 'compact-shot-workspace': variant === 'storyboard' }"
|
||||
role="status"
|
||||
aria-busy="true"
|
||||
:aria-label="variant === 'subject-images' ? '正在读取形态图片' : '正在读取分镜设计'"
|
||||
>
|
||||
<template v-if="!bodyOnly" #header>
|
||||
<!-- 以下是与真实图库共用筛选栏布局的占位 -->
|
||||
<div v-if="variant === 'subject-images'" class="form-image-filter-region" aria-hidden="true">
|
||||
<div class="form-image-filters">
|
||||
<NSkeleton class="search-filter" :height="34" />
|
||||
<NSkeleton class="module-filter" :height="34" />
|
||||
<NSkeleton class="status-filter" :height="34" />
|
||||
<div class="form-image-display-controls">
|
||||
<NSkeleton v-for="index in 4" :key="index" :width="34" :height="34" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 以下是分镜剧集、统计和操作区占位 -->
|
||||
<div v-else class="workspace-toolbar" aria-hidden="true">
|
||||
<div class="toolbar-episode"><NSkeleton :height="34" /></div>
|
||||
<div class="toolbar-metrics">
|
||||
<NSkeleton :width="90" :height="14" />
|
||||
<NSkeleton :width="90" :height="14" />
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<NSkeleton :width="34" :height="34" />
|
||||
<NSkeleton :width="96" :height="34" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 以下是形态图库卡片骨架 -->
|
||||
<div v-if="variant === 'subject-images'" aria-hidden="true" class="form-image-grid gallery-loading-grid">
|
||||
<article v-for="index in 24" :key="index" class="panel form-image-card overflow-hidden">
|
||||
<!-- 以下是图库方形图片区占位 -->
|
||||
<div class="relative aspect-square">
|
||||
<NSkeleton class="absolute inset-0" width="100%" height="100%" />
|
||||
</div>
|
||||
<!-- 以下是等高、等间距的文字骨架 -->
|
||||
<div class="gallery-loading-caption grid gap-3 p-4">
|
||||
<NSkeleton v-for="width in galleryCaptionWidths" :key="width" :width="width" :height="12" />
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<!-- 以下是分镜目录、镜头摘要和标签骨架 -->
|
||||
<div v-else aria-hidden="true" class="storyboard-loading-grid">
|
||||
<div class="panel directory-panel storyboard-loading-directory">
|
||||
<div class="directory-heading">
|
||||
<NSkeleton :width="90" :height="16" />
|
||||
<NSkeleton :width="52" :height="12" />
|
||||
</div>
|
||||
<div v-for="index in 6" :key="index" class="storyboard-loading-beat grid gap-2 px-3.5 py-3">
|
||||
<NSkeleton :width="66" :height="12" />
|
||||
<NSkeleton :height="46" />
|
||||
<NSkeleton :height="46" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel grid min-w-0 content-start gap-5 p-5 lg:p-7">
|
||||
<NSkeleton :width="100" :height="12" />
|
||||
<NSkeleton :width="'min(100%, 210px)'" :height="22" />
|
||||
<NSkeleton :width="'90%'" :height="16" />
|
||||
<div class="flex flex-wrap gap-4">
|
||||
<NSkeleton v-for="index in 4" :key="index" :width="64" :height="24" />
|
||||
</div>
|
||||
<NSkeleton :width="'min(100%, 150px)'" :height="16" />
|
||||
<NSkeleton :width="'76%'" :height="16" />
|
||||
<div v-for="index in 5" :key="index" class="grid gap-3">
|
||||
<NSkeleton :width="84" :height="14" />
|
||||
<NSkeleton :width="'min(100%, 520px)'" :height="48" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
@reference "../../../styles/styles.css";
|
||||
/* 图库骨架和真实卡片使用同一响应式列宽。 */
|
||||
.form-image-grid {
|
||||
display: grid;
|
||||
--gallery-card-min-width: 260px;
|
||||
--gallery-gap: 12px;
|
||||
grid-template-columns: repeat(auto-fill, minmax(min(var(--gallery-card-min-width), 100%), 1fr));
|
||||
gap: var(--gallery-gap);
|
||||
}
|
||||
/* 图库筛选布局与加载占位共用宽度和断点。 */
|
||||
.gallery-sticky-controls > .form-image-filter-region {
|
||||
@apply my-0;
|
||||
}
|
||||
.form-image-filter-region {
|
||||
@apply my-3 p-3;
|
||||
/* 外层使用浅灰分组,输入与下拉恢复为表面色,避免同色后失去控件边界。 */
|
||||
--app-field: var(--app-surface);
|
||||
--app-field-hover: var(--app-surface);
|
||||
background: var(--app-subtle);
|
||||
container-type: inline-size;
|
||||
}
|
||||
.form-image-toolbar {
|
||||
@apply grid grid-cols-[minmax(0,_1fr)] items-center gap-y-3 gap-x-4;
|
||||
}
|
||||
.form-image-toolbar.has-impact-picker {
|
||||
@apply grid-cols-[auto_minmax(0,_1fr)];
|
||||
}
|
||||
.asset-impact-picker {
|
||||
@apply flex items-center gap-2 min-w-0;
|
||||
}
|
||||
.form-image-toolbar > * {
|
||||
@apply min-w-0;
|
||||
}
|
||||
.form-image-filters {
|
||||
@apply grid grid-cols-[minmax(200px,_360px)_152px_160px_auto] items-center gap-y-3 gap-x-4;
|
||||
}
|
||||
.form-image-filters > * {
|
||||
@apply min-w-0;
|
||||
}
|
||||
.filter-result-count {
|
||||
@apply justify-self-end text-muted text-xs whitespace-nowrap;
|
||||
}
|
||||
.form-image-display-controls {
|
||||
@apply flex items-center justify-self-end gap-4;
|
||||
}
|
||||
.gallery-layout-switch {
|
||||
@apply flex items-center gap-2;
|
||||
}
|
||||
/* 未选中的排版按钮与图库操作按钮共用浅灰底,同时不覆盖选中布局的绿色状态。 */
|
||||
.gallery-layout-switch .layout-option-button:not(.layout-option-active),
|
||||
.gallery-layout-switch .gallery-action-button {
|
||||
background: var(--app-control-hover);
|
||||
}
|
||||
@container (max-width: 1200px) {
|
||||
.form-image-toolbar.has-impact-picker {
|
||||
@apply grid-cols-[minmax(0,_1fr)];
|
||||
}
|
||||
}
|
||||
@container (max-width: 900px) {
|
||||
.form-image-filters {
|
||||
@apply grid-cols-[minmax(0,_1fr)_152px];
|
||||
}
|
||||
.status-filter {
|
||||
@apply col-start-1 row-start-2;
|
||||
}
|
||||
.form-image-display-controls {
|
||||
@apply col-start-2 row-start-2;
|
||||
}
|
||||
}
|
||||
@container (max-width: 460px) {
|
||||
.form-image-filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
/* 移动端固定为两行:搜索给类型选择让位,状态可收缩以优先保留四个完整操作按钮。 */
|
||||
.search-filter {
|
||||
flex: 1 1 calc(100% - 130px);
|
||||
min-width: 0;
|
||||
}
|
||||
.module-filter {
|
||||
flex: 0 0 120px;
|
||||
}
|
||||
.status-filter {
|
||||
flex: 0 1 110px;
|
||||
min-width: 90px;
|
||||
}
|
||||
.form-image-display-controls {
|
||||
flex: 1 0 152px;
|
||||
width: auto;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.filter-result-count {
|
||||
@apply hidden;
|
||||
}
|
||||
}
|
||||
.project-workspace-skeleton .form-image-filter-region {
|
||||
margin: 0;
|
||||
}
|
||||
.project-workspace-skeleton {
|
||||
container-type: inline-size;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.gallery-loading-grid,
|
||||
.storyboard-loading-grid {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.gallery-loading-grid {
|
||||
align-content: start;
|
||||
grid-auto-rows: max-content;
|
||||
}
|
||||
.storyboard-loading-grid > .panel {
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.project-workspace-skeleton .n-skeleton {
|
||||
--n-color-start: var(--app-border) !important;
|
||||
}
|
||||
.storyboard-loading-grid {
|
||||
display: grid;
|
||||
grid-template-columns: clamp(240px, 22%, 280px) minmax(0, 1fr);
|
||||
gap: var(--app-content-gap);
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.storyboard-loading-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
grid-template-rows: auto minmax(0, 1fr);
|
||||
}
|
||||
.project-workspace-skeleton .toolbar-episode > .n-skeleton,
|
||||
.project-workspace-skeleton .toolbar-actions > .n-skeleton {
|
||||
height: 44px !important;
|
||||
}
|
||||
.project-workspace-skeleton .toolbar-actions > .n-skeleton {
|
||||
width: 44px !important;
|
||||
}
|
||||
.storyboard-loading-beat:nth-child(n + 3) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,45 +1,120 @@
|
||||
import { computed, inject, type InjectionKey } from 'vue'
|
||||
import { computed, inject, ref, watch, type InjectionKey, type Ref } 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 type CheckpointWorkflow = 'create-drama' | 'breakdown'
|
||||
|
||||
/** 项目布局共享轻量读取,完整记录只有消费者进入时才加载。 */
|
||||
export function useProjectData(id: Ref<string>) {
|
||||
const query = useQuery(id, async (projectId, signal) => {
|
||||
const [project, checkpoints, stageReadiness] = await Promise.all([
|
||||
projectsApi.detail(projectId, signal),
|
||||
projectsApi.checkpoints(projectId, signal),
|
||||
projectsApi.stageReadiness(projectId, signal)
|
||||
])
|
||||
return { project, checkpoints, stageReadiness }
|
||||
})
|
||||
const project = computed<ProjectDetail | null>(() => query.data.value?.project ?? null)
|
||||
const checkpoints = computed<Checkpoint[]>(() => query.data.value?.checkpoints ?? [])
|
||||
/** 导航只消费当前项目的准入响应。 */
|
||||
const stageReadiness = computed(() => {
|
||||
const readiness = query.data.value?.stageReadiness
|
||||
return readiness?.projectId === id.value ? readiness : null
|
||||
})
|
||||
/** 同项目并发轻量刷新只采用最后一次请求。 */
|
||||
let readinessRefresh = 0
|
||||
/** 子页面完成当前步骤后调用,只刷新轻量项目状态与导航门禁。 */
|
||||
async function refreshStageReadiness() {
|
||||
const projectId = id.value
|
||||
const snapshot = query.data.value
|
||||
if (!projectId || snapshot?.project.id !== projectId) return
|
||||
const request = ++readinessRefresh
|
||||
const nextReadiness = await projectsApi.stageReadiness(projectId)
|
||||
if (
|
||||
request === readinessRefresh &&
|
||||
id.value === projectId &&
|
||||
query.data.value === snapshot &&
|
||||
nextReadiness.projectId === projectId
|
||||
/** 正式项目正文与导航条件分别读取。 */
|
||||
const projectQuery = useQuery(id, (projectId, signal) =>
|
||||
projectId ? projectsApi.detail(projectId, signal) : Promise.resolve(null)
|
||||
)
|
||||
const readinessQuery = useQuery(id, (projectId, signal) =>
|
||||
projectId ? projectsApi.stageReadiness(projectId, signal) : Promise.resolve(null)
|
||||
)
|
||||
/** 摘要失败会阻断写操作,但不阻塞工作区浏览。 */
|
||||
const summaryQuery = useQuery(id, (projectId, signal) =>
|
||||
projectId ? projectsApi.checkpointSummaries(projectId, signal) : Promise.resolve(null)
|
||||
)
|
||||
/** 当前项目已请求过的工作流,页面卸载时保留。 */
|
||||
const requested = ref<Partial<Record<CheckpointWorkflow, string>>>({})
|
||||
/** 页面与布局可能同时观察到同一个终态,只处理一次。 */
|
||||
const handledExecutions = new Map<string, Promise<void>>()
|
||||
watch(
|
||||
id,
|
||||
() => {
|
||||
requested.value = {}
|
||||
handledExecutions.clear()
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
|
||||
/**
|
||||
* 用项目编号作为查询键;离开项目会取消旧请求并清除旧结果。
|
||||
* @param workflow 当前工作流
|
||||
* @returns 完整记录及其独立查询状态
|
||||
*/
|
||||
function createCheckpointQuery(workflow: CheckpointWorkflow) {
|
||||
const key = computed(() => (requested.value[workflow] === id.value ? id.value : ''))
|
||||
return useQuery(key, (projectId, signal) =>
|
||||
projectId ? projectsApi.checkpoints(projectId, signal, workflow) : Promise.resolve(null)
|
||||
)
|
||||
query.data.value = { ...snapshot, stageReadiness: nextReadiness }
|
||||
}
|
||||
return { ...query, project, checkpoints, stageReadiness, refreshStageReadiness }
|
||||
/** 两个查询在布局生命周期内存活,同项目切页直接复用。 */
|
||||
const checkpointQueries = {
|
||||
'create-drama': createCheckpointQuery('create-drama'),
|
||||
breakdown: createCheckpointQuery('breakdown')
|
||||
}
|
||||
/** 只发布当前项目的正式数据。 */
|
||||
const project = computed(() => (projectQuery.data.value?.id === id.value ? projectQuery.data.value : null))
|
||||
const stageReadiness = computed(() =>
|
||||
project.value && readinessQuery.data.value?.projectId === id.value ? readinessQuery.data.value : null
|
||||
)
|
||||
/** 摘要未取得或刷新失败时禁止依赖其作出写入判断。 */
|
||||
const summaryBlocked = computed(
|
||||
() =>
|
||||
!project.value ||
|
||||
summaryQuery.data.value === null ||
|
||||
summaryQuery.loading.value ||
|
||||
!!summaryQuery.error.value
|
||||
)
|
||||
/** 页面外壳加载与错误不包含按需正文。 */
|
||||
const loading = computed(() => projectQuery.loading.value || readinessQuery.loading.value)
|
||||
const error = computed(() => projectQuery.error.value || readinessQuery.error.value || summaryQuery.error.value)
|
||||
|
||||
/**
|
||||
* 声明页面需要某个工作流的正文;重复声明不会发出新请求。
|
||||
* @param workflow 当前工作流
|
||||
* @returns 完整记录查询
|
||||
*/
|
||||
function useWorkflowCheckpoints(workflow: CheckpointWorkflow) {
|
||||
if (requested.value[workflow] !== id.value) requested.value[workflow] = id.value
|
||||
return checkpointQueries[workflow]
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入或任务终态后只刷新摘要和受影响的已加载正文。
|
||||
* @param workflow 受影响的工作流,没有对应正文时仅刷新摘要
|
||||
* @param projectId 操作开始时绑定的项目
|
||||
* @param executionKey 共享观察器使用的终态标识
|
||||
* @returns 本次刷新结束
|
||||
*/
|
||||
async function refreshWorkflow(workflow: CheckpointWorkflow | null, projectId = id.value, executionKey?: string) {
|
||||
if (!projectId || id.value !== projectId) return
|
||||
const existing = executionKey ? handledExecutions.get(executionKey) : undefined
|
||||
if (existing) return existing
|
||||
const update = Promise.all([
|
||||
summaryQuery.refresh(),
|
||||
workflow && requested.value[workflow] === projectId
|
||||
? checkpointQueries[workflow].refresh()
|
||||
: Promise.resolve()
|
||||
]).then(() => {})
|
||||
if (executionKey) handledExecutions.set(executionKey, update)
|
||||
await update
|
||||
}
|
||||
|
||||
/** 刷新工作区入口数据,不读取完整工作流历史。 */
|
||||
async function refresh() {
|
||||
await Promise.all([projectQuery.refresh(), readinessQuery.refresh(), summaryQuery.refresh()])
|
||||
}
|
||||
|
||||
return {
|
||||
project,
|
||||
projectQuery,
|
||||
stageReadiness,
|
||||
readinessQuery,
|
||||
summaryQuery,
|
||||
summaryBlocked,
|
||||
loading,
|
||||
error,
|
||||
refresh,
|
||||
refreshProject: projectQuery.refresh,
|
||||
refreshStageReadiness: readinessQuery.refresh,
|
||||
useWorkflowCheckpoints,
|
||||
refreshWorkflow
|
||||
}
|
||||
}
|
||||
|
||||
/** 项目布局向子页面提供的类型安全上下文。 */
|
||||
|
||||
Reference in new issue
Block a user