规范补到十七条并把探针升到「六道 + 一道反向验证」:行高、栅格、纵向节奏、标签底色全部有闸
症状:这一轮改的每一类毛病里,有四类靠人眼复查根本守不住——表格行被内容撑高(实测最高 255px)、该用栅格的地方用自然排列(窄屏两种坏画面:一行右边缘参差不齐、折行点随内容 漂移)、纵向节奏断(底边不齐 / 收缩错位)、标签自带彩色底纹(§2.1 要求中性底);而卡头 `right` 长起来把标题压成竖排(430 档标题 291×145)也没有任何闸门会报。更麻烦的是 rhythmcheck 的判据原先读像素,豁免写宽一格就永远安静地返回 0——14 条命中里混着探针 自己的假警报,没人敢信它的红。 做法:①`docs/UI规范.md` 新增 R17 表格行高纪律(§13.2)与 R16 信息块三件套的落地口径 (§13.1),§9.3 补卡头折行那条(含「折行样式要挂在 `.ant-card-head-wrapper` 而不是 `.ant-card-head`」这个陷阱与 430/1440 的实测数据),§15 扩成 15.1–15.7 六道常驻探针 加一道反向验证,§16 提交清单插入第 9 步「动过布局跑三张像素闸、改过判据跑 gateprobe」; ②新增 `tableaudit.py`(逐表报容器宽/可视宽/行数/最高行/列宽,超行高点名)、 `gridcheck.py`、`rhythmcheck.py`(GAP + RAG,四条写法级豁免逐条写明为什么豁免)、 `tagcheck.py`(扫标签 tinted 底);③`gateprobe.py` 用「坏 fixture 必须被点名、合法形态 必须被放行」两组用例反向验证三张像素闸,共 4/4 全对,不碰源码不触发 HMR; ④`rhythmcheck.py` 的判据改成只读写法不读像素(`isPin` 认 mt-auto / inline margin-top / justify-content;RAG 侧放行子块自带 max-width、align-self 与整行居中的胶囊组), `classaudit.mjs` 把 `<Flex align="flex-start">` 的取值加进 PROSE 白名单(它天天作为 props 值出现,逐行切词分不清引号内外);⑤`visualcheck.py` 的项目子页改成量「镜头最多」 的项目并支持 NEX_PROJECT_ID 覆盖——列表第一个常是空项目,空态下溢出与截断两类断言等于 没测;⑥README 的规范条目数同步到十七条(只提这一行,其余内容归并行的后端改动)。 为什么:这类毛病全是「看起来挺整齐、量一下才知道差 200px」,只有把它们变成退出码才能 防止下一轮又漏回去;而像素闸一旦可能悄悄失灵,就必须配一道反向验证——先证明闸门坏了 会响,它的绿才有意义。main
parent
ad4cdcb52b
commit
7e784b5303
|
|
@ -110,7 +110,7 @@ antd 的 `InputRef` / `TextAreaRef` 在 kit 内部折掉(`lib/ref.ts`)——
|
|||
**控件标签被省略号截掉**(分段 / 页签 / 按钮 / **下拉当前值**)、**4xx/5xx**(按 URL 分诊:素材文件在
|
||||
开发库里缺失的 404 单独计数,接口 404 判失败并点名发出它的路由)。
|
||||
|
||||
选型理由、四层分工、咬过人的陷阱见 `docs/UI规范.md` §0(十六条硬规矩 R1–R16)与 §1。
|
||||
选型理由、四层分工、咬过人的陷阱见 `docs/UI规范.md` §0(十七条硬规矩 R1–R17)与 §1。
|
||||
旧的手写规范探针(`scripts/ui/legacy/{audit,metrics,vocab}.py`)已作废归档。
|
||||
|
||||
改过控件、表单或主题,提交前跑一遍 UI 体检(前端 5173 与后端 8000 需在跑):
|
||||
|
|
|
|||
245
docs/UI规范.md
245
docs/UI规范.md
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
---
|
||||
|
||||
## 0. 十六条硬规则(违反任意一条 = 返工)
|
||||
## 0. 十七条硬规则(违反任意一条 = 返工)
|
||||
|
||||
| # | 规则 | 为什么 |
|
||||
|---|---|---|
|
||||
|
|
@ -38,11 +38,12 @@
|
|||
| R9 | **不写私档数字**:`bg-[#...]`、`text-[13px]`、`rounded-[7px]`、`leading-[1.9]`、`w-[3px]`、自造断点一律禁止;颜色/字号/圆角/间距只准用转发到 `--ant-*` 的语义名,或者 Tailwind 的 4px 栅格(`gap-3` = 12 = `marginSM`)。响应式宽度 `w-[min(...)]` 与贴在内容上的尺寸 prop 例外 | 任意值是「第二把尺子」的入口,一旦允许就会长回手写规范 |
|
||||
| R10 | **ref 契约**:kit 一律 `forwardRef`,ref 只交 DOM 节点,组件库句柄不外泄(折法唯一,见 `lib/ref.ts`) | `ref?:` 写在 props 里 tsc 照过、运行时只 warn,功能静默没了 |
|
||||
| R11 | **图标只用 `@ant-design/icons`,且只在 `components/icons/index.ts` 一处 import**。自绘 `Icon.tsx`/`glyphs.ts` 已删,目录只剩这张语义登记表;页面写的是语义名(`IconGrid`/`IconWarn`),字形名只出现在表里。纯图标按钮必须带 `title` + `aria-label`(`<IconButton>` 把 label 同时喂给两者) | 收口前有 32 个文件散着 import 73 只图标,「同一个意思该长什么样」全站无一处可查;40 个手绘 glyph 更是同一只「会亮的方块」长出五种长相的根源 |
|
||||
| R12 | **改了尺子就全量回归**:动过 `theme/antd.ts`、`styles/index.css`、`styles/app.css` 任一文件 → §15 两道探针全量重跑,且**窄屏 430/576 也在回归宽度里** | 只在窄屏生效的规则必须有截图证据,不能靠推理 |
|
||||
| R12 | **改了尺子就全量回归**:动过 `theme/antd.ts`、`styles/index.css`、`styles/app.css` 任一文件 → §15 六道探针全量重跑,且**窄屏 430/576 也在回归宽度里** | 只在窄屏生效的规则必须有截图证据,不能靠推理 |
|
||||
| R13 | **布局 utility 压在 antd 组件根节点上,依赖三处层叠声明**:`app/providers.tsx` 的 `<StyleProvider layer>`;`styles/index.css` 里拆开 import **之前**的 `@layer theme, base, components, antd, utilities;`;以及 `@import "tailwindcss/preflight.css" layer(antd)`——**preflight 必须与 antd 同层**,写回 `layer(base)` 会被 antd 的 prepend 反超、全站复位反吃组件样式。两者任一被摘掉,`max-md:hidden` 这类 utility 会**静默失效**(tsc / build 全绿,只有浏览器能看出来)(详见 §1.1) | Tailwind v4 把 utility 放进 `@layer`,而 antd 默认注入的 CSS 未分层;按 CSS 层叠规则「未分层永远赢过分层」, antd 会把我们的布局 utility 全量盖掉 |
|
||||
| R14 | **按钮与浮层底部只用 antd 原生词汇**:`type` / `danger` / `size` / `icon` / `shape` / `loading`,自造 `variant` 方言已废;浮层底部一律「辅助 → 取消 → 主行动」右对齐、整条 md 档、最多一颗 `type="primary"`(详见 §5.1、§10)。裸 `<button>` 只许出现在 §5.2 的自定义表面族白名单里 | 219 处 `variant=` 是靠 codemod 迁完的:只要方言还在,下一个页面就会接着发明名字,主题与档位又收不口 |
|
||||
| R15 | **按钮一律是图标按钮**:凡有动作语义的按钮都写 `icon={<IconXxx />}`,`FilePick` / `RecordAudio` 这两个自带触发元素的封装也走 `icon` 槽;一个意思全站只许一只图形(§5.1.1) | 一排纯文字按钮要逐个读完才知道哪颗是什么,图标剪影一眼分得开;用户截图原话「按钮都要使用图标按钮」 |
|
||||
| R16 | **统计块 / 回显信息块一律带底纹**:`Stat` 自带 `bg-fill-tertiary`,`Block` 默认档与无色调 `Tag`/`Status` 默认落在 `--ant-color-fill-tertiary`,页面**不许**再手涂 `bg-[#...]` 或把这类盒子改成白底描边(§2、§5.1.2) | 白底数字块与卡片同色,扫一眼分不出「这是结论」还是「这是容器」;底纹是 antd 自己那层 fill,明暗两档都跟着主题走 |
|
||||
| R16 | **信息块三件套各有唯一写法**(§13.1):① **统计**=`Stat`/`StatGrid`,自带 `bg-fill-tertiary` 底纹 + 右下角语义水印图形,页面不再手涂 `bg-[#...]`;② **只读回显**=`Info`(antd `Descriptions`),「灰盒 + label 在上」和用 `Input disabled` 装只读值一律废止,只读 `Tag` 不许描边,统计用途的计数不许用无底纹灰胶囊;③ **语义提示**=`Notice`(antd `Alert`),页面不再自拼 `border + warning-bg` 当告警 | 白底数字块与卡片同色,扫不出「这是结论」还是「这是容器」;灰盒回显和旁边的输入框长得一样,用户去找可点的框,框里却没有可改的东西;底纹与告警底色都是 antd 自己的 fill / 语义色层,明暗两档跟主题走,不需要再养一套私有皮肤 |
|
||||
| R17 | **表格行不许被子元素撑高**(§13.2):① 先做列宽预算——`Table` 默认 `minWidth={false}`,定宽列合计必须回到容器里,长文列**不写 `width`** 吃掉剩余宽度且扣掉内边距后 ≥ 200px;② 单元格里的长文案一律 `<Clamp>` 封顶(标题 1 行 / 说明与报错 2 行)并把全文挂原生 `title`,表格里的 `ErrorText` 同样必须给 `lines`;③ 动作列按「`颗数×32 + (颗数−1)×6 + 16`」算宽、图标化一行放完。一个格子的预算是**正文两行 + 次要元信息一行 ≈ 84px**,超了就是返工。**这条由 `scripts/ui/tableaudit.py` 常驻量,不靠自觉** | 「列宽」与「文案长度」两头堵,只调列宽永远调不完:审核留痕一句质检长文把行顶到 255px、生成记录一条 prompt 顶到 227px,一屏只剩三条记录,表格退化成段落。用户第 28 轮原话「表格行不要被子元素撑高(长文折 8 行 = 设计失败)」 |
|
||||
---
|
||||
|
||||
## 1. 谁定尺子:四层,antd 在最上面
|
||||
|
|
@ -713,16 +714,32 @@ sm 档给密集处:表格单元格、缩略图角标、一行挤五六个的
|
|||
- 栅格:`<Grid cols>` 只用于**等宽内容卡**;字段排布一律 `<FormRow>`。
|
||||
- **成组筛选项不许塞进 `<PanelHead right>`**:那块常常不足 300px,放两个 `Field` 就低于最小轨道。
|
||||
`PanelHead right` 只放**一个**计数或单个动作(G1)。
|
||||
- **值型控件(下拉 / 分段 / 单选组)的宽度归控件,不归「标签 + 控件」**:
|
||||
`nf-w-*` 写的是 flex-basis = **整字段**宽,而标签列是 `max-content`——标签每多一个字控件就少十几 px。
|
||||
同一个 narrow 档包两个字段,「状态 全部状态」够(93px)、「排序 按更新时间」不够(107px):
|
||||
能不能看全由标签字数决定,这不是设计,是巧合(2026-11 实测全站 23 处:91>70 / 77>70 / 77>46)。
|
||||
正解写在 `app.css`:`.nex-field:has(> .nf-ctl > :is(.ant-select, .ant-segmented, .ant-radio-group))`
|
||||
把 `flex-basis` 交回内容,档位降级成挂在 `.nf-ctl` 上的 `min-width: var(--nf-ctl-min)`——
|
||||
标签长 → 整字段顶宽,一行放不下就**整字段换行**(§7 唯一的降档方式)。
|
||||
输入框 / 数字框 / 日期框**不吃这条**:它们没有「内容宽度」可言(intrinsic 是 `size` 给的 20 字符),
|
||||
撑满列宽才是正解,照旧吃 flex-basis。
|
||||
代价是刻意的:工具条更早换行、字段宽度随选中值变化。
|
||||
- **`right` 里那句长文案不许把标题压成竖排**(2026-11 第 29 轮 · 430 档 `/projects/10/review`):
|
||||
antd 的卡头是**不换行**的 flex,`right` 写「下一步:时间线合成 + 配音/字幕/混音 — …」要 400px 以上,
|
||||
窄屏只剩 30px 给标题 ⇒「流程进度」一个字一行。做法在 `styles/app.css`:
|
||||
`.nex-panel .ant-card-head-wrapper { flex-wrap:wrap; row-gap:margin-xxs }`
|
||||
+ `.nex-panel .ant-card-extra { flex-shrink:0; max-width:100% }`——宽屏照旧同一行读完,
|
||||
窄屏整句掉到第二行(实测 430:标题 292×24、extra 折到第二行;1440 一字未动)。
|
||||
⚠ 真正的 flex 容器是 **`-wrapper`**,写在块级壳 `.ant-card-head` 上等于没写。
|
||||
页面侧口径不变:`right` 只放一个计数或一句「下一步」,成段说明进 `<PanelHead sub>`。
|
||||
- **值型控件(下拉 / 分段 / 单选组)看得全看不懂,由格子宽度负责,不由标签字数决定**:
|
||||
旧口径是给整字段写 `nf-w-*`(flex-basis),而标签列是 `max-content`——同一个 narrow 档,
|
||||
「状态 全部状态」够(93px)、「排序 按更新时间」不够(107px),能不能看全成了巧合。
|
||||
`nf-w-*` / `.nf-ctl` / `--label-w` 那一层已经随私有 CSS 一起删了(`app.css:85`),现在的口径是:
|
||||
① 字段宽度是字段自己的属性(`<Field width>`),inline 字段把同一个数交给控件列
|
||||
(`--nex-ctl-w`,见 `Controls.tsx` 的 `INLINE_CTL_W`);
|
||||
② 一旦进 `<Ctlbar cols>` 栅格,列边界归 `Col`,`app.css` 的
|
||||
`.nex-ctlbar-grid .nex-field-inline .ant-form-item-control{flex:1 1 auto}` 让 `--nex-ctl-w`
|
||||
当场让位给列宽——同一行的控件右缘因此必然对齐;
|
||||
③ 所以「选中值被省略号裁一半」只剩一个成因:**格子本身太窄**,正解是降列(下面的 ROW_STEPS),
|
||||
不是给某一只下拉单独加宽。
|
||||
- **`ROW_STEPS` 的降列档位按「正文宽」取,不是按视口宽**:侧栏占 224(≤ `md` 折叠成 64)
|
||||
+ 内容内边距 32,768 视口的正文只有 512,而 antd `Col` 的断点量的是视口——
|
||||
档位必须整体往窄挪一档,否则每格 158 起步。
|
||||
实测(`visualcheck` 768 档 /assets):5 等分在 `md` 给到 3 列时每格 158,
|
||||
标签 69 之后只剩 69,选中值「全部类型」77px 被裁成 53px;
|
||||
`5:` 挪成「≤1600 四列 / ≤1200 三列 / ≤992 两列 / ≤576 单列」后最窄一格 237,值 132 全可见。
|
||||
新增 `cols` 档位时按**同一把尺子**算:目标是最窄一格 ≥ 200(inline 标签 ≈ 70 + 值 ≥ 120)。
|
||||
- **唯一的豁免是「选项名本身就是一整句散文」的下拉**,标记类 `nex-prose-value`。
|
||||
这类下拉的选中值盒子在任何档位都放不下整句——时间线右栏实测 135~303px,
|
||||
而「模型原声直出(口型同步 + 角色声线做参考 · 推荐,不生成 TTS)」要 442px;
|
||||
|
|
@ -876,6 +893,91 @@ sm 档给密集处:表格单元格、缩略图角标、一行挤五六个的
|
|||
- **Playwright 的 `locator.click()` 会先把目标居中**(CDP `scrollIntoViewIfNeeded`):
|
||||
量滚动位移之前基线必须在 `scroll_into_view_if_needed()` 之后再取,或者干脆用真实鼠标 `mouse.click(x, y)`。
|
||||
|
||||
### 13.1 信息块三件套:统计卡 / 只读回显 / 语义提示(R16 落地)
|
||||
|
||||
用户截图里那一类「信息块」其实是三种不同的东西,各有一个 antd 原生写法,混用就是本轮返工的全部原因。
|
||||
|
||||
| 种类 | 它在回答什么 | 唯一写法 | 已废止的写法 |
|
||||
|---|---|---|---|
|
||||
| **统计** | 「现在有多少 / 达没达标」 | `Stat`(= antd `Statistic` + 卡)/ `StatGrid` | 自绘大数字、白底数字块、把计数写成无底纹的灰 `Tag` 胶囊 |
|
||||
| **只读回显** | 「它被配置成了什么」 | `Info`(= antd `Descriptions`,`bordered` + `size=small` + `colon=false`) | 灰盒 + `label` 在上的假输入框、`<Input disabled>` 装只读值、带描边的只读 `Tag`、`a · b · c` 散文属性行 |
|
||||
| **语义提示** | 「这一步会发生什么 / 为什么不能做」 | `Notice`(= antd `Alert`,四档 `type` + `description` 第二层) | 自拼 `border border-warning-border + bg-warning-bg`、`<b>` + `<small>` 造二层 |
|
||||
|
||||
**① 统计卡:底纹 + 背景图形。** `Stat` 的卡档自带 `bg-fill-tertiary`,并给右下角压一枚同语义的
|
||||
`--nex-stat-mark` 水印图标(`opacity 0.09`、84px、`pointer-events:none`,文字层 `z-index:1` 抬在之上)。
|
||||
水印只在给了 `icon` 时出现,配色取 `--nex-stat-tint`(与 `tone` 同一支语义色),不是新的色值。
|
||||
栅格一律 `StatGrid`,卡片列数走 `steps`,别在页面写 `grid-cols-*` 定宽。
|
||||
|
||||
**② 只读回显:一律 `Info`。** `Info` 的 label 列由 antd 上 `colorFillAlter` 底纹(深色档在 `app.css`
|
||||
抬到 7% 白,4% 压不出「这一列是标签」),值列 `overflow-wrap:anywhere`。用法三约束:
|
||||
- **分栏**:宽面板用 `column={{xs:1,sm:2}}` 让 antd 自己降列;**侧栏 / 窄卡(< 420px)一律 `column={1}`**,
|
||||
短属性合并进同一个 label(`语言 / 性别 / 版本`)——响应式断点量的是视口,窄卡会以为自己在宽屏,把值挤成竖排。
|
||||
- **进卡片加 `nex-info-in-card`**:卡本身已有描边,表格再描一圈就是双层框,这个类只去外框、保留内部网格线。
|
||||
- **标签不许裸放进值列**:一组 `Tag` 直接进 `<td>` 会挤成一坨,一律包 `TagGroup`(组内 4px、组下 12px 由它管)。
|
||||
- **计数一律 `Count`**(`ui/Panel.tsx`,`<Count n={q.queued} unit="条" tone="warn" />`):等宽数字 +
|
||||
小一档的灰单位,**非零才按 `tone` 上语义色,0 一律降成 `text-text-tertiary`**——0 表示「没有要处理的」,
|
||||
不该和 8 抢注意力。这套口径原先散在各页的局部函数里(调度中心的 `cnt`),
|
||||
质检页要做同一个块只能再抄一遍;现在只有组件这一份,页面别再自己写「非零才上色」。
|
||||
- **`Info` 的分栏档位由 `fillInfoColumns` 向上补齐**:antd `Descriptions` 把 `column` 与内置
|
||||
`{xs:1,sm:2,md:3,lg:3,xl:3,xxl:3}` 合并后由宽到窄取第一个命中档,于是只写 `{xs:2,sm:3,lg:5}`
|
||||
的回显在 1440 命中的是内置 `xl=3`——**声明的 5 列在桌面上永远不生效**。
|
||||
补齐后「没写的右档 = 最近一次声明的值」,页面只写「从哪一档开始降到几列」。
|
||||
- **项里写了 `span` 的回显,`column` 必须是定值**:antd 的 `span` 不跟断点走,
|
||||
而校验是「每一行 span 之和 = `column`」。`column={{xs:1,sm:2}}` + `span:2` 在窄屏
|
||||
1 列时当场不匹配,控制台报 ``Sum of column `span` in a line not match `column` of Descriptions.``
|
||||
(`visualcheck` 的 console 闸门就是它)。正解写 `column={2}`:长描述顶满一行、短属性并排,
|
||||
430 也成立;**不要**在 `Info` 里把 `span` 夹到最小档列数——那会让宽屏的整行项退成半行。
|
||||
- **两栏版式按「哪一侧是主内容」给宽度**:`<Layout spans={[main, aside]}>` 默认 `side='right'`
|
||||
(第 0 个子元素在左、拿 `main`)。审核页这类「结论在右」的版面就写 `spans={[9, 15]}`
|
||||
——左列只是质检清单,等宽的 `[12,12]` 会把右侧的人工审核挤成竖排(用户第 27 轮点名)。
|
||||
- **栅格除不尽 24 时走百分比 flex**:`ColAt`(`ui/grid.tsx`)在 `24 / 列数` 不是整数时
|
||||
下发 `flex: 0 0 (100/列数)%`。span 只能取整数,5 张统计卡按 `24/5` 取整成 5 就是 5×5=25 > 24,
|
||||
第 5 张整张被挤到下一行——「一行就得放完」的那几档必须用 flex,不是 span。
|
||||
|
||||
**③ 语义提示:一律 `Notice`。** 一句人话写 `children`(= Alert 的 `message`),
|
||||
明细 / 长解释写 `description`,别在 `children` 里自己 `<b>` + `<p>` 造第二层。
|
||||
`info` 用于「平台会怎么做」,`warning` 用于「能继续但有坑」,`error` 用于「现在点不动」,
|
||||
`success` 用于「这一步已经就绪」;图标由 Alert 自带,页面不再手写 `IconWarn` 之类。
|
||||
|
||||
### 13.2 表格行高纪律(R17 落地)
|
||||
|
||||
**症状**(第 28 轮全站表格体检,也是 `scripts/ui/tableaudit.py` 的立项原因):数据行被子元素
|
||||
撑到 84px 以上,一屏只剩三条记录,「表格」退化成「一列一列的段落」。
|
||||
|
||||
| 位置 | 撑高原因 | 改前 | 改后 |
|
||||
|---|---|---|---|
|
||||
| 审核页「审核留痕」说明列 | 一句 90 字质检结论在 464px 里折 11 行 | **255** | 61 |
|
||||
| 交付页「生成记录」提示词列 | 完整 prompt 全文直出 | **227** | 81 |
|
||||
| 交付页「成片记录」名称列 | 片名折两行 + 预设折两行 + 报错原文未封顶 | **145** | 82 |
|
||||
| 调度中心「分镜任务清单」说明列 | 定宽列吃掉宽度后只剩 112px,同一句话折 8 行 | **168** | 59 |
|
||||
| 总览页「流程节点明细」 | 说明列排在中间,被定宽列挤到 160px | 81 | 61 |
|
||||
| 时间线页「时间线版本」操作列 | 三颗带字按钮要 262px,220 的列放不下 ⇒ 折两排 | 79 | 49 |
|
||||
| 项目列表「项目」列 | 名称 + 规格各折两行 | 79 | 59 |
|
||||
|
||||
**三条做法**:
|
||||
|
||||
1. **先做列宽预算,再谈文案**。`Table` 默认 `minWidth={false}`:定宽列合计必须回到容器里,
|
||||
剩下的宽度整块留给长文列,长文列**不写 `width`**(内部按剩余宽度铺)。
|
||||
1440 视口的尺子:内容区 1180,全宽 Panel 的表容器 **1118**,`<Layout>` 15 栏 **674**、9 栏 **378**。
|
||||
估宽:中文 ≈ 12px/字、等宽 11px ≈ 6.6px/字、antd small 单元格左右内边距共 **16px**、
|
||||
控件 md 档 32px。长文列扣掉 16px 后**至少留 200px**,否则再宽的句子也只是换个方向折。
|
||||
次要信息(key、id、耗时)排到末列,别让它们卡在长文列左边。
|
||||
2. **长文案一律 `<Clamp>` 封顶**(`ui/Table.tsx`):`lines={1}` 给标题/名称类,`lines={2}`
|
||||
给说明、报错、prompt 类,完整文本传 `title` 悬停看全。表格里的 `ErrorText` 同理**必须给
|
||||
`lines` + `title`**(成片记录那条「响度两遍归一:实测混音 −20.2 LUFS…」就是它顶到 86px 的)。
|
||||
一个格子的预算:**正文两行(2×22)+ 次要元信息一行(20)+ 上下内边距 16 ≈ 84px**。
|
||||
3. **动作列图标化**(R15):三颗带字按钮 262px 折成两排,换三颗 `type="text" shape="circle"`
|
||||
只要 `3×32 + 2×6 + 16 = 128`。**动作列宽度照这颗公式算**,别按「看着够宽」估——
|
||||
差 12px 就是折两排,行高从 49 变 87。
|
||||
|
||||
**为什么不用 antd 的 `column.ellipsis`**:它只支持单行,长说明折成一行等于没显示;
|
||||
要为两行再包一层 `Tooltip` 就得给全站包组件(R8:页面不 import antd),而原生 `title` 已经够用。
|
||||
|
||||
**为什么 `line-clamp-*` 不能直接写在 `column.className` 上**:`className` 落在 `<td>` 上,
|
||||
`-webkit-line-clamp` 依赖 `display:-webkit-box`,套在单元格上会破坏 `table-cell` 布局
|
||||
(实测列宽不再受 `width` 约束)。所以封顶必须包一层内层 `<div>`,也就是 `<Clamp>`。
|
||||
`cellWrap` 只解决「不顶宽表格」、不解决「不撑高行」,新页面别再拿它当封顶用。
|
||||
|
||||
---
|
||||
|
||||
## 14. 说明文字与表单增删(G1/G2/G3/G4/G5)
|
||||
|
|
@ -941,7 +1043,7 @@ G4 剩下的只是「增 / 删放在哪一行」:
|
|||
|
||||
---
|
||||
|
||||
## 15. 两道常驻探针(退出码都必须为 0)
|
||||
## 15. 六道常驻探针 + 一道反向验证(退出码都必须为 0)
|
||||
|
||||
### 15.1 `node scripts/ui/classaudit.mjs` —— 量源码用词
|
||||
|
||||
|
|
@ -965,9 +1067,9 @@ node scripts/ui/classaudit.mjs frontend/src/pages/Help.tsx
|
|||
当前基线(五道全绿):
|
||||
|
||||
```text
|
||||
0 个死类名 / 3912 个候选
|
||||
0 个死类名 / 3971 个候选
|
||||
0 处绕过登记表的图标 import(只许 src/components/icons/index.ts)
|
||||
0 处未收口的裸 <button>(白名单 7 个文件 / 实际命中 7 个)
|
||||
0 处未收口的裸 <button>(白名单 6 个文件 / 实际命中 6 个)
|
||||
0 处不符合浮层底部动作口径(Drawer actions / Modal footer)
|
||||
0 处越界的 import 'antd'(R8:只许 theme/ · app/ · components/{ui,forms} · stores/notice.ts)
|
||||
```
|
||||
|
|
@ -1058,6 +1160,104 @@ NEX_WIDTHS=1440,992,768,430 NEX_THEMES=dark,light .venv/bin/python scripts/ui/vi
|
|||
- 历史账:迁移期的 `audit16/19/20.js`、`metrics.py`/`audit.py`(旧手写规范口径)、
|
||||
`mk16.py / mkinv.py / mkall.py`、`/tmp/nex_*.py` 全部作废,别再引用。
|
||||
|
||||
### 15.3 `.venv/bin/python scripts/ui/tableaudit.py` —— 量表格行高(R17)
|
||||
|
||||
第 28 轮立项:行高是「tsc / build / classaudit 全绿、页面却是坏的」最典型的一类,
|
||||
`visualcheck` 只管溢出不管行高,所以再立一道专量表格的闸。
|
||||
逐路由遍历 `.ant-table-wrapper`,报「容器宽 / 可视宽 / 内容宽 / 逐列宽 / 最高数据行」,
|
||||
超线就把撑高元凶按 `标签.class 宽×高` 直接点名到元素,省得再开 devtools 手摸。
|
||||
|
||||
| 判定 | 阈值 | 口径出处 | 环境变量(默认值) |
|
||||
|---|---|---|---|
|
||||
| 数据行最高 | > 84px 违规 | R17(正文两行 + 次要元信息一行 + 上下 16) | `NEX_ROW_H_MAX`(84) |
|
||||
| 横向溢出 | `scrollWidth − clientWidth` > 40px 违规 | R1 / §13.2 第 1 条 | `NEX_SCROLL_SLACK`(40) |
|
||||
|
||||
- **豁免**:rc-table 的 `.ant-table-measure-row` 与 antd 空态 `.ant-table-placeholder`
|
||||
——空态那条 105px 是 antd 自己的占位,不是被子元素撑高的,计入就会满屏假阳性。
|
||||
- 退出码 = 违规表的张数(0 = 全绿)。
|
||||
- 路由里的 `{id}` 自动取**镜头最多的项目**(`NEX_PROJECT_ID` 未设时逐个问 `/api/projects/:id/shots`):
|
||||
开发库里列表第一个往往是刚建的空项目,每张表都是空态,等于没测。
|
||||
|
||||
```bash
|
||||
.venv/bin/python scripts/ui/tableaudit.py # 默认 10 条路由 × 1440
|
||||
NEX_ROUTES="/projects/{id}/delivery,/projects/{id}/review" \
|
||||
.venv/bin/python scripts/ui/tableaudit.py # 只跑改过的页
|
||||
NEX_ROUTES="/projects/{id}/review" NEX_THEMES=light \
|
||||
NEX_ROW_H_MAX=64 .venv/bin/python scripts/ui/tableaudit.py # 收紧阈值自查
|
||||
```
|
||||
|
||||
**这道闸反向验证过**:把 `<Clamp>` 摘掉、或把时间线操作列的 `width: 128` 改回 116,
|
||||
探针立刻红并且点名 `DIV.min-w-0 flex-1 258x86`(成片名称列)/折成两排的按钮行,改回复绿。
|
||||
|
||||
### 15.4 `.venv/bin/python scripts/ui/gridcheck.py` —— 量「该用栅格却在自然排列」
|
||||
|
||||
第七轮立项、第 30 轮补登记(**以前只有脚本在跑、文档没账**,新克隆根本不知道有这道闸)。
|
||||
用户口径:**该用 grid 的地方不要用自然排列**。`flex-wrap` 在同族子块宽度参差时必然产出
|
||||
两种坏画面:一行里右边缘参差不齐、折行点随内容漂移,第二行的左边缘对不上第一行。
|
||||
判定只看渲染结果:容器 = `flex-direction:row` + `flex-wrap:wrap`,子块按 antd 控件族归类
|
||||
(form-item / select / input / number / card / check / seg / tile / tag),**同族 ≥3 颗**才立案:
|
||||
|
||||
| 判定 | 立案阈值 | 为什么 |
|
||||
|---|---|---|
|
||||
| `rag` | 同族子块宽度极差 > 40px | 一行放得下也没对齐 |
|
||||
| `misalign` | 折行后各行左边缘极差 > 8px | 折行点随意,跨行对不上 |
|
||||
|
||||
- **按族豁免**:`btn` 按钮组本就该按内容自然排列(同概念不跨行由 visualcheck 的 ActionGroup 断言管);
|
||||
`span` 是 `.nex-chipbar` / `.nex-taggroup` 里的胶囊与只读标签——筛已有内容 = 胶囊流,
|
||||
宽度**必须**跟着文案走,等宽反而读不出区别。
|
||||
- 折行错位按**容器全部子块**分行:行首的标签 / 前置按钮会把整行推右,只按同族分行会量出 100~270px 的假错位。
|
||||
- 正解:改 `Ctlbar cols={n}` / `Row+Col` / `OptionGrid`(§7),或确认它属于胶囊流并放进 `.nex-chipbar`。
|
||||
- 退出码 0/1;默认 1440·1280·1024 × 浅色 × 13 条路由,`NEX_WIDTHS` / `NEX_THEMES` / `NEX_ROUTES` 可收窄。
|
||||
|
||||
### 15.5 `.venv/bin/python scripts/ui/rhythmcheck.py` —— 量纵向节奏与收缩错位
|
||||
|
||||
同第七轮立项。用户口径:**组件之间的上下、左右边距要合理**。本站纵向间距的唯一来源是
|
||||
`PageStack`(页内区块)与栅格 `gutter`(格与格),页面里再补 `mt-*/mb-*` 就会同一屏混着
|
||||
12/16/20/24 四档。对着渲染结果量两件事:
|
||||
|
||||
| 判定 | 立案条件 | 口径出处 |
|
||||
|---|---|---|
|
||||
| `GAP` | 同一列容器内相邻可见子块的纵向间距**不止一档**,或 > 24px(`--ant-margin`) | §1、§6 |
|
||||
| `RAG` | 列容器把子块排成 shrink-wrap:容器在要求撑满,子块却各自贴着内容宽度(比容器窄 > 48px) | §13 |
|
||||
|
||||
四条**写法级**豁免(第 30 轮重新收口:判据一律读「怎么写的」,不读「恰好长在哪」):
|
||||
|
||||
- **末块 `mt-auto` / `justify-content` 钉底**:卡底动作跨卡对齐到同一水平线用的,这一档间距本来就不该固定。
|
||||
⚠ 早先这里比的是「末块 bottom 是否贴着内容底」,而内容撑开的容器里最后一块**天然**贴着底——
|
||||
等于把每条容器的最后一档间距全放过;`margin-top:auto` 的计算值是它吃掉的全部余量,也永远算不出「有余量」。
|
||||
- **并排的两块**:top 齐平 / 纵向有重叠 / 横向根本不相接。grid 多列 + `items-center` 时两块 top 会差几十 px,
|
||||
只比 top 会把并排量成 -30px 的假间距。
|
||||
- **子块自己写了 `max-width` 或 `align-self`**:页头 sub 的 72ch 栏宽是刻意的排版宽度,不是收缩错位。
|
||||
- **整块居中的排版**:容器 `items-center` 且每个子块 `align-self:center`(折叠流水那种胶囊行)——排版不是排列。
|
||||
|
||||
退出码 0/1;默认 1440 × 明暗 × 13 条路由(回归时建议 `NEX_WIDTHS=1440,768`)。
|
||||
|
||||
### 15.6 `.venv/bin/python scripts/ui/tagcheck.py` —— 量标签底色(§2.1)
|
||||
|
||||
同第七轮立项。用户口径:**项目中的浅绿色标签都要处理到新的颜色设计上**。根因两条:
|
||||
主题曾把 success/warning/error 的**文字档**当 seed 喂回去(派生出脏绿 `colorSuccessBg`)、
|
||||
页面直接写 `<Tag color="success">`。现在的口径是**标签底一律中性 `fill-tertiary`,
|
||||
语义只由头部那颗 6px 圆点承载**(整段 Notice / Alert 保留 antd 语义底)。判定分两步,
|
||||
都要沿祖先链**合成真实叠色**之后再算:
|
||||
|
||||
| 判定 | 立案阈值 | 说明 |
|
||||
|---|---|---|
|
||||
| 标签自己加没加色 | `标签合成底 − 所坐表面合成底` 的 RGB 极差 > 10 | 中性底三通道等量下降(极差 ≈ 0);`#f6ffed` 浅绿 / 脏绿 / 浅蓝 ≥ 18 |
|
||||
| 文字色 | 合成后极差 > 40 | 正文灰 18、语义绿 `#52c41a` 166 |
|
||||
|
||||
唯一例外:**选中态胶囊** `.ant-tag-checkable-checked`——点亮就是它表达「选了这颗」的方式。
|
||||
退出码 0/1;默认 1440 × 明暗 × 13 条路由。
|
||||
|
||||
### 15.7 `.venv/bin/python scripts/ui/gateprobe.py` —— 反向验证上面三张像素闸
|
||||
|
||||
第 30 轮立项:`gridcheck` / `rhythmcheck` / `tagcheck` 判的都是像素,**它们自己也需要被体检**——
|
||||
豁免写宽一格,闸门就会永远安静地返回 0。它不碰源码、不触发 HMR,直接在 `/assets` 上种两块 fixture:
|
||||
|
||||
- `pb-*`(坏):栅格该用却自然排列 / 同容器两档纵向间距 / shrink-wrap / 标签铺语义色块 —— 三道闸**必须点名**;
|
||||
- `pg-*`(好):`mt-auto` 钉底 / 整块居中的排版 / `max-w-[72ch]` 栏宽 / `.nex-chipbar` 胶囊流 —— **必须放行**。
|
||||
|
||||
任一条对不上退出码 1("闸门瞎了或过敏,先修闸门再谈页面")。改动这三道闸的判据或豁免时**必须**跑它。
|
||||
|
||||
---
|
||||
|
||||
## 16. 改动流程(每个页面必须走完)
|
||||
|
|
@ -1069,14 +1269,19 @@ NEX_WIDTHS=1440,992,768,430 NEX_THEMES=dark,light .venv/bin/python scripts/ui/vi
|
|||
4. `node scripts/ui/classaudit.mjs` → EXIT=0。**先过词汇表再谈样式**:
|
||||
缺原语就补进 kit(补的时候给它打标记类、写「症状 / 做法 / 为什么」),别在页面里临时代一套。
|
||||
5. 新写或改到一个 kit 组件时**当场反向验证**:故意把它写坏(摘掉 `forwardRef`、往 props 里塞
|
||||
`ref?:`、把 `componentSize` 下发换成死高度、把注释写进 JSX 子节点),
|
||||
`ref?:`、把 `componentSize` 下发换成死高度、把注释写进 JSX 子节点、把 `<Clamp>` 摘掉),
|
||||
确认探针立刻红并且点名,再改回来复跑回绿。没有反向验证的闸等于装饰。
|
||||
6. `npm run build`(= `tsc --noEmit` + `vite build`)→ 通过。
|
||||
7. **跑 `scripts/ui/visualcheck.py`**,改了 `theme/antd.ts` / `styles/index.css` / `styles/app.css`
|
||||
就**全量重跑**(含 430/576 窄屏),不能只跑改动页;然后**目视截图**。
|
||||
8. 结论进报告对应章节:现象 → 根因 → 改法 → 逐项验收表。
|
||||
9. **改过任何会被手册截图的界面,重拍 12 张插图**:`scripts/ui/helpshots.py`
|
||||
8. **动过表格就跑 `scripts/ui/tableaudit.py`**(§15.3):列宽、行高、横向溢出三件事
|
||||
只有浏览器量得出来,`tsc` 与 `classaudit` 都看不见。
|
||||
9. **动过布局就跑三张像素闸**(§15.4~§15.6):`gridcheck` 看该栅格没栅格、`rhythmcheck` 看
|
||||
纵向档位与收缩错位、`tagcheck` 看标签底色。改过这三道闸的判据或豁免,还要跑
|
||||
`scripts/ui/gateprobe.py`(§15.7)——豁免写宽一格,闸门就永远安静地返回 0。
|
||||
10. 结论进报告对应章节:现象 → 根因 → 改法 → 逐项验收表。
|
||||
11. **改过任何会被手册截图的界面,重拍 12 张插图**:`scripts/ui/helpshots.py`
|
||||
(`→ frontend/public/help/*.png`,1600×1000、@2x 拍完 LANCZOS 缩回、锁浅色、主角固定
|
||||
项目 12、五个项目子页先收起「项目概况」,口径写在脚本 docstring 里)。
|
||||
插图是 `<img>` 直出的静态文件,**不参与构建**:tsc / build / 两道探针全绿,
|
||||
插图是 `<img>` 直出的静态文件,**不参与构建**:tsc / build / 六道探针全绿,
|
||||
手册里也可能还是上一个皮肤的旧截图。
|
||||
|
|
|
|||
|
|
@ -149,10 +149,11 @@ const PROSE = new Set([
|
|||
'row', 'text', 'top', 'group-global', 'group-project',
|
||||
/* 2026-11 布局层改用 antd Flex 后多出来的三个 props 值 / CSS 取值:
|
||||
`wrap` 是 <Flex wrap> 这个布尔属性本身、`space-between` 是 justify="space-between"、
|
||||
`not-allowed` 是 style 里的 cursor。Tailwind 里对应的事各有正名
|
||||
`not-allowed` 是 style 里的 cursor、`flex-start` 是 <Flex align="flex-start">。
|
||||
Tailwind 里对应的事各有正名
|
||||
(flex-wrap / justify-between / cursor-not-allowed),这三个词当类名写出来必然是笔误,
|
||||
但作为 props 值天天出现,逐行切词分不清引号内外,只能在这里点名。 */
|
||||
'wrap', 'space-between', 'not-allowed',
|
||||
'wrap', 'space-between', 'not-allowed', 'flex-start',
|
||||
])
|
||||
|
||||
const dead = []
|
||||
|
|
|
|||
|
|
@ -0,0 +1,146 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""反向验证:证明三道新闸门「坏了会响、好了不响」(2026-11 第七轮起常驻)。
|
||||
|
||||
`gridcheck` / `rhythmcheck` / `tagcheck` 都是对着渲染结果量像素的探针,
|
||||
它们自己也需要被体检一次:豁免写宽一格,闸门就会永远安静地返回 0。
|
||||
这里不碰源码、不触发 HMR——直接在页面上种两块 fixture:
|
||||
|
||||
· `pb-*`(bad) :故意造出「栅格该用却自然排列 / 同一容器两档纵向间距 /
|
||||
收缩错位 / 标签铺语义色块」四种缺陷,三个闸门必须**点名**到它;
|
||||
· `pg-*`(good):故意造出四种**合法**形态(卡底 mt-auto 钉底、整块居中的排版、
|
||||
正文 max-w-[72ch] 栏宽、.nex-chipbar 胶囊流),闸门必须放行。
|
||||
|
||||
任何一条对不上就退出 1——说明闸门瞎了或者过敏,先修闸门再谈页面。
|
||||
用法:
|
||||
.venv/bin/python scripts/ui/gateprobe.py
|
||||
"""
|
||||
import importlib.util
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
HERE = pathlib.Path(__file__).resolve().parent
|
||||
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
|
||||
USER = os.environ.get("NEX_USER", "admin")
|
||||
PWD = os.environ.get("NEX_PASS", "admin1234")
|
||||
|
||||
|
||||
def load(mod_name: str):
|
||||
"""按路径加载闸门模块,直接复用它们的探针 JS,避免同一份判据写两遍。"""
|
||||
spec = importlib.util.spec_from_file_location(mod_name, HERE / f"{mod_name}.py")
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
|
||||
tagcheck = load("tagcheck")
|
||||
rhythmcheck = load("rhythmcheck")
|
||||
gridcheck = load("gridcheck")
|
||||
|
||||
FIXTURE = r"""() => {
|
||||
const old = document.getElementById('nex-gateprobe'); if (old) old.remove();
|
||||
const host = document.createElement('div');
|
||||
host.id = 'nex-gateprobe';
|
||||
host.style.cssText = 'padding:24px;display:flex;flex-direction:column;gap:0';
|
||||
host.innerHTML = `
|
||||
<div class="pb-gap" style="display:flex;flex-direction:column;width:400px">
|
||||
<div style="height:30px"></div>
|
||||
<div style="height:30px;margin-top:8px"></div>
|
||||
<div style="height:30px;margin-top:20px"></div>
|
||||
</div>
|
||||
<span class="ant-tag pb-tag" style="display:inline-block;width:120px;height:24px;
|
||||
background:#f6ffed;color:#237804;border:1px solid #b7eb8f">反向验证标签</span>
|
||||
<div class="pb-rag" style="display:flex;flex-direction:column;align-items:flex-start;width:400px">
|
||||
<div style="width:400px;height:30px"></div>
|
||||
<div style="width:150px;height:30px"></div>
|
||||
<div style="width:250px;height:30px"></div>
|
||||
</div>
|
||||
<div class="pb-grid" style="display:flex;flex-direction:row;flex-wrap:wrap;gap:8px;width:900px">
|
||||
<input class="ant-input" style="width:120px" value="甲" />
|
||||
<input class="ant-input" style="width:300px" value="乙" />
|
||||
<input class="ant-input" style="width:160px" value="丙" />
|
||||
</div>
|
||||
<div class="pg-pin" style="display:flex;flex-direction:column;height:200px;width:400px">
|
||||
<div style="height:40px"></div>
|
||||
<div style="height:40px"></div>
|
||||
<div class="mt-auto" style="height:40px"></div>
|
||||
</div>
|
||||
<div class="pg-center" style="display:flex;flex-direction:column;align-items:center;width:400px">
|
||||
<div style="width:400px;height:30px;align-self:center"></div>
|
||||
<div style="width:150px;height:30px;align-self:center"></div>
|
||||
<div style="width:200px;height:30px;align-self:center"></div>
|
||||
</div>
|
||||
<div class="pg-measure" style="display:flex;flex-direction:column;width:400px">
|
||||
<div style="height:30px"></div>
|
||||
<div style="height:30px;max-width:200px"></div>
|
||||
<div style="height:30px;max-width:240px"></div>
|
||||
</div>
|
||||
<div class="nex-chipbar pg-chipbar" style="display:flex;flex-direction:row;flex-wrap:wrap;gap:8px;width:900px">
|
||||
<span class="nex-chip ant-tag ant-tag-checkable" style="display:inline-block;width:80px;height:24px">甲</span>
|
||||
<span class="nex-chip ant-tag ant-tag-checkable" style="display:inline-block;width:210px;height:24px">乙乙乙</span>
|
||||
<span class="nex-chip ant-tag ant-tag-checkable" style="display:inline-block;width:120px;height:24px">丙丙</span>
|
||||
</div>`;
|
||||
(document.querySelector('main') || document.body).appendChild(host);
|
||||
return [...host.querySelectorAll('[class]')].length;
|
||||
}"""
|
||||
|
||||
|
||||
def names(rows, key):
|
||||
"""把检出结果摊平成「元素标记串」,再用 fixture 的类名点名。"""
|
||||
return " | ".join(str(r.get(key, "")) for r in rows)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
fails = []
|
||||
with sync_playwright() as pw:
|
||||
b = pw.chromium.launch()
|
||||
pg = b.new_context(viewport={"width": 1440, "height": 1600}).new_page()
|
||||
pg.set_default_timeout(20000)
|
||||
pg.goto(BASE + "/login")
|
||||
pg.wait_for_selector("#login-user")
|
||||
pg.fill("#login-user", USER)
|
||||
pg.fill("#login-pass", PWD)
|
||||
pg.click("button[type=submit]")
|
||||
pg.wait_for_url(lambda u: "/login" not in u, timeout=20000)
|
||||
pg.goto(BASE + "/assets")
|
||||
pg.wait_for_timeout(1400)
|
||||
n = pg.evaluate(FIXTURE)
|
||||
pg.wait_for_timeout(300)
|
||||
print("fixture nodes:", n)
|
||||
|
||||
checks = [
|
||||
("tagcheck", tagcheck.JS, "el", [("pb-tag", True), ("ant-input", False)]),
|
||||
("rhythmcheck.GAP", rhythmcheck.GAP, "el",
|
||||
[("pb-gap", True), ("pg-pin", False)]),
|
||||
("rhythmcheck.RAG", rhythmcheck.RAG, "el",
|
||||
[("pb-rag", True), ("pg-center", False), ("pg-measure", False)]),
|
||||
("gridcheck", gridcheck.JS, "el",
|
||||
[("pb-grid", True), ("pg-chipbar", False)]),
|
||||
]
|
||||
for label, js, key, expectations in checks:
|
||||
rows = pg.evaluate(js)
|
||||
hay = names(rows, key)
|
||||
for marker, should_fire in expectations:
|
||||
hit = marker in hay
|
||||
ok = hit == should_fire
|
||||
print(f"{'OK ' if ok else 'FAIL'} {label:<18} {marker:<12} "
|
||||
f"{'必须点名' if should_fire else '必须放行'} "
|
||||
f"→ {'点名了' if hit else '没点名'}")
|
||||
if not ok:
|
||||
fails.append(f"{label}/{marker}")
|
||||
print(" 实际:", hay[:400])
|
||||
b.close()
|
||||
|
||||
if fails:
|
||||
print("GATEPROBE_FAIL", " ".join(fails))
|
||||
print("→ 闸门本身出问题:不是漏检(豁免写宽了)就是误报(豁免没生效),先修闸门")
|
||||
return 1
|
||||
print("GATEPROBE_OK 4/4 闸门坏了会响、好了不响")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""栅格体检:找「该用栅格却在自然排列」的容器(2026-11 第七轮起常驻)。
|
||||
|
||||
用户口径:**该用 grid 的地方不要用自然排列**。自然排列(`flex-wrap`)在同类子块
|
||||
宽度参差时会产出两种坏画面:① 一行里右边缘参差不齐;② 折行点随内容漂移,
|
||||
第二行的左边缘对不上第一行。同量子块只要 >2 个并排,就必须落在栅格里
|
||||
(`Ctlbar cols={n}` / `Row+Col` / `OptionGrid` / CSS grid)。
|
||||
|
||||
判定(对着渲染结果量,不看代码):
|
||||
容器 = display:flex + flex-direction:row + flex-wrap:wrap;
|
||||
子块按「族」归类(form-item / select / input / number / card / check / seg …),
|
||||
**同一族 ≥3 颗**才立案——混排的胶囊流本来就不要求等宽。
|
||||
立案条件(任一):
|
||||
rag 同族子块宽度极差 > 40px(一行放得下也没对齐)
|
||||
misalign 折行后各行左边缘极差 > 8px(折行点随意)
|
||||
折行错位按**容器全部子块**分行——行首的标签 / 前置按钮会把第一行推右,
|
||||
只按同族子块分行会把这算成 100~270px 的假错位。
|
||||
按族豁免:
|
||||
btn 按钮组本就该按内容自然排列(同概念不跨行由 visualcheck 的 ActionGroup 断言管)
|
||||
span .nex-chipbar / .nex-taggroup 里的胶囊与只读标签:筛已有内容 = 胶囊流,
|
||||
宽度**必须**跟着文案走,等宽反而读不出区别
|
||||
用法:
|
||||
NEX_THEMES=light NEX_WIDTHS=1440,1280,1024 .venv/bin/python scripts/ui/gridcheck.py
|
||||
退出码:0 = 干净,1 = 有立案。
|
||||
"""
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
from collections import Counter
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
|
||||
WIDTHS = [int(x) for x in os.environ.get("NEX_WIDTHS", "1440,1280,1024").split(",")]
|
||||
THEMES = os.environ.get("NEX_THEMES", "light").split(",")
|
||||
ROUTES = [r for r in os.environ.get(
|
||||
"NEX_ROUTES",
|
||||
"/,/assets,/models,/projects/{id}/overview,/projects/{id}/library,"
|
||||
"/projects/{id}/storyboard,/projects/{id}/dispatch,/projects/{id}/review,"
|
||||
"/projects/{id}/timeline,/projects/{id}/delivery,/account,/users,/help").split(",") if r]
|
||||
USER = os.environ.get("NEX_USER", "admin")
|
||||
PWD = os.environ.get("NEX_PASS", "admin1234")
|
||||
OUT = pathlib.Path(os.environ.get("NEX_SHOTS", "/tmp/nex_ui_grid")); OUT.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
PROJECT_JS = r"""async () => {
|
||||
const t = localStorage.getItem('nex-auth');
|
||||
const tok = t ? (JSON.parse(t)?.state?.token || JSON.parse(t)?.token) : '';
|
||||
const h = {headers: {Authorization: 'Bearer ' + tok}};
|
||||
const j = await (await fetch('/api/projects', h)).json();
|
||||
const list = j.projects || j.items || j.data || (Array.isArray(j) ? j : []);
|
||||
let best = ''; let n = -1;
|
||||
for (const p of list) {
|
||||
const s = await (await fetch(`/api/projects/${p.id}/shots`, h)).json();
|
||||
const c = s.count ?? (s.shots || []).length;
|
||||
if (c > n) { n = c; best = p.id; }
|
||||
}
|
||||
return best || list[0]?.id || '';
|
||||
}"""
|
||||
|
||||
JS = r"""() => {
|
||||
const cls=(el)=>(typeof el.className==='string'?el.className:'').trim().split(/\s+/).slice(0,5).join('.');
|
||||
// 子块「同类」判定:同一控件族才要求等宽
|
||||
const kind=(el)=>{
|
||||
if (el.matches('.ant-form-item')) return 'form-item';
|
||||
if (el.matches('.ant-card')) return 'card';
|
||||
if (el.matches('.ant-select')) return 'select';
|
||||
if (el.matches('.ant-input-affix-wrapper,.ant-input')) return 'input';
|
||||
if (el.matches('.ant-input-number')) return 'number';
|
||||
if (el.matches('.ant-btn')) return 'btn';
|
||||
if (el.matches('.ant-checkbox-wrapper')) return 'check';
|
||||
if (el.matches('.ant-radio-button-wrapper,.ant-segmented-item')) return 'seg';
|
||||
if (el.matches('.nex-chip,.ant-tag-checkable')) return 'tile'; // 可点胶囊 / 可选项
|
||||
if (el.matches('.ant-tag')) return 'tag'; // 只读回显标签
|
||||
if (el.matches('.nex-tile,.nex-opt-cell')) return 'tile';
|
||||
return ''; // 裸 span/div/a 是内容不是控件族
|
||||
};
|
||||
const out=[];
|
||||
for (const el of document.querySelectorAll('main *')) {
|
||||
const cs=getComputedStyle(el);
|
||||
if (cs.display!=='flex'||cs.flexDirection!=='row'||cs.flexWrap==='nowrap') continue;
|
||||
const kids=[...el.children].filter(c=>{const k=getComputedStyle(c),r=c.getBoundingClientRect();
|
||||
return k.display!=='none'&&k.position!=='absolute'&&k.position!=='fixed'&&r.height>4&&r.width>20;});
|
||||
if (kids.length<3) continue;
|
||||
const byKind={};
|
||||
kids.forEach(k=>{const g=kind(k);(byKind[g]=byKind[g]||[]).push(k);});
|
||||
for (const [g,set] of Object.entries(byKind)) {
|
||||
if (!g || set.length<3) continue;
|
||||
if (g==='btn') continue; // 按钮组本就该自然排列
|
||||
/* 只读标签(kit Tag / Status)整族豁免:宽度天生跟文案走。
|
||||
「完成 6/6」「待补 2」这种并排回显挤在一起是设计意图,等宽反而读不出差别;
|
||||
真正该上栅格的是**可选项**,它们走 Chip / OptionGrid(tile 族),仍然在检查里。
|
||||
胶囊流(.nex-chipbar / .nex-taggroup)里的可点 Chip 同理豁免。 */
|
||||
if (g==='tag') continue;
|
||||
if (g==='tile' && set.every(k=>k.closest('.nex-chipbar,.nex-taggroup,.ant-pagination'))) continue;
|
||||
const ws=set.map(k=>Math.round(k.getBoundingClientRect().width));
|
||||
const rag=Math.max(...ws)-Math.min(...ws);
|
||||
/* 折行错位要按**容器全部子块**分行:行首常有标签 / 选择按钮这类前置件,
|
||||
只按同族子块分行会把「第一行被前置件推右」误判成折行错位(104~270px 的假案)。
|
||||
分行容差 10px:居中排列时同排子块的 top 会差几像素。 */
|
||||
const rows=[];
|
||||
for (const k of kids.map(c=>({l:c.getBoundingClientRect().left,t:c.getBoundingClientRect().top}))
|
||||
.sort((x,y)=>x.t-y.t)) {
|
||||
const r=rows.find(g2=>Math.abs(g2.t-k.t)<=10); if (r) r.ls.push(k.l); else rows.push({t:k.t,ls:[k.l]});
|
||||
}
|
||||
const starts=rows.map(r=>Math.round(Math.min(...r.ls)));
|
||||
const misalign=rows.length>1 ? Math.max(...starts)-Math.min(...starts) : 0;
|
||||
if (misalign<=8 && rag<=40) continue;
|
||||
if (rag>40 || misalign>8) out.push({kind:g,n:set.length,rag,misalign,rows:rows.length,
|
||||
el:el.tagName.toLowerCase()+'.'+cls(el).slice(0,70),widths:ws.slice(0,8),
|
||||
rows:rows.length,n:set.length,
|
||||
texts:set.slice(0,6).map(k=>((k.innerText||'').trim().slice(0,10)))});
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
|
||||
def main() -> int:
|
||||
seen: Counter = Counter()
|
||||
detail: dict = {}
|
||||
with sync_playwright() as pw:
|
||||
b = pw.chromium.launch()
|
||||
ctx = b.new_context(viewport={"width": 1440, "height": 900})
|
||||
pg = ctx.new_page()
|
||||
pg.set_default_timeout(20000)
|
||||
pg.goto(BASE + "/login")
|
||||
pg.wait_for_selector("#login-user")
|
||||
pg.fill("#login-user", USER)
|
||||
pg.fill("#login-pass", PWD)
|
||||
pg.click("button[type=submit]")
|
||||
pg.wait_for_url(lambda u: "/login" not in u, timeout=20000)
|
||||
pid = pg.evaluate(PROJECT_JS)
|
||||
for width in WIDTHS:
|
||||
pg.set_viewport_size({"width": width, "height": 900})
|
||||
for theme in THEMES:
|
||||
pg.evaluate("(t) => localStorage.setItem('nex-the', t)", theme)
|
||||
for r in ROUTES:
|
||||
if "{id}" in r and not pid:
|
||||
continue
|
||||
route = r.replace("{id}", str(pid))
|
||||
pg.goto(BASE + route)
|
||||
pg.wait_for_timeout(1300)
|
||||
for row in pg.evaluate(JS):
|
||||
key = (route, theme, width, row["el"][:70], row["kind"])
|
||||
seen[key] += 1
|
||||
detail.setdefault(key, row)
|
||||
b.close()
|
||||
|
||||
for k, v in seen.items():
|
||||
d = detail[k]
|
||||
print(f"{k[0]:<32} {k[1]}/{k[2]} x{v:<2} {k[4]:<10} "
|
||||
f"rag={d['rag']:<4} mis={d['misalign']:<4} rows={d['rows']} n={d['n']} {k[3][:60]}")
|
||||
print(f" widths={d['widths']} texts={d['texts']}")
|
||||
total = sum(seen.values())
|
||||
print("GRID_TOTAL", total, "unique", len(seen))
|
||||
if total:
|
||||
print("→ 这些容器同族子块 ≥3 却没走栅格:改 Ctlbar cols={n} / Row+Col / OptionGrid,"
|
||||
"或确认它属于胶囊流(应在 .nex-chipbar / .nex-taggroup 里)")
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
@ -0,0 +1,188 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""节奏体检:组件之间的上下、左右边距是否由**版面尺子**给(2026-11 第七轮起常驻)。
|
||||
|
||||
用户口径:**组件之间的上下、左右边距要合理**。本站唯一的纵向间距来源是
|
||||
`PageStack`(页内区块)与栅格 `gutter`(格与格),页面里再补 `mt-*/mb-*`
|
||||
就会同一屏出现 12/16/20/24 混着来。这里对着渲染结果量两件事:
|
||||
|
||||
1) 纵向节奏(gap):容器(flex-column / grid / .nex-stack)里相邻可见子块的
|
||||
实际间距必须**只有一档**,且 ≤ 24px(= --ant-margin 那一档)。
|
||||
豁免三种合法形态:
|
||||
· 末块**钉**在容器内容底——只认既定写法(卡底动作 `mt-auto`、`justify-content`
|
||||
钉两端),跨卡把按钮排到同一水平线上用的,这一档间距本来就不该固定;
|
||||
钉底不能读像素(margin-top:auto 的计算值恰好等于它吃掉的余量,永远算不出
|
||||
「有余量」;而内容撑开的列容器里末块天然贴着内容底,只比位置等于把全站末档全放过);
|
||||
· 同一行的两块(top 齐平 / 纵向重叠 / 横向不相接——grid 多列 + items-center
|
||||
时两块的 top 会差几十 px,只比 top 会把并排量成 -30px 的假间距);
|
||||
· 单行胶囊按钮(高 ≤48,宽度跟文案走是设计意图)。
|
||||
2) 收缩错位(ragged):flex-column 容器把子块排成「一块宽一块窄」的
|
||||
shrink-wrap 效果。同样豁免两种刻意行为:子块自己写了 max-width / align-self
|
||||
(正文 `max-w-[72ch]` 这种栏宽)、整块内容居中(容器 items-center 且每个子块
|
||||
align-self:center,是排版不是排列)。
|
||||
|
||||
用法:
|
||||
NEX_THEMES=light,dark NEX_WIDTHS=1440,1280 .venv/bin/python scripts/ui/rhythmcheck.py
|
||||
退出码:0 = 干净,1 = 有立案。
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
|
||||
WIDTHS = [int(x) for x in os.environ.get("NEX_WIDTHS", "1440").split(",")]
|
||||
THEMES = os.environ.get("NEX_THEMES", "light,dark").split(",")
|
||||
ROUTES = [r for r in os.environ.get(
|
||||
"NEX_ROUTES",
|
||||
"/,/assets,/models,/projects/{id}/overview,/projects/{id}/library,"
|
||||
"/projects/{id}/storyboard,/projects/{id}/dispatch,/projects/{id}/review,"
|
||||
"/projects/{id}/timeline,/projects/{id}/delivery,/account,/users,/help").split(",") if r]
|
||||
USER = os.environ.get("NEX_USER", "admin")
|
||||
PWD = os.environ.get("NEX_PASS", "admin1234")
|
||||
OUT = pathlib.Path(os.environ.get("NEX_SHOTS", "/tmp/nex_ui_rhythm")); OUT.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
PROJECT_JS = r"""async () => {
|
||||
const t = localStorage.getItem('nex-auth');
|
||||
const tok = t ? (JSON.parse(t)?.state?.token || JSON.parse(t)?.token) : '';
|
||||
const h = {headers: {Authorization: 'Bearer ' + tok}};
|
||||
const j = await (await fetch('/api/projects', h)).json();
|
||||
const list = j.projects || j.items || j.data || (Array.isArray(j) ? j : []);
|
||||
let best = ''; let n = -1;
|
||||
for (const p of list) {
|
||||
const s = await (await fetch(`/api/projects/${p.id}/shots`, h)).json();
|
||||
const c = s.count ?? (s.shots || []).length;
|
||||
if (c > n) { n = c; best = p.id; }
|
||||
}
|
||||
return best || list[0]?.id || '';
|
||||
}"""
|
||||
|
||||
# 纵向节奏:同一容器内相邻子块的间距只准一档
|
||||
GAP = r"""() => {
|
||||
const cls=(el)=>(typeof el.className==='string'?el.className:'').trim().split(/\s+/).slice(0,4).join('.');
|
||||
const out=[];
|
||||
const all=[document.querySelector('main')||document.body,...document.querySelectorAll('main *')];
|
||||
for (const el of all) {
|
||||
const cs=getComputedStyle(el);
|
||||
if (!(el.classList.contains('nex-stack')||(cs.display==='flex'&&cs.flexDirection==='column')||cs.display==='grid')) continue;
|
||||
const kids=[...el.children].filter(c=>{const k=getComputedStyle(c),r=c.getBoundingClientRect();
|
||||
return k.display!=='none'&&k.position!=='absolute'&&k.position!=='fixed'&&r.height>6&&r.width>120;});
|
||||
if (kids.length<2) continue;
|
||||
const gaps=[];
|
||||
const box=el.getBoundingClientRect();
|
||||
const pb=parseFloat(cs.paddingBottom)||0;
|
||||
/* 「末块是钉到底上的」只能读写法,不能读像素:margin-top:auto 的计算值就是
|
||||
它吃掉的全部余量,于是「有余量」永远算不出来;而内容撑开的容器里最后一块
|
||||
**天然**贴着内容底,只看位置等于把每条容器的最后一档间距全放过。
|
||||
本站钉底只有两种写法:卡底动作的 `mt-auto`,和 justify-content 的钉两端。 */
|
||||
const jc=['flex-end','space-between','space-around','space-evenly'].includes(cs.justifyContent);
|
||||
const isPin=(k)=>/(^|\s)mt-auto(\s|$)/.test(typeof k.className==='string'?k.className:'')
|
||||
|| (k.style && k.style.marginTop==='auto') || jc;
|
||||
for (let i=1;i<kids.length;i++){
|
||||
const a=kids[i-1].getBoundingClientRect(),b=kids[i].getBoundingClientRect();
|
||||
/* 「同一行」的三种形态都要跳过:top 齐平;纵向有重叠;横向根本不相接
|
||||
(grid 多列 + items-center 时两个子块的 top 会差几十 px,只比 top 会把
|
||||
并排的两块当成上下两块,量出 -30px 的假间距)。 */
|
||||
const vOverlap = a.top < b.bottom - 1 && b.top < a.bottom - 1;
|
||||
const sideBySide = a.right <= b.left + 1 || b.right <= a.left + 1;
|
||||
if (Math.abs(a.top-b.top)<2 || vOverlap || sideBySide) continue;
|
||||
// 末块确实钉在容器「内容底」(减掉下内边距,直接比 border box 会永远差一个 padding)
|
||||
// 注意 isPin 要读**元素**——b 已经是 DOMRect 了,传进去永远判不出钉底
|
||||
if (i===kids.length-1 && isPin(kids[i])) {
|
||||
if (Math.abs(box.bottom-pb-b.bottom)<=2) continue;
|
||||
}
|
||||
gaps.push(Math.round(b.top-(a.top+a.height)));
|
||||
}
|
||||
if (!gaps.length) continue;
|
||||
const uniq=[...new Set(gaps.map(g=>Math.abs(g)))];
|
||||
if (uniq.length>1||uniq[0]>24) out.push({el:el.tagName.toLowerCase()+'.'+cls(el),kids:kids.length,gaps,
|
||||
detail:kids.slice(0,8).map(k=>k.tagName.toLowerCase()+'.'+cls(k)+':'+Math.round(k.getBoundingClientRect().height))});
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
# shrink-wrap:列容器里子块宽度参差
|
||||
RAG = r"""() => {
|
||||
const cls=(el)=>(typeof el.className==='string'?el.className:'').trim().split(/\s+/).slice(0,4).join('.');
|
||||
const out=[];
|
||||
for (const el of document.querySelectorAll('main *')) {
|
||||
const cs=getComputedStyle(el);
|
||||
const col=el.classList.contains('nex-tile')||(cs.display==='flex'&&cs.flexDirection==='column');
|
||||
if (!col) continue;
|
||||
const kids=[...el.children].filter(c=>{const k=getComputedStyle(c),r=c.getBoundingClientRect();
|
||||
return k.display!=='none'&&k.display!=='contents'&&k.position!=='absolute'&&k.position!=='fixed'&&r.height>10&&r.width>40;});
|
||||
if (kids.length<2) continue;
|
||||
const cw=el.getBoundingClientRect().width; if (cw<260) continue;
|
||||
const hh=el.getBoundingClientRect().height;
|
||||
// 单行胶囊 / 标签按钮:align-items:center + 子块宽度跟文案走,本来就该收缩
|
||||
if (hh<=48) continue;
|
||||
/* 「比容器窄」有两种,只有一种是病:
|
||||
· 子块自己写了 max-width(正文 72ch 那种刻意的栏宽)或 align-self——是设计选择,放行;
|
||||
· 整块内容居中(容器 items-center 且每个子块 align-self:center)——排版不是排列,放行;
|
||||
· 剩下的才是 shrink-wrap:容器在要求撑满,子块却各自贴着内容宽度,左右边缘七零八落。 */
|
||||
const optOut=(k)=>{const s=getComputedStyle(k);
|
||||
return s.maxWidth!=='none'||s.alignSelf!=='auto'||/max-w-|w-\[/.test(typeof k.className==='string'?k.className:'');};
|
||||
const widths=kids.map(k=>Math.round(k.getBoundingClientRect().width));
|
||||
const ragged=kids.some((k,i)=>cw-widths[i]>48&&!optOut(k));
|
||||
const al=cs.alignItems;
|
||||
const centered=al==='center'&&kids.every(k=>getComputedStyle(k).alignSelf==='center');
|
||||
if (al==='flex-start'||al==='start'||al==='end'||al==='baseline'||
|
||||
(ragged&&!centered&&al!=='center'&&!el.classList.contains('nex-stack')))
|
||||
out.push({el:el.tagName.toLowerCase()+'.'+cls(el),align:al,cw:Math.round(cw),widths,
|
||||
first:kids[0].tagName.toLowerCase()+'.'+cls(kids[0]).slice(0,40)});
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
|
||||
def main() -> int:
|
||||
res = {"gap": {}, "rag": {}}
|
||||
with sync_playwright() as pw:
|
||||
b = pw.chromium.launch()
|
||||
pg = b.new_context(viewport={"width": 1440, "height": 900}).new_page()
|
||||
pg.set_default_timeout(20000)
|
||||
pg.goto(BASE + "/login")
|
||||
pg.wait_for_selector("#login-user")
|
||||
pg.fill("#login-user", USER)
|
||||
pg.fill("#login-pass", PWD)
|
||||
pg.click("button[type=submit]")
|
||||
pg.wait_for_url(lambda u: "/login" not in u, timeout=20000)
|
||||
pid = pg.evaluate(PROJECT_JS)
|
||||
for width in WIDTHS:
|
||||
pg.set_viewport_size({"width": width, "height": 900})
|
||||
for theme in THEMES:
|
||||
pg.evaluate("(t) => localStorage.setItem('nex-the', t)", theme)
|
||||
for r in ROUTES:
|
||||
if "{id}" in r and not pid:
|
||||
continue
|
||||
route = r.replace("{id}", str(pid))
|
||||
pg.goto(BASE + route)
|
||||
pg.wait_for_timeout(1300)
|
||||
key = f"{route}@{width}/{theme}"
|
||||
res["gap"][key] = pg.evaluate(GAP)
|
||||
res["rag"][key] = pg.evaluate(RAG)
|
||||
bg = pg.evaluate("getComputedStyle(document.body).backgroundColor")
|
||||
b.close()
|
||||
|
||||
for k in res["gap"]:
|
||||
for x in res["gap"][k]:
|
||||
print(f"GAP {k:<34} {x['el'][:60]} kids={x['kids']} gaps={x['gaps']}")
|
||||
print(f" {x['detail']}")
|
||||
for k in res["rag"]:
|
||||
for x in res["rag"][k]:
|
||||
print(f"RAG {k:<34} {x['el'][:60]} align={x['align']} cw={x['cw']} widths={x['widths']}")
|
||||
g = sum(len(v) for v in res["gap"].values())
|
||||
rg = sum(len(v) for v in res["rag"].values())
|
||||
print("body-bg", bg, "GAP_TOTAL", g, "RAGGED_TOTAL", rg)
|
||||
(OUT / "rhythm.json").write_text(json.dumps(res, ensure_ascii=False, indent=1))
|
||||
if g or rg:
|
||||
print("→ 纵向间距只准由 PageStack / 栅格 gutter 给:删掉页面里补的 mt-*/mb-*,"
|
||||
"或给列容器 items-stretch 让子块撑满")
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""表格体检(第三道常驻探针,2026-11 第 28 轮起):登录 → 逐路由量每一张表的
|
||||
「容器宽 / 可视宽 / 内容宽 / 各列宽 / 最高行 / 把行撑高的那个元素」。
|
||||
|
||||
为什么要它:行高是最容易「编译通过但页面是坏的」的一类。长文案列没给够宽就塞进
|
||||
表格,单元格会折成四五行,整行被顶到 100~250px,一屏只能看见三条记录——tsc、
|
||||
build、classaudit 全都测不出来,visualcheck 也只管溢出不管行高。所以这里把两条
|
||||
红线钉死(见 docs/UI规范.md §13.2 R17):
|
||||
1) 数据行最高 ≤ NEX_ROW_H_MAX(默认 84px ≈ 正文两行 + 一行次要元信息);
|
||||
2) 横向溢出 ≤ NEX_SCROLL_SLACK(默认 40px,定宽列合计必须回到容器内)。
|
||||
空态行(.ant-table-placeholder)是 antd 自己那条 60px 占位,不算数据行,跳过。
|
||||
|
||||
用法:
|
||||
NEX_ROUTES="/,/assets,/projects/10/delivery" .venv/bin/python scripts/ui/tableaudit.py
|
||||
# 路由里的 {id} 会用登录后的会话自动补成第一个项目的 id
|
||||
退出码 = 违规表的张数(0 = 全绿)。
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
|
||||
WIDTH = int(os.environ.get("NEX_WIDTH", "1440"))
|
||||
USER = os.environ.get("NEX_USER", "admin")
|
||||
PWD = os.environ.get("NEX_PASS", "admin1234")
|
||||
ROW_H_MAX = int(os.environ.get("NEX_ROW_H_MAX", "84"))
|
||||
SCROLL_SLACK = int(os.environ.get("NEX_SCROLL_SLACK", "40"))
|
||||
ROUTES = [r for r in os.environ.get(
|
||||
"NEX_ROUTES",
|
||||
"/,/assets,/models,/projects/{id}/overview,/projects/{id}/library,"
|
||||
"/projects/{id}/storyboard,/projects/{id}/dispatch,/projects/{id}/review,"
|
||||
"/projects/{id}/timeline,/projects/{id}/delivery").split(",") if r]
|
||||
|
||||
# 空项目每张表都是空态行,量不到任何东西 ⇒ {id} 取「镜头最多」的那个项目,
|
||||
# 而不是列表第一个(开发库里第一个往往是刚建的空项目)。
|
||||
PROJECT_JS = r"""async () => {
|
||||
const t = localStorage.getItem('nex-auth');
|
||||
const tok = t ? (JSON.parse(t)?.state?.token || JSON.parse(t)?.token) : '';
|
||||
const h = {headers: {Authorization: 'Bearer ' + tok}};
|
||||
const j = await (await fetch('/api/projects', h)).json();
|
||||
const list = j.projects || j.items || j.data || (Array.isArray(j) ? j : []);
|
||||
let best = ''; let n = -1;
|
||||
for (const p of list) {
|
||||
const s = await (await fetch(`/api/projects/${p.id}/shots`, h)).json();
|
||||
const c = s.count ?? (s.shots || []).length;
|
||||
if (c > n) { n = c; best = p.id; }
|
||||
}
|
||||
return best || list[0]?.id || '';
|
||||
}"""
|
||||
|
||||
# 一张表 → 一行报告。撑高元凶按「格子内高度最大的那个后代元素」给出,
|
||||
# 直接指到 class 名,省得再人肉开 devtools。
|
||||
PROBE = r"""() => [...document.querySelectorAll('.ant-table-wrapper')].map((w, i) => {
|
||||
const body = w.querySelector('.ant-table-body') || w.querySelector('.ant-table-content');
|
||||
const head = [...w.querySelectorAll('.ant-table-thead th')]
|
||||
.filter(th => !th.className.includes('ant-table-cell-scrollbar'))
|
||||
.map(th => ({ t: (th.textContent || '').trim().slice(0, 8), w: Math.round(th.getBoundingClientRect().width) }));
|
||||
// measure 行是 rc-table 的量尺占位、placeholder 行是 antd 的空态,都不算数据行
|
||||
const rows = [...w.querySelectorAll('.ant-table-tbody tr')]
|
||||
.filter(r => !r.className.includes('measure') && !r.className.includes('placeholder'));
|
||||
const tall = rows.map(r => {
|
||||
const cells = [...r.children].map(td => {
|
||||
let worst = null;
|
||||
td.querySelectorAll('*').forEach(el => {
|
||||
const h = Math.round(el.getBoundingClientRect().height);
|
||||
if (!worst || h > worst.h) worst = { h, s: el.tagName + '.' + String(el.className).slice(0, 34) };
|
||||
});
|
||||
return { t: (td.textContent || '').trim().slice(0, 16), w: Math.round(td.getBoundingClientRect().width),
|
||||
h: Math.round(td.getBoundingClientRect().height), worst };
|
||||
});
|
||||
return { h: Math.round(r.getBoundingClientRect().height), cells };
|
||||
}).sort((a, b) => b.h - a.h)[0] || null;
|
||||
const title = (w.closest('.ant-card')?.querySelector('.ant-card-head-title')?.textContent || '').trim().slice(0, 18);
|
||||
return { i, title, rows: rows.length,
|
||||
boxW: Math.round(w.getBoundingClientRect().width),
|
||||
clientW: body ? body.clientWidth : 0, scrollW: body ? body.scrollWidth : 0,
|
||||
maxRowH: tall ? tall.h : 0, head, tall };
|
||||
})"""
|
||||
|
||||
|
||||
def login(page) -> None:
|
||||
page.goto(BASE + "/login", wait_until="networkidle")
|
||||
if page.locator("#login-user").count():
|
||||
page.fill("#login-user", USER)
|
||||
page.fill("#login-pass", PWD)
|
||||
page.click("button[type=submit]")
|
||||
page.wait_for_timeout(1500)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
bad = 0
|
||||
with sync_playwright() as pw:
|
||||
browser = pw.chromium.launch()
|
||||
page = browser.new_page(viewport={"width": WIDTH, "height": 1100})
|
||||
login(page)
|
||||
for route in ROUTES:
|
||||
if "{id}" in route:
|
||||
pid = page.evaluate(PROJECT_JS)
|
||||
if not pid:
|
||||
print("!! 拿不到项目 id,跳过", route)
|
||||
continue
|
||||
route = route.replace("{id}", str(pid))
|
||||
page.goto(BASE + route, wait_until="networkidle")
|
||||
page.wait_for_timeout(2200)
|
||||
tables = [t for t in page.evaluate(PROBE) if t["rows"]]
|
||||
if not tables:
|
||||
continue
|
||||
print("=" * 24, route)
|
||||
for t in tables:
|
||||
over_w = t["scrollW"] - t["clientW"]
|
||||
flags = []
|
||||
if t["maxRowH"] > ROW_H_MAX:
|
||||
flags.append(f"行高超 {ROW_H_MAX}")
|
||||
if over_w > SCROLL_SLACK:
|
||||
flags.append(f"横向溢出 {over_w}")
|
||||
mark = " ⚠ " + "、".join(flags) if flags else ""
|
||||
print(f'#{t["i"]} 「{t["title"]}」 容器{t["boxW"]} 可视{t["clientW"]}/内容{t["scrollW"]} '
|
||||
f'行{t["rows"]} 最高行{t["maxRowH"]}{mark}')
|
||||
print(" 列:", " ".join(f'{c["t"]}={c["w"]}' for c in t["head"]))
|
||||
if flags and t["tall"]:
|
||||
print(" 撑高行", t["tall"]["h"], "→", " | ".join(
|
||||
f'{c["t"]}@{c["w"]}x{c["h"]}' for c in t["tall"]["cells"] if c["h"] > 48))
|
||||
worst = max((c["worst"] for c in t["tall"]["cells"] if c["worst"]),
|
||||
key=lambda x: x["h"], default=None)
|
||||
if worst:
|
||||
print(f' 元凶 h={worst["h"]} {worst["s"]}')
|
||||
if flags:
|
||||
bad += 1
|
||||
browser.close()
|
||||
print(f"\n=== 违规 {bad} 张表 ===")
|
||||
return bad
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""标签底色体检:标签只准中性底 + 语义圆点,不许再铺语义色块(2026-11 第七轮起常驻)。
|
||||
|
||||
用户口径:**项目中的浅绿色标签都要处理到新的颜色设计上**。
|
||||
根因有两条,都在这条闸门里钉死:
|
||||
1) `theme/antd.ts` 曾把 success/warning/error 的**文字档**当 seed 喂回主题,
|
||||
派生出来的 `colorSuccessBg` 变成一块脏绿,全站「完成 / 就绪」标签都穿着它;
|
||||
2) 页面直接写 antd 的 `<Tag color="success">`(预设色标签=#f6ffed 浅绿底)。
|
||||
现在的口径(components/ui/Status.tsx 顶部有完整说明):
|
||||
· 标签底一律中性(fill-tertiary),文字正文色;
|
||||
· 语义只由头部那颗 6px 圆点承载,色值仍只有 `--ant-color-<语义>` 一个来源;
|
||||
· 整段提示(Notice / Alert)保留 antd 的语义底,那是它表达「这是一条通知」的方式。
|
||||
|
||||
判定分两步,都要**沿祖先链合成真实叠色**之后再算:
|
||||
1) **标签自己加没加色**:`标签合成底 − 它所坐表面的合成底` 的 RGB 极差 ≤ 10。
|
||||
中性 fill-tertiary 与本站表面同属 antd 中性色板,叠上去三通道等量下降(极差 ≈ 0);
|
||||
`#f6ffed` 浅绿 / `#d2dec8` 脏绿 / `#e6f4ff` 浅蓝的极差 ≥ 18,一律立案。
|
||||
只看合成底不行——标签坐在一块蓝底信息块上时会整片误判。
|
||||
2) **文字色**:合成后极差 ≤ 40(正文灰 18、语义绿 #52c41a 166)。
|
||||
唯一例外:**选中态胶囊**(`.ant-tag-checkable-checked`)——点亮就是它表达「选了这颗」的方式。
|
||||
用法:
|
||||
NEX_THEMES=light,dark .venv/bin/python scripts/ui/tagcheck.py
|
||||
退出码:0 = 干净,1 = 有立案。
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173")
|
||||
WIDTHS = [int(x) for x in os.environ.get("NEX_WIDTHS", "1440").split(",")]
|
||||
THEMES = os.environ.get("NEX_THEMES", "light,dark").split(",")
|
||||
ROUTES = [r for r in os.environ.get(
|
||||
"NEX_ROUTES",
|
||||
"/,/assets,/models,/projects/{id}/overview,/projects/{id}/library,"
|
||||
"/projects/{id}/storyboard,/projects/{id}/dispatch,/projects/{id}/review,"
|
||||
"/projects/{id}/timeline,/projects/{id}/delivery,/account,/users,/help").split(",") if r]
|
||||
USER = os.environ.get("NEX_USER", "admin")
|
||||
PWD = os.environ.get("NEX_PASS", "admin1234")
|
||||
|
||||
PROJECT_JS = r"""async () => {
|
||||
const t = localStorage.getItem('nex-auth');
|
||||
const tok = t ? (JSON.parse(t)?.state?.token || JSON.parse(t)?.token) : '';
|
||||
const h = {headers: {Authorization: 'Bearer ' + tok}};
|
||||
const j = await (await fetch('/api/projects', h)).json();
|
||||
const list = j.projects || j.items || j.data || (Array.isArray(j) ? j : []);
|
||||
let best = ''; let n = -1;
|
||||
for (const p of list) {
|
||||
const s = await (await fetch(`/api/projects/${p.id}/shots`, h)).json();
|
||||
const c = s.count ?? (s.shots || []).length;
|
||||
if (c > n) { n = c; best = p.id; }
|
||||
}
|
||||
return best || list[0]?.id || '';
|
||||
}"""
|
||||
|
||||
JS = r"""() => {
|
||||
/* 计算值有三种写法都要认:rgb()/rgba()、color(srgb r g b / a)(antd 的 color-mix
|
||||
在 Chrome 里就是这么序列化出来的)、transparent。不认第三种的话暗色档的
|
||||
`color-mix(in srgb, …)` 会解析成 null,整片标签被当成「底色未知」漏检。 */
|
||||
const rgba=(s)=>{
|
||||
s=(s||'').trim();
|
||||
if (!s||s==='transparent') return null;
|
||||
let m=s.match(/^color\(\s*srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+))?\s*\)$/i);
|
||||
if (m) return [+m[1]*255,+m[2]*255,+m[3]*255,m[4]===undefined?1:+m[4]];
|
||||
m=(s.match(/[\d.]+/g)||[]).map(Number);
|
||||
if (m.length<3) return null;
|
||||
return [m[0],m[1],m[2],m.length>3?m[3]:1];
|
||||
};
|
||||
/* 半透明色必须先按真实叠色合成再判饱和度:中性标签底是 rgba(17,26,34,.04),
|
||||
未合成的原色三元组极差就有 17,直接判会把整站中性标签全报成彩色块。 */
|
||||
const over=(c,b)=>{ if(!c) return b; const a=c[3];
|
||||
return [0,1,2].map(i=>Math.round(c[i]*a+b[i]*(1-a))).concat([1]); };
|
||||
const bgOf=(el,base)=>{ let acc=base;
|
||||
for (let cur=el; cur && cur!==document.documentElement; cur=cur.parentElement) {
|
||||
const c=rgba(getComputedStyle(cur).backgroundColor);
|
||||
if (!c || c[3]===0) continue; // 透明层直接跳过:合成它会把上面铺黑
|
||||
acc = over(c, acc);
|
||||
if (c[3]===1) break;
|
||||
}
|
||||
return acc; };
|
||||
const chroma=(c)=>c?Math.round(Math.max(...c.slice(0,3))-Math.min(...c.slice(0,3))):-1; // 中性灰 ≈ 0
|
||||
/* 判「这一层自己有没有加色」:拿标签合成后的底 **减去它所坐表面的合成底**。
|
||||
中性 fill-tertiary 与本站所有表面同族(同一套 antd 中性色板),叠上去三通道
|
||||
等量下降,delta 极差 ≈ 0;语义浅底(#f6ffed 绿 / #e6f4ff 蓝 / 暗色 #162312)
|
||||
delta 极差 ≥ 18。只看合成底会把「标签坐在一块蓝底信息块上」误判成彩色标签。 */
|
||||
const delta=(a,b)=>a&&b?a.map((v,i)=>Math.round(v-b[i])).slice(0,3):null;
|
||||
const cls=(el)=>(typeof el.className==='string'?el.className:'').trim().split(/\s+/).slice(0,4).join('.');
|
||||
const bodyBg=rgba(getComputedStyle(document.body).backgroundColor)||[255,255,255,1];
|
||||
const out=[];
|
||||
for (const el of document.querySelectorAll('main .ant-tag, .ant-tag')) {
|
||||
const r=el.getBoundingClientRect();
|
||||
if (!r.width||!r.height) continue;
|
||||
const cs=getComputedStyle(el);
|
||||
const surf=bgOf(el.parentElement, bodyBg);
|
||||
const bg=over(rgba(cs.backgroundColor), surf), fg=over(rgba(cs.color), bg);
|
||||
const bgc=chroma(delta(bg,surf)), fgc=chroma(fg);
|
||||
const checked=el.classList.contains('ant-tag-checkable-checked'); // 选中态胶囊:点亮是它的职责
|
||||
if (!checked && (bgc>10 || fgc>40)) out.push({el:cls(el).slice(0,60),
|
||||
bg:'rgb('+bg.slice(0,3).join(',')+')',bgRaw:cs.backgroundColor.slice(0,44),bgc,
|
||||
fg:'rgb('+fg.slice(0,3).join(',')+')',fgRaw:cs.color.slice(0,40),fgc,
|
||||
text:(el.innerText||'').trim().replace(/\s+/g,' ').slice(0,20)});
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
|
||||
def main() -> int:
|
||||
bad = []
|
||||
with sync_playwright() as pw:
|
||||
b = pw.chromium.launch()
|
||||
pg = b.new_context(viewport={"width": 1440, "height": 900}).new_page()
|
||||
pg.set_default_timeout(20000)
|
||||
# 登录页没有外壳,登录后再访问会被守卫弹走,所以单独一趟放在登录之前
|
||||
pg.goto(BASE + "/login")
|
||||
pg.wait_for_selector("#login-user")
|
||||
for theme in THEMES:
|
||||
pg.evaluate("(t) => localStorage.setItem('nex-the', t)", theme)
|
||||
pg.goto(BASE + "/login")
|
||||
pg.wait_for_selector("#login-user")
|
||||
pg.wait_for_timeout(600)
|
||||
for row in pg.evaluate(JS):
|
||||
row["where"] = f"/login/{theme}"
|
||||
bad.append(row)
|
||||
pg.fill("#login-user", USER)
|
||||
pg.fill("#login-pass", PWD)
|
||||
pg.click("button[type=submit]")
|
||||
pg.wait_for_url(lambda u: "/login" not in u, timeout=20000)
|
||||
pid = pg.evaluate(PROJECT_JS)
|
||||
for width in WIDTHS:
|
||||
pg.set_viewport_size({"width": width, "height": 900})
|
||||
for theme in THEMES:
|
||||
pg.evaluate("(t) => localStorage.setItem('nex-the', t)", theme)
|
||||
for r in ROUTES:
|
||||
if "{id}" in r and not pid:
|
||||
continue
|
||||
route = r.replace("{id}", str(pid))
|
||||
pg.goto(BASE + route)
|
||||
pg.wait_for_timeout(1200)
|
||||
for row in pg.evaluate(JS):
|
||||
row["where"] = f"{route}@{width}/{theme}"
|
||||
bad.append(row)
|
||||
b.close()
|
||||
|
||||
seen = set()
|
||||
for x in bad:
|
||||
k = (x["el"], x["bg"], x["fg"])
|
||||
if k in seen:
|
||||
continue
|
||||
seen.add(k)
|
||||
print(f"TINT {x['where']:<32} {x['el'][:56]:<56} bg={x['bg']}(chroma {x['bgc']}) "
|
||||
f"fg={x['fg']}(chroma {x['fgc']}) «{x['text']}»")
|
||||
print("TAG_TINTED_TOTAL", len(bad), "unique", len(seen))
|
||||
if bad:
|
||||
print("→ 标签又铺上语义色块了:底色一律走 kit Tag(中性 fill-tertiary + 圆点),"
|
||||
"别在页面上写 antd 的 <Tag color=\"success\">")
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
|
@ -42,7 +42,26 @@ ROUTES = [r for r in os.environ.get(
|
|||
NAV_ROUTES = [r for r in ROUTES
|
||||
if not any(x in r for x in ("/account", "/users", "/help", "/login"))]
|
||||
USER = os.environ.get("NEX_USER", "admin")
|
||||
FORCED_PID = os.environ.get("NEX_PROJECT_ID", "")
|
||||
PWD = os.environ.get("NEX_PASS", "admin1234")
|
||||
# 项目子页一律量「镜头最多」的那个项目:列表第一个往往是刚建的空项目,
|
||||
# 空项目的分镜墙 / 调度清单 / 审核表全是空态,溢出与截断这两类断言等于没测。
|
||||
# 需要指定项目时用 NEX_PROJECT_ID。
|
||||
PROJECT_JS = r"""async () => {
|
||||
const t = localStorage.getItem('nex-auth');
|
||||
const tok = t ? (JSON.parse(t)?.state?.token || JSON.parse(t)?.token) : '';
|
||||
const h = {headers: {Authorization: 'Bearer ' + tok}};
|
||||
const j = await (await fetch('/api/projects', h)).json();
|
||||
const list = j.projects || j.items || j.data || (Array.isArray(j) ? j : []);
|
||||
let best = ''; let n = -1;
|
||||
for (const p of list) {
|
||||
const s = await (await fetch(`/api/projects/${p.id}/shots`, h)).json();
|
||||
const c = s.count ?? (s.shots || []).length;
|
||||
if (c > n) { n = c; best = p.id; }
|
||||
}
|
||||
return best || list[0]?.id || '';
|
||||
}"""
|
||||
|
||||
# rc-resize-observer 在 React 18 下的已知告警,antd 内部依赖,与应用代码无关
|
||||
IGNORE = ("findDOMNode is deprecated", "Support for React will be removed")
|
||||
|
||||
|
|
@ -454,15 +473,9 @@ def main() -> int:
|
|||
if r == "/login":
|
||||
continue # 登录前那一趟量过了,这里再访问只会撞守卫
|
||||
if "{id}" in r:
|
||||
pid = pid or FORCED_PID
|
||||
if not pid:
|
||||
pid = page.evaluate("""async () => {
|
||||
const t = localStorage.getItem('nex-auth');
|
||||
const tok = t ? (JSON.parse(t)?.state?.token || JSON.parse(t)?.token) : '';
|
||||
const r = await fetch('/api/projects', {headers:{Authorization:'Bearer '+tok}});
|
||||
const j = await r.json();
|
||||
const list = j.projects || j.items || j.data || (Array.isArray(j) ? j : []);
|
||||
return list[0]?.id || '';
|
||||
}""")
|
||||
pid = page.evaluate(PROJECT_JS)
|
||||
if not pid:
|
||||
print("!! 拿不到项目 id,跳过", r)
|
||||
continue
|
||||
|
|
|
|||
Loading…
Reference in New Issue