209 lines
11 KiB
TypeScript
209 lines
11 KiB
TypeScript
/**
|
||
* 「项目概况」抽屉:项目身份 + 指标 + 流程 + 七站跳转 + 项目级操作,全部收在一处。
|
||
*
|
||
* 症状(2026-11 第十一轮 · 用户第 2 条原话「项目总览、展开、归档(删除)和顶部系统
|
||
* Header 的项目总览应该整合到一处…点击展开侧面的面板,把项目概况、操作按钮都放到
|
||
* 那个对应的面板中」「要进一步把各级的信息归拢并提供交互的层次清晰」):
|
||
* 项目身份在**同一屏说了三遍**——顶栏那颗胶囊(名称·状态·进度·当前节点)、
|
||
* 外壳那条面包屑工具条(项目名 + 镜头/合格/任务/成本 + 展开概况 + 删除项目)、
|
||
* 概览页的「流程概览」页头(归档项目);而 4 张指标卡 + 12 节点流程条坐在正文上方,
|
||
* 每个环节页都要先滚过这两屏才看到自己真正的内容。层级也是乱的:
|
||
* 「项目级」的操作(归档 / 删除)出现在「页面级」的位置上。
|
||
* 做法:四级层次各归各位——
|
||
* ① 顶栏控制台 = 唯一的项目身份入口(点击展开本抽屉,不再跳页);
|
||
* ② 本抽屉 = 项目层(身份回显 / 指标 / 流程 / 七站跳转 / 归档 / 删除);
|
||
* ③ PageHead = 内容层门牌卡(每站一张带底纹的卡,见 components/ui/Page.tsx);
|
||
* ④ Panel = 内容层。于是工作台外壳可以一行可见块都不渲染(见 pages/ProjectDetail.tsx)。
|
||
* 为什么用右侧抽屉而不是弹窗:这是「随时查一眼项目全局」的辅助面板,
|
||
* 遮罩之下正文还在原地,关掉就回到刚才那一站,不需要重新载入。
|
||
* 数据一律读 useProjectStore(外壳每 6 秒轮询),这里不发第二个请求。
|
||
*/
|
||
import { useState } from 'react'
|
||
import { useLocation, useNavigate } from 'react-router-dom'
|
||
import { Flex, Grid } from 'antd'
|
||
import * as api from '../../api/client'
|
||
import { fmtMoney, fmtTime, pct, statusLabel } from '../../lib/format'
|
||
import { moduleState } from '../../lib/pipeline'
|
||
import {
|
||
Button, Drawer, ErrorText, Info, Notice, PageStack, Panel,
|
||
Stat, StatGrid, Status, Tag, Value, type TagTone
|
||
} from '../../components/ui'
|
||
import { WorkflowBar } from '../../components/media/WorkflowBar'
|
||
import {
|
||
IconChart, IconClose, IconDelete, IconFolder, IconBolt, IconClock,
|
||
IconProjects, IconSync, IconTracks
|
||
} from '../../components/icons'
|
||
import { pathOf, projectModules, type NavItem } from './nav'
|
||
import { refresh, useProjectStore } from '../../stores/project'
|
||
import { notify } from '../../stores/notice'
|
||
|
||
/** 环节汇总状态 → 标签(口径与 lib/pipeline 的节点状态一致,只是从 12 个节点折成 7 站) */
|
||
const MODULE_TAG: Record<string, { label: string; tone: TagTone }> = {
|
||
done: { label: '已完成', tone: 'ok' },
|
||
active: { label: '进行中', tone: 'accent' },
|
||
failed: { label: '需处理', tone: 'bad' },
|
||
pending: { label: '待处理', tone: 'default' }
|
||
}
|
||
|
||
/** 环节项 → 路由最后一段(NODE_MODULE 的取值口径就是它) */
|
||
const slugOf = (m: NavItem): string => pathOf(m, '0').split('/').pop() || ''
|
||
|
||
export function ProjectBriefDrawer({ open, onClose, projectId }: {
|
||
open: boolean
|
||
onClose: () => void
|
||
projectId: string
|
||
}) {
|
||
const navigate = useNavigate()
|
||
const location = useLocation()
|
||
/* 抽屉宽度是 min(620, 100vw-32):手机上是 398,回显表两列会把「分辨率 / 帧率」
|
||
这种标签挤到折行,所以列数跟着视口降档。antd Descriptions 要求每行的 span 之和
|
||
等于 column,简介那条通栏的 span 也必须跟着算——写死 span:2 在单列下会报
|
||
「Sum of column span in a line not match column」。 */
|
||
const twoCol = !!Grid.useBreakpoint().sm
|
||
const [busy, setBusy] = useState(false)
|
||
const [confirming, setConfirming] = useState(false)
|
||
const [error, setError] = useState('')
|
||
const project = useProjectStore((s) => s.project)
|
||
const workflow = useProjectStore((s) => s.workflow)
|
||
const stats = useProjectStore((s) => s.stats)
|
||
const loadedId = useProjectStore((s) => s.loadedId)
|
||
/* 认「加载成功的那份数据自己的 id」,不认路由号:口径见 stores/project.ts 的 loadedId */
|
||
const proj = projectId && loadedId === Number(projectId) ? project : null
|
||
const st = stats || {}
|
||
const isArchived = proj?.status === 'archived'
|
||
const curSlug = slugOf(projectModules.find((m) => pathOf(m, projectId) === location.pathname) || projectModules[0])
|
||
|
||
function go(to: string) {
|
||
onClose()
|
||
navigate(to)
|
||
}
|
||
|
||
async function run(fn: () => Promise<void>) {
|
||
setBusy(true)
|
||
setError('')
|
||
try { await fn() } catch (exc: any) { setError(exc?.message || String(exc)) } finally { setBusy(false) }
|
||
}
|
||
|
||
const setArchived = (on: boolean) => run(async () => {
|
||
await api.patch(`/api/projects/${projectId}`, { status: on ? 'archived' : 'draft' })
|
||
notify(on ? '项目已归档,不再自动推进流程' : '已取消归档,流程状态按镜头真实进度重算')
|
||
await refresh()
|
||
})
|
||
|
||
const removeProject = () => run(async () => {
|
||
await api.del(`/api/projects/${projectId}`, { purge_files: true })
|
||
navigate('/')
|
||
})
|
||
|
||
const taskHint = Object.entries<any>(st.task_status || {}).map(([k, v]) => `${statusLabel(k)} ${v}`).join(' · ')
|
||
const nextStep = workflow.find((s: any) => s.state === 'active' || s.state === 'failed')
|
||
|
||
return (
|
||
<Drawer open={open} onClose={onClose} label="项目概况" destroyOnHidden
|
||
loading={!proj}
|
||
width="min(620px, calc(100vw - 32px))"
|
||
title={proj?.name || `项目 #${projectId}`}
|
||
sub={proj ? `${statusLabel(proj.status)} · 流程 ${pctDone(workflow)} · ${proj.resolution || '—'} / ${proj.aspect_ratio || '—'}` : '项目概况'}
|
||
actions={<>
|
||
<Button type="text" className="mr-auto" icon={<IconProjects />} onClick={() => go('/')}>
|
||
返回项目总览
|
||
</Button>
|
||
<Button disabled={busy} icon={isArchived ? <IconSync /> : <IconFolder />}
|
||
title="归档后后端不再自动推进流程节点;取消归档后按镜头真实进度重算"
|
||
onClick={() => void setArchived(!isArchived)}>
|
||
{isArchived ? '取消归档' : '归档项目'}
|
||
</Button>
|
||
{confirming && (
|
||
<Button disabled={busy} icon={<IconClose />} onClick={() => setConfirming(false)}>取消</Button>
|
||
)}
|
||
<Button type="primary" danger disabled={busy} icon={<IconDelete />}
|
||
title={confirming ? '分镜、任务与已生成素材一起清除,不可恢复' : '删除整个项目'}
|
||
onClick={() => { if (confirming) void removeProject(); else setConfirming(true) }}>
|
||
{confirming ? '确认删除' : '删除项目'}
|
||
</Button>
|
||
</>}>
|
||
{/* 正文没到之前由 Drawer 的 loading 出骨架(阶段 4):这里只渲染有数据的那一支 */}
|
||
{proj && (
|
||
<PageStack>
|
||
<ErrorText>{error}</ErrorText>
|
||
|
||
<Panel size="small" title="项目身份"
|
||
extra={<Status value={proj.status} />}>
|
||
<Info className="mb-0" column={twoCol ? 2 : 1} items={[
|
||
{ label: '画幅', value: proj.aspect_ratio || '—' },
|
||
{ label: '分辨率 / 帧率', value: `${proj.resolution || '—'} · ${proj.fps || '—'}fps` },
|
||
{ label: '题材', value: proj.genre || '—' },
|
||
{ label: '目标时长', value: `${proj.target_duration ?? '—'}s` },
|
||
{ label: '默认模型', value: proj.default_provider ? `${proj.default_provider}/${proj.default_model || '—'}` : '未指定' },
|
||
{ label: '创建时间', value: fmtTime(proj.created_at) },
|
||
{ label: '简介', value: proj.description || '—', span: twoCol ? 2 : 1 }
|
||
]} />
|
||
</Panel>
|
||
|
||
<StatGrid cols={2}>
|
||
<Stat icon={<IconTracks />} label="镜头(合格/总数)"
|
||
value={<>{st.shots_approved || 0}<i>/ {st.shots || 0}</i></>}
|
||
hint={`驳回 ${st.shots_rejected || 0} · 合格进度 ${pct(st.progress_ratio)}`} />
|
||
<Stat icon={<IconClock />} label="时长(计划/已生成)"
|
||
value={<>{(st.planned_duration || 0).toFixed(1)}s<i>/ {(st.generated_duration || 0).toFixed(1)}s</i></>}
|
||
hint={taskHint || '暂无任务'} />
|
||
<Stat icon={<IconBolt />} label="任务(活跃/总数)"
|
||
value={<>{st.tasks_active || 0}<i>/ {st.tasks || 0}</i></>}
|
||
hint={taskHint || '暂无任务'} />
|
||
<Stat icon={<IconChart />} label="成本 / 成片"
|
||
value={fmtMoney(st.cost?.total_cost, st.cost?.currency)}
|
||
hint={`${(st.exports || []).length} 个导出记录`} />
|
||
</StatGrid>
|
||
|
||
<Panel size="small" title="流程进度"
|
||
extra={nextStep ? <Value>下一步:{nextStep.label}</Value> : <Value>全部 {workflow.length} 个节点已完成</Value>}>
|
||
<WorkflowBar workflow={workflow} compact />
|
||
</Panel>
|
||
|
||
<Panel size="small" title="项目环节"
|
||
sub="点一行直接跳到对应环节。">
|
||
<Flex vertical gap={2}>
|
||
{projectModules.map((m, i) => {
|
||
const slug = slugOf(m)
|
||
const tag = MODULE_TAG[moduleState(workflow, slug)] || MODULE_TAG.pending
|
||
const isCur = slug === curSlug
|
||
return (
|
||
<Button key={slug} type="text" block className="nex-brief-row"
|
||
title={m.hint} onClick={() => go(pathOf(m, projectId))}>
|
||
<Flex component="span" align="center" gap={8} className="w-full min-w-0">
|
||
<span className="nex-brief-mark">{m.icon}</span>
|
||
<span className="min-w-0 truncate text-xs font-semibold">
|
||
{i + 1}. {m.label}
|
||
</span>
|
||
<span className="ms-auto flex-none">
|
||
{isCur
|
||
? <Tag tone="accent">当前</Tag>
|
||
: <Tag tone={tag.tone}>{tag.label}</Tag>}
|
||
</span>
|
||
</Flex>
|
||
</Button>
|
||
)
|
||
})}
|
||
</Flex>
|
||
</Panel>
|
||
|
||
{confirming && (
|
||
<Notice danger onClose={() => setConfirming(false)}>
|
||
删除《{proj.name}》会同时清除分镜、任务与已生成素材,且不可恢复。
|
||
</Notice>
|
||
)}
|
||
</PageStack>
|
||
)}
|
||
</Drawer>
|
||
)
|
||
}
|
||
|
||
/** 轨道百分比:与顶栏控制台同一个算法(已完成节点 / 全部节点),不用后端的镜头合格率 */
|
||
function pctDone(nodes: any[]): string {
|
||
const total = nodes.length
|
||
if (!total) return '流程未生成'
|
||
return `${Math.round((nodes.filter((n: any) => n.state === 'done').length / total) * 100)}%`
|
||
}
|
||
|
||
export default ProjectBriefDrawer
|