81 lines
4.8 KiB
TypeScript
81 lines
4.8 KiB
TypeScript
/**
|
||
* 导航表:侧栏两级菜单的唯一来源(一级 = 全局三项 + 项目环节,二级 = 七个环节)。
|
||
*
|
||
* 为什么不是 zustand:这张表是静态表不是状态。加一个项目环节 = 这里加一行
|
||
* + `app/router.tsx` 加一条子路由(含 handle 标题),两边顺序保持一致即可。
|
||
*
|
||
* 内容页不做多页签(产品口径),所以这里不再伺候外壳的页签条;
|
||
* 页面内部的页签(kit 的 <Tabs>)自己带 items,不从这里取。
|
||
*
|
||
* 图标:一律取自 components/icons(全站唯一的图标登记表,背后是 Ant Design
|
||
* 官方图标库)。以前全站是 60 多个 Unicode 字符(⌂ ✧ ◫ ✕ ⏻ …),粗细由字体
|
||
* 决定、颜色由文字继承,同一个「关闭」在三个地方是三种粗细。
|
||
*
|
||
* 本轮重设计换掉了侧栏里四枚图形,理由都写在登记表对应那一行旁边,这里只记结论:
|
||
* 项目总览 Appstore(四方块) → Project(看板格) —— 原来和「资产管理」的素材墙撞脸
|
||
* 资产管理 FolderOpen(文件夹) → Appstore(方块) —— 原来和父级「项目环节」上下同图
|
||
* 质检审核 Audit(夹板) → SafetyCertificate(盾牌) —— 夹板的勾在 14px 下糊成一块板
|
||
* 时间线 NodeIndex(节点连线) → Scissor(剪刀) —— 节点连线读不出「剪辑」
|
||
* 尺寸也不由这里写:菜单图标走 Menu 的 iconSize token(16),按钮图标走
|
||
* Button 的 onlyIconSize(继承字号)——antd 已经各定过一档。
|
||
*/
|
||
import type { ReactNode } from 'react'
|
||
import {
|
||
IconApi, IconBolt, IconDashboard, IconDownload, IconGrid,
|
||
IconLibrary, IconProjects, IconShield, IconStoryboard, IconTimeline
|
||
} from '../../components/icons'
|
||
|
||
export type NavItem = {
|
||
/** 全局项是固定路径;项目项给 (projectId) => 路径 */
|
||
to: string | ((id: string | number) => string)
|
||
icon: ReactNode
|
||
label: string
|
||
hint: string
|
||
}
|
||
|
||
/** 全局三项:不依赖项目 */
|
||
export const globalNav: NavItem[] = [
|
||
{ to: '/', icon: <IconProjects />, label: '项目总览', hint: '所有项目的进度与全局动态' },
|
||
{ to: '/assets', icon: <IconLibrary />, label: '平台资产库', hint: '人物 / 场景 / 声线母版' },
|
||
{ to: '/models', icon: <IconApi />, label: '模型管理中心', hint: '大模型 / 视频 / 图像 / 声音' }
|
||
]
|
||
|
||
/** 项目的七个环节:顺序就是流程顺序,别按字母排。侧栏只放环节名,不放项目名 */
|
||
export const projectModules: NavItem[] = [
|
||
{ to: (id) => `/projects/${id}/overview`, icon: <IconDashboard />, label: '流程概览', hint: '总控台 / 全节点进度' },
|
||
{ to: (id) => `/projects/${id}/library`, icon: <IconGrid />, label: '资产管理', hint: '人物 / 声音 / 场景' },
|
||
{ to: (id) => `/projects/${id}/storyboard`, icon: <IconStoryboard />, label: '分镜与脚本', hint: '镜头 / 关键帧 / 提示词' },
|
||
{ to: (id) => `/projects/${id}/dispatch`, icon: <IconBolt />, label: '任务调度中心', hint: '队列 / 执行 / 重试 / 并发' },
|
||
{ to: (id) => `/projects/${id}/review`, icon: <IconShield />, label: '质检与审核', hint: '质检 + 人工审核' },
|
||
{ to: (id) => `/projects/${id}/timeline`, icon: <IconTimeline />, label: '时间线合成', hint: '片段 / 配音 / 字幕' },
|
||
{ to: (id) => `/projects/${id}/delivery`, icon: <IconDownload />, label: '导出与成本', hint: '成片 / 成本台账' }
|
||
]
|
||
|
||
/** 项目 id 从 /projects/123/... 里取;取不到就是 0(此时项目路径表整体不命中) */
|
||
export function projectIdOf(pathname: string): string {
|
||
const m = /^\/projects\/(\d+)/.exec(pathname)
|
||
return m ? m[1] : ''
|
||
}
|
||
|
||
/** 菜单项的 key 就是路径:这样 selectedKeys 与 navigate 同一个值,不用再维护第二份 id */
|
||
export const pathOf = (item: NavItem, projectId: string): string =>
|
||
typeof item.to === 'string' ? item.to : projectId ? item.to(projectId) : ''
|
||
|
||
/**
|
||
* 路由 → 菜单项(页头用它反查图标,见 components/ui/Page.tsx 的 PageHead)。
|
||
*
|
||
* 症状(2026-11 第十二轮 · 用户第 1 条「标题前一个和左侧菜单一致的图标」):
|
||
* 页头如果要显示图形,就得在页面里再 import 一次图标——同一个位置两份登记,
|
||
* 换菜单图形时页头必然忘(上一版眉标那枚图标就是这么和侧栏对不上号的)。
|
||
* 做法:反查这张导航表本身。菜单和页头读同一个 ReactNode,物理上不可能不一致。
|
||
* 不在菜单里的路由(/account、/admin/users、/help)返回 null,页面自己传 icon。
|
||
*/
|
||
export function navItemAt(pathname: string): NavItem | null {
|
||
const clean = pathname.replace(/\/+$/, '') || '/'
|
||
const hit = globalNav.find((m) => m.to === clean)
|
||
if (hit) return hit
|
||
const pid = projectIdOf(clean)
|
||
if (!pid) return null
|
||
return projectModules.find((m) => pathOf(m, pid) === clean) ?? null
|
||
}
|