129 lines
7.6 KiB
TypeScript
129 lines
7.6 KiB
TypeScript
/**
|
||
* 状态表面(阶段 6 自 `Panel.tsx` 拆出,实现原样搬移):
|
||
* 「这一块正在发生什么 / 什么都没有 / 出了什么错」只有这五个名字,
|
||
* 对应 NEX 06 §7 的 loading · empty · error。
|
||
*
|
||
* 口径(不要在这里长出第六把尺子):
|
||
* · 首屏等待 = <SkeletonBlock>(形状可预期),局部刷新 = <Spinner>(不打断阅读);
|
||
* · 什么都没有 = <Empty>,文案按三分类写(还没生成 / 筛完没有 / 出错后为空);
|
||
* · 贴在内容块上方的结果说明 = <Notice>,它是 R19 反馈四级的第二级
|
||
* (第一级贴在控件旁:ErrorText / LineHint;第三、四级在 Toast.tsx 与 Confirm.tsx)。
|
||
*/
|
||
import { type CSSProperties, type ReactNode } from 'react'
|
||
import { Empty as AntEmpty, Flex, Progress, Skeleton } from 'antd'
|
||
import { cn } from '../../lib/cn'
|
||
import { IconClose, IconLoading } from '../icons'
|
||
import { Button } from './Button'
|
||
import { BLOCK_TONE } from './Panel'
|
||
import { NOTICE_TONE, TONE_ICON, TONE_TINT } from './tone'
|
||
|
||
/** 进度条:antd Progress(站内只有这一条;bad=异常态用 antd 的 exception 色) */
|
||
export function ProgressBar({ value, bad, className }: { value: number; bad?: boolean; className?: string }) {
|
||
const pct = Math.max(0, Math.min(100, Number(value) || 0))
|
||
return (
|
||
<Progress percent={pct} showInfo={false} status={bad ? 'exception' : 'normal'}
|
||
size="small" className={cn('nex-progress min-w-[60px]', className)} />
|
||
)
|
||
}
|
||
|
||
|
||
/** 空态:antd Empty(简单图,站内不放插画——卡片里那块地方给不起) */
|
||
export function Empty({ children = '暂无数据', className }: { children?: ReactNode; className?: string }) {
|
||
return <AntEmpty className={cn('my-2', className)} image={AntEmpty.PRESENTED_IMAGE_SIMPLE} description={children} />
|
||
}
|
||
|
||
/* 「读取中:一块居中的 Spin」这个导出(旧 <Loading>)在阶段 4 删掉了:
|
||
它全站只有三处调用,三处都是**首屏**,而首屏的正确表面是下面的 <SkeletonBlock>。
|
||
留着它等于给后来人留一把会退回「空白 + 转圈」的尺子——局部刷新请用 <Spinner>,
|
||
整块等待请用 <SkeletonBlock>,两者都够用。(审计报告 D6 / V6 · UI规范 §15.3) */
|
||
|
||
/**
|
||
* 首屏骨架 = antd Skeleton(阶段 4 · 补 NEX 06 §7 的 loading 态)。
|
||
*
|
||
* 症状:全站 0 处骨架。首屏是「一块空白 + 一颗转圈」——路由分包在拉、项目在拉,
|
||
* 内容区只有一枚居中 Spin(实测 240px 高的空盒子)。读者既不知道这里将出现
|
||
* 什么形状的东西,也分不清「在加载」和「加载完什么都没有」。
|
||
* 做法:骨架只用在**首屏**两处——① 路由级 Suspense 兜底(`app/App.tsx::PageLoading`),
|
||
* ② 抽屉正文(`ui/Overlay.tsx::Drawer` 的 `loading`)。
|
||
* 面板头 / 字段级的刷新维持内联 `Spinner`,那是成熟设计,不要拿骨架去闪。
|
||
* 为什么只有 rows / title 两个参数:站内首屏只有两种形状——「一摞段落」与
|
||
* 「一行标题 + 一摞段落」,都在 antd Skeleton 自己的档位里;开更多参数
|
||
* 等于给页面发第二把尺子(想要别的形状说明那一处不是首屏)。
|
||
* `nex-skeleton` 是闸门落点:像素检查要能认出「这一屏此刻是骨架」,
|
||
* 才不会把骨架当成空白内容误判成 empty 态。
|
||
* `label` 决定这摞骨架对读屏说不说话:一屏只该有一句进度播报,
|
||
* 所以纯装饰的那一段(页头形状)不传 label,它整块 `aria-hidden`。
|
||
*/
|
||
export function SkeletonBlock({ rows = 3, title = true, label, className, style }: {
|
||
/** 段落行数(antd 默认 3 行,这里对齐成站内首屏的常见高度) */
|
||
rows?: number
|
||
/** 要不要那一行标题占位:页头形状用 true,正文里续段用 false */
|
||
title?: boolean
|
||
/** 读屏与低视力用户看到的进度说明;只挂 sr-only,不占版面。不传 = 这摞纯装饰 */
|
||
label?: string
|
||
className?: string
|
||
style?: CSSProperties
|
||
}) {
|
||
return (
|
||
<div className={cn('nex-skeleton min-w-0', className)} style={style}
|
||
role={label ? 'status' : undefined} aria-busy="true"
|
||
aria-hidden={label ? undefined : true}>
|
||
<Skeleton active title={title} paragraph={{ rows }} avatar={false} />
|
||
{label ? <span className="sr-only">{label}</span> : null}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
/** 行内小转圈(按钮、状态条里那颗) */
|
||
export function Spinner({ className }: { className?: string }) {
|
||
return <IconLoading spin aria-hidden className={cn('align-[-1px] text-xs', className)} />
|
||
}
|
||
|
||
/**
|
||
* 提示条:自绘表面,**不用 antd `Alert`**(2026-11 第十三轮)。
|
||
*
|
||
* 症状(用户原话「整体修改系统中所有提示窗、完成后的反馈 tips 等。不要使用默认组件」):
|
||
* 这一层原来是 antd Alert 的直封装,于是站内同时存在两套「信息块长相」——
|
||
* 同一页里 <Block> 系列有语义描边 + 语义底纹 + 圆角 + 内边距档位,
|
||
* 而 Alert 是 antd 自带的那套(浅色档还带着它自己的 closable 图标位置),
|
||
* 并且它**没有 action 位**:App.tsx 那条「后端连接异常」要挂「重试」按钮,
|
||
* 只能绕过 kit 直接 import antd 的 Alert。
|
||
* 做法:读 R16.3 那把唯一的尺子 `BLOCK_TONE`(语义底纹 + 语义描边),
|
||
* 左侧色块用色块族(20px 档,与概况抽屉的七站行同一尺寸),
|
||
* 两行文案 = `children`(一句人话)+ `description`(明细 / 善后),
|
||
* 右侧新增 `action` 位(重试、去设置这种善后按钮),`onClose` 走标准图标按钮。
|
||
* props 与原来完全一致(含 antd 词汇的 `type`),30 处调用点零改动。
|
||
* 为什么保留 antd 的 type 词汇:`type="success" | "error"` 这套名字已经写在 30 处调用点里,
|
||
* 它是**语义**而不是皮肤;`NOTICE_TONE` 把它翻成站内语气,皮肤换多少轮都不用碰页面。
|
||
*/
|
||
export function Notice({ children, description, danger, className, onClose, type, action }: {
|
||
children: ReactNode; danger?: boolean; className?: string; onClose?: () => void
|
||
/**
|
||
* 第二层说明(与 antd Alert 同名):`children` 是「一句人话」的标题,
|
||
* 多条明细 / 善后按钮属于正文,塞进 children 会让整块只有一层粗体、
|
||
* 明细和按钮跟着一起加粗,于是页面又自己写 <b> + <p> 造第二层。
|
||
*/
|
||
description?: ReactNode
|
||
/** Alert 的四档语义;`danger` 是站内先写下的 error 简写,两者等价 */
|
||
type?: 'info' | 'success' | 'warning' | 'error'
|
||
/** 右侧善后动作(重试 / 去设置);一颗 Button 或一组按钮,不放正文 */
|
||
action?: ReactNode
|
||
}) {
|
||
if (!children) return null
|
||
const tone = NOTICE_TONE[type ?? (danger ? 'error' : 'info')]
|
||
return (
|
||
<Flex align="start" gap={10} role={tone === 'bad' || tone === 'warn' ? 'alert' : undefined}
|
||
className={cn('nex-notice mb-4', BLOCK_TONE[tone], className)}>
|
||
<span className="nex-notice-mark" aria-hidden
|
||
style={{ ['--nex-mark-tint' as string]: TONE_TINT[tone] }}>{TONE_ICON[tone]}</span>
|
||
<div className="min-w-0 flex-1">
|
||
<div className="nex-notice-title">{children}</div>
|
||
{description && <div className="nex-notice-desc">{description}</div>}
|
||
</div>
|
||
{action && <div className="nex-notice-action flex flex-wrap items-center gap-2">{action}</div>}
|
||
{onClose && <Button type="text" size="sm" className="nex-notice-close" aria-label="关闭提示"
|
||
title="关闭提示" icon={<IconClose />} onClick={onClose} />}
|
||
</Flex>
|
||
)
|
||
}
|