nex_animation/frontend/src/components/ui/Page.tsx

365 lines
20 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 页面级骨架(旧全局样式里的 header / .row / .between / .error / .sub / .layout)。
*
* 这些不是"组件"那么重,但 13 个页面每一页都要用;写成一处的意义和
* UI规范第二章一样:同一层级的东西在所有页面上量出来必须是同一个数。
* 页面里再出现 <header className="flex justify-between…"> 就算抄回去了一遍。
*
* 症状(2026-11 第三轮重写的对象):原子控件与卡片已经换成 antd,这一层却还是
* div + Tailwind——页头的大标题是自搓 <h1>(字号跟 theme 里的 fontSizeHeading1
* 没关系)、两栏正文写死 `grid-cols-[minmax(0,1.5fr)_minmax(300px,0.8fr)]`
* 加一个私有断点 `max-xl`。于是 Card 按 antd 断点换列、正文按私有宽度换列,
* 同一屏里两套栅格各排各的,页面看着"控件是 antd 的、版面不是"。
* 做法:骨架也交给 antd——页头 = Flex + Typography.Title,
* 横排 = Flex,分节线 = Divider,两栏 = Row + Col(断点只有 antd 的 xs…xxl,
* 换算见 grid.tsx)。页面继续写 <PageHead/> <Layout> <Stack>,名字不变。
* 为什么 kit 的 Row 不改成 antd Row:kit 的 <Row> 语义是"一排会折行的控件"
* (26 处调用),antd Row 是 24 等分栅格,两者不是一个东西;
* 这里把 antd 的那对引进来叫 AntRow/AntCol,铺列由本文件的 Layout 负责。
*/
import { type CSSProperties, type ReactNode } from 'react'
import { useNavigate } from 'react-router-dom'
import { Avatar, Breadcrumb as AntBreadcrumb, Col as AntCol, Divider, Flex, Row as AntRow, Typography } from 'antd'
import { cn } from '../../lib/cn'
import { LAYER } from '../../lib/layers'
import { ActionGroup } from './Ctlbar'
import { Clamp } from './Table'
import { Panel } from './Panel'
import { splitSpans, type GridCollapse } from './grid'
/** 次要说明文字(.muted):11px + 最淡的一级灰,表格单元格的第二行、附注都用它 */
export const MUTED = 'text-text-quaternary text-xs'
/** 等宽小字(.mono):路径 / id / 枚举码 / 数值列 */
export const MONO = 'font-mono text-xs '
/** 弱化 + 等宽(.muted.mono):id、路径、枚举码 */
export const MUTED_MONO = `${'text-text-quaternary'} ${MONO}`
/**
* 站内文字链配色(.link):<Link> 没有组件形态,用这个类名常量保持一致。
* 用 text-primary(=antd 的 colorLink 默认就等于 colorPrimary)而不是 text-success:
* 绿色那一族在站内只有一个含义——「这件事成功了」(Tag ok / 流程 done),
* 上一版让它兼职当链接色,于是「完成」和「可点」是同一个颜色,
* 换成标准蓝以后两者各归各位:链接=主色,状态=语义色。
*/
export const LINK_CLS = 'text-primary text-xs no-underline hover:underline'
/**
* 板块标记(自绘那个 45px 渐变方块 + 一层 glow)= antd Avatar 的方形档。
*
* 症状:项目总控台左上角的「N」自己写了 w-[45px] h-[45px] rounded-lg + 渐变
* + shadow,尺寸、圆角、字号三处都不在 theme 里,深色主题下那圈 glow 还会糊成脏块。
* 做法:方形 Avatar 走 antd 的 sizeStep 与 borderRadius,底色取 colorPrimary,
* 文字颜色取 colorTextLightSolid——换主题两样都自己跟着翻。
* 为什么留一个方块而不是删掉:它是这一整块的识别物(总控台 = N),
* 删了以后卡头只剩一行字,和站内其他卡头分不出主次。
*/
export function Mark({ children, size = 40, className, style }: {
children: ReactNode; size?: number; className?: string; style?: CSSProperties
}) {
return (
<Avatar shape="square" size={size} className={cn('nex-mark !flex-none !font-bold', className)}
style={{ background: 'var(--ant-color-primary)', color: 'var(--ant-color-text-light-solid)', ...style }}>
{children}
</Avatar>
)
}
/**
* 正文分节标题 = antd Typography.Title(level 1…5)。
*
* 症状:站内「这一节叫什么」写过四种尺子——手册自带 TAG_H1/H2/H3 三套
* (30 / 18 / 16px + tracking-tight,都不在 theme 的 fontSizeHeading* 里)、
* 仪表盘的建项目卡写裸 <h3 className="mb-3">、用户管理弹窗写裸 <h3>、
* 模型管理中心的卡头再写一套 <h3 className="text-sm font-semibold">。
* 同一层级的标题在四处长得都不一样,屏幕阅读器的大纲也是乱的。
* 做法:只留 level 一个参数,字号 / 行高 / 字重 / 颜色交给 antd 的标题档
* (theme 里的 fontSizeHeading1…5),页面不再自己写 text-lg font-bold。
* 为什么不是 PanelHead:PanelHead 是「卡片头」(带右端动作、坐在卡里),
* Heading 是「正文里的一节」——手册、抽屉正文、弹窗正文都属于后者。
*/
export function Heading({ level = 2, children, id, className, title }: {
level?: 1 | 2 | 3 | 4 | 5; children: ReactNode
/** 锚点 id:手册的目录靠它跳转 */
id?: string; className?: string; title?: string
}) {
return (
<Typography.Title level={level} id={id} title={title}
className={cn('!mb-2 !mt-4 min-w-0 first:mt-0', className)}>{children}</Typography.Title>
)
}
/**
* 正文段落 = antd Typography.Paragraph。
*
* 症状:手册整页的正文写死 `text-sm text-text-quaternary leading-loose`,
* 与 antd 正文(14px / 1.5714 / colorText)差了 5px 行高和两级灰度;
* 同一篇说明写在手册里是 12px 灰字、写进抽屉里是 14px 黑字。
* 做法:段落只有这一种实现,字号、行高、颜色全走 antd 排版档;
* 需要更弱一档的说明文字用 <Value>,不要再造第三种。
*/
export function Paragraph({ children, className }: { children: ReactNode; className?: string }) {
return <Typography.Paragraph className={cn('min-w-0 wrap-anywhere', className)}>{children}</Typography.Paragraph>
}
/** 行内代码 = antd Typography.Text code(自带描边底纹,不再手写 rounded-sm border px-1) */
export function Code({ children, className }: { children: ReactNode; className?: string }) {
return <Typography.Text code className={className}>{children}</Typography.Text>
}
/** 命令 / 配置块 = antd 的 code 皮肤 + 横向滚动(手册里的 shell 片段) */
export function CodeBlock({ children, className }: { children: ReactNode; className?: string }) {
return (
<Typography.Paragraph code className={cn(
'block overflow-x-auto whitespace-pre scrollbar-slim', className)}>{children}</Typography.Paragraph>
)
}
/** 窄屏时把只读补充条撑满一行,让两三枚胶囊不会挤成一团中文碎渣 */
const WRAP_ACTIONS = 'max-lg:w-full max-lg:[&>button]:flex-1'
/**
* 页头主操作在窄屏的宽度:整组满宽,装不下整组时交给 `ActionGroup` 的自动档。
* ⚠ 这里不能再写 `max-lg:[&>button]:flex-1`:`useAutoStack` 的自然宽度只在
* 「子项都按内容定尺」时量得到(`natural()` 见到 flex-grow>0 直接返回 0),
* 等分一挂上自动档就永远认为「量不到」→ 三颗主操作在窄屏折成 2 + 1,
* 正是闸门 `btnrowcheck.BTNROWS` 点名的破法(第 17 轮实测 576 档 2 + 1、430 档三行)。
*/
const HEAD_ACTIONS = 'max-lg:w-full'
/**
* 内容页页头 = **一张带主色底纹的「门牌卡」**,全站唯一实现(旧 NodeHead 已并进这里)。
*
* 症状(2026-11 第十二轮 · 用户原话「内容页 Header 重写,只保留节点名(1 级标题)+
* 描述说明。标题前一个和左侧菜单一致的图标。右侧的主功能入口要对齐」):
* ① 页头有三行字——眉标「项目环节 · 第 N / 7 站 · 流程概览」、大标题、职责说明。
* 眉标和标题讲的是同一件事(这一站叫什么),站次在侧栏高亮项、顶栏流程条、
* 项目概况抽屉里又各说了一遍(R18:每一级的信息只在该级说一遍);
* ② 眉标那枚图标孤零零在第一行左端,离标题隔了一整行,对不上「这图形=菜单里那项」;
* 第十四轮(用户原话「不要图标」+ 门牌截图):反查菜单图形那一层整层删掉——
* 标题左侧带底色的方块的语义是「图标 = 这一站」,但它和左栏高亮项说的是同一句话,
* 门牌里再摆一次就是给同一信息配第二个视觉锚点(R18),而且这块主色方块
* 紧接着下面卡头的品牌 N、统计卡的色块,一屏三颗同形状的方块互相抢注意力。
* ③ 右端动作挂在**整块页头**的垂直中线上,七站的说明有长有短、有的两行有的一行,
* 主按钮在每一页的 y 都不一样,概览页没有动作时那条中线还是空的。
* 做法:页头只留两层,第一行横向排满——
* 第一行 = 一级标题 +(右端)整页成立的主操作;
* 第二行 = 一句话职责说明(以及 meta 那种只读补充),横跨整行。
* 第一行高度钉在 controlHeight,主操作与它垂直居中、右缘贴卡内边距——
* 七站的「新建 / 入队 / 批量放行 / 开始导出」因此必然落在同一条水平线上。
* 标题左缘 = 卡内边距 = 下面每一张卡正文的左缘:门牌与正文同一条竖线对齐,
* 这件事在没有图标之前做不到(图标方块把标题整体右推 42px)。
* 为什么仍然是一张卡(2026-11 第十一轮的口径不变):页头与正文卡之间只有 16px 空白时,
* 它读起来像「正文上面漏了半句话」;主色底纹 + 主色描边让它是全站唯一带主色
* 描边的卡,一眼就是「这一层的门牌」,主次不靠字号硬撑。
* 分工(UI规范 §2):PageHead 只放**整页成立**的动作(新建、入队、批量放行、开始导出);
* PanelHead 只放**离开这一块就不成立**的动作;Tabs 右端不放按钮。
* 窄屏:标题行与动作组各自满宽;整组横排连一整行都放不下时由 `ActionGroup`
* 翻成**竖排等宽**(换行的是整组,不是组里少一颗),说明仍在最下面一行。
*/
export function PageHead({ title, sub, meta, actions, className }: {
title?: ReactNode
/** 标题下方的一句话职责说明(12px 次要色,最宽 72ch) */
sub?: ReactNode
/** 说明之上再加一排只读补充(手册页的特性标签);没有就不占行 */
meta?: ReactNode
/** 右端主操作:与标题同排、整体右对齐;窄屏整组满宽、按钮等分 */
actions?: ReactNode
className?: string
}) {
return (
<Panel size="small" className={cn('nex-pagehead min-w-0', className)}>
<Flex wrap align="center" justify="space-between" gap={12} className="min-w-0">
{/* 标题行里没有图形(第十四轮「不要图标」):只留一级标题,左缘就是卡内边距 */}
<Flex align="center" gap={10} wrap className="nex-pagehead-title min-w-0 flex-1 max-lg:w-full">
<Typography.Title level={3} className="!mb-0 !min-w-0">{title}</Typography.Title>
</Flex>
{/* 自动档开着(第 17 轮):满宽那一行仍放不下整组时,ActionGroup 把这几颗
主操作翻成竖排等宽,读者看到的始终是「一整组」,不是 2 + 1 */}
{actions && <ActionGroup className={HEAD_ACTIONS}>{actions}</ActionGroup>}
{/* 说明行 w-full:它必然掉到第二行,主操作因此永远和标题同一排 */}
{(meta || sub) && (
<Flex vertical gap={6} className="w-full min-w-0">
{meta && <Row className={WRAP_ACTIONS}>{meta}</Row>}
{sub && (
<Typography.Text type="secondary"
className="!mb-0 block max-w-[72ch] text-xs leading-relaxed">{sub}</Typography.Text>
)}
</Flex>
)}
</Flex>
</Panel>
)
}
/**
* 面包屑 = antd Breadcrumb(层级导航的唯一实现)。
*
* 症状:项目子页顶部写着「← 项目总览 + 状态 Tag + 当前节点 Tag」,
* 这三样在应用顶栏的流程控制台里全都有,等于同屏两遍项目信息。
* 做法:外壳只留一条面包屑(项目总览 / 项目名)表达「我在哪个项目里」,
* 状态、进度、当前节点交给顶栏那一条,页面不再重复。
* 为什么 items 收字符串/对象而不是 ReactNode:页面不能 import antd(规范 R8),
* 跳转由组件内部 useNavigate 完成,页面只给 { label, to }。
*/
export function Breadcrumb({ items, className }: {
items: { label: ReactNode; to?: string }[]
className?: string
}) {
const navigate = useNavigate()
return (
<AntBreadcrumb className={cn('min-w-0', className)}
items={items.map((it) => ({
key: String(it.to ?? it.label),
title: it.to
? <a onClick={(e) => { e.preventDefault(); navigate(it.to!) }}>{it.label}</a>
: <span className="min-w-0 truncate">{it.label}</span>
}))} />
)
}
/**
* 页面级工具条 = **只有卡头的那张 Card**(antd Card title + extra)。
*
* 症状(体检截图里到处可见的那排「悬浮在页面底色上的东西」):质检页的六个计数 + 三颗按钮、
* 调度页的「任务执行:…」Tag + 忙闲、时间线页的「时间线版本 0 + 下拉 + 两颗按钮」、
* 分镜页吸顶那一横条——它们都不属于任何卡片,页面就用 <Between>/<div border> 裸排在
* 页面底色上。于是这一排没有容器、没有左右内边距、没有基线:Tag 31px、按钮 32、
* 下拉 24、自绘条 padding 16,四种高度贴在一起,看起来永远差一点没对齐。
* 做法:工具条也是一张卡,只是它只有卡头。左端 = 说明/计数(Card 的 title 槽,
* 用 <Value> 写就是 12px 次要文字),右端 = 动作(Card 的 extra 槽,K1 之后
* 自带 wrap + gap + 垂直居中)。卡片头自带的分隔线、内边距、最小高度全都成立,
* 页面不再需要 padding/border/圆角这三个类名。
* 为什么不用 antd Flex 直接铺:Flex 只解决「一排」,不解决「这一排坐在哪」——
* 站内一切有边框的横块都是 Card(规范 §3),工具条不该是第七种容器。
*/
export function Toolbar({ info, sub, actions, className, sticky }: {
/** 左端主句:标题或一句摘要(渲染在卡头标题槽里) */
info?: ReactNode
/** 左端第二行:只读计数 / 状态 Tag 组(渲染在卡头 sub 槽,12px 次要文字) */
sub?: ReactNode
/** 右端:动作按钮组 / 视图切换(自动右靠、折行、等高) */
actions?: ReactNode
className?: string
/** 吸顶:贴在应用顶栏下沿(分镜工作台那种「工具永远够得到」的横条) */
sticky?: boolean
}) {
return (
/* z-40 → LAYER.toolbar:全局层只从 lib/layers.ts 取值(UI规范.md §10 的层级表) */
<Panel pad={false} className={cn(sticky && 'sticky top-(--nex-bar)', className)}
style={sticky ? { zIndex: LAYER.toolbar } : undefined}
title={info} sub={sub} extra={actions} />
)
}
/** 通用横排(.row):窄屏自动折行,同行控件等高由 antd 的 controlHeight 三档保证 */
export function Row({ children, className, tight, gap }: {
children?: ReactNode; className?: string; tight?: boolean
/** 覆盖默认 8px 行内间距(卡头这类要贴紧/拉开一点的位置) */
gap?: number
}) {
return (
<Flex wrap align="center" gap={gap ?? (tight ? 6 : 8)} className={cn('min-w-0', className)}>
{children}
</Flex>
)
}
/** 两端对齐(.between):左说明右动作,窄屏折行后仍然左对齐 */
export function Between({ children, className, tight }: { children?: ReactNode; className?: string; tight?: boolean }) {
return (
<Flex wrap justify="space-between" align="center" gap={tight ? 6 : 12}
className={cn('min-w-0 max-lg:!justify-start', className)}>
{children}
</Flex>
)
}
/** 行内错误回显(.error):12px 红字,紧贴它说明的那个控件,不占提示条的位置 */
export function ErrorText({ children, className, lines, title }: {
children?: ReactNode; className?: string
/** 表格单元格里必须给(R17 表格行高纪律):一条 60 字的报错能把整行顶到 100px 以上 */
lines?: 1 | 2
/** 配合 lines 的悬停全文:传拼接好的纯文本 */
title?: string
}) {
if (!children) return null
return (
<Typography.Text type="danger" className={cn('!mt-1 block !text-xs [overflow-wrap:anywhere]', className)}>
{lines ? <Clamp lines={lines} title={title}>{children}</Clamp> : children}
</Typography.Text>
)
}
/** 分节线(.sub):同一面板里两个话题之间用它,不要再塞一个 h3 */
export function Sub({ children, className }: { children?: ReactNode; className?: string }) {
return (
<div className={cn('min-w-0', className)}>
<Divider className="!my-5" />
{children}
</div>
)
}
/**
* 内容页正文(.tabstack):面板之间固定 16px 呼吸,页面不要再自己写 mb-*。
* 叫 PageStack 不叫 TabStack:外壳没有多页签条(产品口径「内容页不做多 Tab」),
* 页签只存在于页面内部(kit 的 <Tabs>),这一层就是普通的正文纵排。
*/
export function PageStack({ children, className, style }: {
children?: ReactNode; className?: string; style?: CSSProperties
}) {
return <Flex vertical gap={16} className={cn('nex-stack min-w-0', className)} style={style}>{children}</Flex>
}
/**
* 两栏正文(.layout)= antd Row + Col。
*
* 症状:旧版写死 `grid-cols-[minmax(0,1.5fr)_minmax(300px,0.8fr)]` + 私有断点,
* 降列宽度与 antd Grid 的 xs…xxl 对不上,跟同一屏里的 Card 各排各的。
* 做法:默认主栏 15 / 侧栏 9(≈1.67:1,与原比例一致),≤1200(antd 的 lg 档)
* 两块各自铺满 24 栅格——即折成单列。列间距走 gutter(16 与站内间距成一套)。
* `side="left"` 给「侧栏在左」的版面(项目总控台:左边下达指令、右边执行过程);
* `spans` 只允许改这两格的 24 等分比例,页面依旧不能自己写 @media。
*/
export function Layout({ children, className, side = 'right', spans, oneAt = 'xl', gutter = 16 }: {
children?: ReactNode; className?: string
/** 侧栏在哪一侧(默认右) */
side?: 'left' | 'right'
/** [主栏, 侧栏] 的 24 等分,默认 [15, 9] */
spans?: [number, number]
/** 到哪个断点折成单列(默认 xl:≤1200 起单列) */
oneAt?: GridCollapse
gutter?: number | [number, number]
}) {
const [main, aside] = spans || [15, 9]
const cells = splitSpans(main, aside, oneAt)
const kids = Array.isArray(children) ? children : [children]
return (
<AntRow gutter={Array.isArray(gutter) ? gutter : [gutter, gutter]}
className={cn('min-w-0 [&>*]:min-w-0', className)}>
{kids.map((child, i) => (
<AntCol key={i} {...(side === 'left' ? (i === 0 ? cells.aside : cells.main) : (i === 0 ? cells.main : cells.aside))}>
{child}
</AntCol>
))}
</AntRow>
)
}
/**
* 一栏内的面板堆叠(.right)。
*
* <Layout> 折成单列之后(antd 的 lg 档,992–1199)这一栏是满宽的,
* 于是临时并排两列把宽度用掉;≤992(md 及以下)再叠回来。
* 档位换算成 Col 的 span 交给 antd Grid,页面不再有第二套断点。
*/
export function Stack({ children, className }: { children?: ReactNode; className?: string }) {
const kids = Array.isArray(children) ? children : [children]
const spans = { xs: 24, sm: 24, md: 24, lg: 12, xl: 24, xxl: 24 }
return (
<AntRow gutter={[16, 16]} className={cn('min-w-0 [&>*]:min-w-0', className)}>
{kids.map((child, i) => <AntCol key={i} {...spans}>{child}</AntCol>)}
</AntRow>
)
}