diff --git a/frontend/src/components/ui/Controls.tsx b/frontend/src/components/ui/Controls.tsx index c8b42ef..bfa6555 100644 --- a/frontend/src/components/ui/Controls.tsx +++ b/frontend/src/components/ui/Controls.tsx @@ -20,13 +20,13 @@ * 高度不写在控件上:紧凑容器只做一件事——`` * 下发 antd 第二档;自绘的那几处读同一个 `--ant-control-height[-sm]`,两条路同一个数。 */ -import type { CSSProperties, MouseEvent, ReactNode } from 'react' +import { cloneElement, isValidElement, useLayoutEffect, useRef, useState, type CSSProperties, type MouseEvent, type ReactElement, type ReactNode } from 'react' import { ConfigProvider, Checkbox as AntCheckbox, Flex, Form, Pagination, Radio as AntRadio, Row, Tag, Typography } from 'antd' import { cn } from '../../lib/cn' import { Button } from './Button' import { Select } from '../forms/Select' import { IconClose } from '../icons' -import { colSpans, toCols, type GridStep } from './grid' +import { colSpans, toCols, FILL_AT, type GridStep } from './grid' /** 分组说明(ChipBar / TagGroup 行首那句「筛选:」):全站只此一种小标签字 */ export const GROUP_LABEL_CLS = 'text-xs text-text-tertiary' @@ -74,7 +74,7 @@ export function Ctlbar({ children, className, as = 'div', cols }: { {cols ? ( - {toCols(children, colSpans(cols, undefined, ROW_STEPS[cols] || []), 'min-w-0')} + {tailRight(toCols(children, colSpans(cols, undefined, ROW_STEPS[cols] || []), 'min-w-0'))} ) : ( @@ -85,6 +85,25 @@ export function Ctlbar({ children, className, as = 'div', cols }: { ) } +/** + * 栅格工具条的最后一格:如果坐的是 (贴右缘的动作组),让它伸缩到行尾。 + * + * 见 grid.tsx 的 FILL_AT:固定 span 的格子只能贴**列**边界,块数除不尽列数时 + * 末尾那格停在半空中(分镜页的「导出」实测落在 75% 处)。整条的右缘要靠格子自己吃掉 + * 剩余宽度。只认 BarRight——末尾是普通字段时它就该老老实实占一格,不该被拉宽。 + */ +function tailRight(cells: ReactNode[]): ReactNode[] { + const last = cells[cells.length - 1] + if (!isValidElement(last)) return cells + const inner = (last.props as { children?: ReactNode }).children + if (!isValidElement(inner) || inner.type !== BarRight) return cells + const props = last.props as { className?: string } + const next = cells.slice() + next[next.length - 1] = cloneElement(last as ReactElement<{ className?: string }>, + { className: cn(props.className, 'nex-ctlbar-tail'), ...FILL_AT }) + return next +} + /** * 同一组的**可枚举选项**(出片预设、画质档位…)=等宽格子,不是 chip 流。 * @@ -138,6 +157,99 @@ export function Actions({ children, className }: { children: ReactNode; classNam return {children} } +/** 组内子项的间距:横排竖排同一个数,和 CardActions / Ctlbar 的 gap 对齐 */ +const AG_GAP = 8 +const px = (v: string) => parseFloat(v) || 0 + +/** + * 「装不下就整组竖排」的自动档:量整组的自然宽度和能给它的最窄祖先,放不下就翻竖排。 + * + * 症状(2026-11 第九轮实测,`scripts/ui/btnrowcheck.py`):分镜导入那三颗 + * 「文本预览 → 导入预演(含图片匹配)→ 正式导入」在 1024 折成 2+1 + * (tops 1108/1108/1140)、860 折成三行;时间线 1024 档「补齐缺失配音」 + * 单独掉第二排。`Flex wrap` 折的是**组内子项**,读者看到的是 + * 「这一排怎么少了一颗」,而它们明明是同一条流程的三步。 + * 做法:两条尺子,页面都不用自己判断—— + * ① 横排时把盒子钉在 `max-content`(只在父级会折行时钉:栅格格子 min-w-0 里 + * 钉会把列宽捅破),父容器于是把整组当**一个** item,放不下整组挪下一行; + * ② 整组连一整行都放不下(窄卡、窄栏、430 手机档)时整组改竖排等宽, + * 和页面手写的 `stack` 同一个视觉,不再是参差的 2 + 1。 + * 自然宽度只有横排时可测(竖排后子项被拉伸到等宽),所以量一次缓存, + * 容器重新宽过缓存值就自动恢复横排。 + * 用法:`ActionGroup` 内部用,页面不用管。第 17 轮之前只有 `PageHead` 传过 + * `auto={false}`(它自带一套「整组满宽 + 按钮等分」),可那套等分恰恰把 + * `natural()` 的量法喂死了(子项 flex-grow>0 就返回 0),于是页头照旧折成 + * 2 + 1;页头改回自动档之后站内再没有容器要关它,这个开关连着删了—— + * 窄屏怎么排只该有一个答案,多留一条路就是多一处会烂掉的豁免。 + * 为什么把结果做成 state 而不是直接写 `el.style`:className 由 React 拥有, + * 竖排↔横排切换时 React 会重写 className,命令式加上去的类会被抹掉, + * 之后没有 resize 就再也补不回来——症状是「窄屏看久了又长出孤儿按钮」。 + */ +function useAutoStack() { + const host = useRef(null) + const mode = useRef(false) // 当前是否竖排:effect 里读它,避免闭包读到旧 state + const need = useRef(0) // 横排需要的自然宽度(只在横排时量得到) + const [vertical, setVertical] = useState(false) + const [atom, setAtom] = useState(false) + + useLayoutEffect(() => { + const el = host.current + if (!el) return + const parents: HTMLElement[] = [] + for (let n = el.parentElement; n && n !== document.documentElement; n = n.parentElement) parents.push(n) + /* 能容下整组的最窄祖先内容宽(从父级一层层往里收;display:contents 的 Dense 不算一层) */ + const room = () => { + let least = Infinity + for (const n of parents) { + const cs = getComputedStyle(n) + if (cs.display === 'contents') continue + const w = n.clientWidth - px(cs.paddingLeft) - px(cs.paddingRight) + if (w > 0) least = Math.min(least, w) + } + return least + } + /* 整组横排的自然宽:子项都按内容定尺才可测,含弹性控件或没渲染完就返回 0(不判断) */ + const natural = () => { + const kids = Array.from(el.children) as HTMLElement[] + const widths = kids.map((k) => k.getBoundingClientRect().width) + if (!kids.length || widths.some((w) => w <= 0)) return 0 + if (kids.some((k) => px(getComputedStyle(k).flexGrow) > 0)) return 0 + return widths.reduce((sum, w) => sum + w, 0) + AG_GAP * (kids.length - 1) + } + /* 只在布局父级会折行时钉 max-content:这样「挪行」由父容器做,整组一起挪。 + `Dense` 挂的是 display:contents,它在 DOM 上是一层、在布局上不是, + 直接从 parents[0] 读会把 Ctlbar / CardActions 看成 contents 而漏掉整组钉宽。 */ + const styles = parents.map((n) => getComputedStyle(n)) + let li = 0 + while (styles[li] && styles[li].display === 'contents') li += 1 + const atomic = !!styles[li] && styles[li].display === 'flex' && styles[li].flexWrap === 'wrap' + + let raf = 0 + const measure = () => { + raf = 0 + if (!mode.current) { const n = natural(); if (n > 0) need.current = n } + const want = need.current > 0 && need.current > room() + 0.5 + setAtom(atomic && !want) + if (want === mode.current) return + mode.current = want + setVertical(want) + } + const schedule = () => { if (!raf) raf = requestAnimationFrame(measure) } + + const ro = new ResizeObserver(schedule) + ;[el, ...parents.slice(0, 3)].forEach((n) => ro.observe(n)) + window.addEventListener('resize', schedule) + measure() + return () => { + ro.disconnect() + window.removeEventListener('resize', schedule) + if (raf) cancelAnimationFrame(raf) + } + }, []) + + return { host, vertical, atom } +} + /** * 同一概念的一组动作 / 勾选项:整组对外是**一个** flex item,要换行就整组一起换行。 * @@ -146,22 +258,21 @@ export function Actions({ children, className }: { children: ReactNode; classNam * 在 378px 的侧栏卡里折成 2 + 1、素材墙一张卡底下 6 颗生成按钮 + 「删除」 * 折成 6 + 1、分镜导入流程「文本预览 → 导入预演 → 正式导入」在 768 折成三行。 * 读者看到的是「这一排怎么少了一颗」,而不是「这三条是一组」。 - * 做法:外层容器按**整组的 max-content**决定这一组落在哪一行,所以要么整组在 - * 这一行,要么整组挪到下一行,不会出现「一排里少一颗」。组内 `gap:marginXS`; - * 只有当整组连一行都放不下(容器比组还窄)时组内才自己折, - * 那种容器(右侧窄栏里的长标题按钮)改用 `stack`:竖排等宽, - * 一眼是「这一组」,也不会在第二行留一颗孤儿。 + * 做法:见 `useAutoStack`——横排钉 max-content(整组一起挪行)、 + * 一整行都放不下时整组竖排等宽。组内 `gap:marginXS`。 * 用法:`……`; * 档位由外层容器下发,这里不再包一层 `Dense`。 */ export function ActionGroup({ children, className, stack }: { children: ReactNode; className?: string - /** 竖排等宽:容器窄到放不下横排时用(窄侧栏卡片里的多颗长标题按钮) */ + /** 竖排等宽:容器明确窄到放不下横排时直接写死(窄侧栏卡片里的多颗长标题按钮) */ stack?: boolean }) { - return stack - ? {children} - : {children} + const { host, vertical, atom } = useAutoStack() + return stack || vertical + ? {children} + : {children} } /** 需要右靠的一组控件(替代写在控件上的 margin-left:auto) */ @@ -245,11 +356,17 @@ export function FieldBlock({ label, required, children, className, style, title, } /** - * 表单作用域:只落下 `.nex-form` 这个标记类。 + * 表单作用域:只落下 `.nex-form` 这个标记类(app.css 表单 glue ①=控件撑满列宽)。 * * 旧版本在这里定义 12 等分轨道和 `--label-w`(「标题与控件对齐」的唯一机制)。 * 标签改到控件上方之后,对齐由 antd 表单栅格负责,这两套私有尺子整体退场—— * 列边界从此只有 Row/Col 一个来源(见 grid.tsx),不会再出现两行字段错开 110px。 + * + * **`` 自己就带这一层**(见下面的 FormRow):一行字段本来就是表单, + * 作用域不该靠调用点记得再包一层。这一改之前站内有 6 处 FormRow 漏包, + * 症状都一样:同一格里下拉铺满、数字框按 antd 的默认 90px 缩成一截, + * 右边界参差不齐(时间线「混音与字幕设置」实测 214 的格子摆 90 的输入框)。 + * 还要用它的场合只剩一个:抽屉里**竖排**的 FieldBlock 串(不排成栅格的那堆字段)。 */ export function FormGrid({ children, className }: { children: ReactNode; className?: string }) { return
{children}
@@ -286,7 +403,8 @@ export function FormRow({ children, cols = 3, className, tight, gap = 16 }: { gap?: number }) { return ( - + {toCols(children, colSpans(cols, undefined, ROW_STEPS[cols] || []), 'min-w-0')} ) diff --git a/frontend/src/components/ui/Page.tsx b/frontend/src/components/ui/Page.tsx index 305058f..effc9d5 100644 --- a/frontend/src/components/ui/Page.tsx +++ b/frontend/src/components/ui/Page.tsx @@ -18,8 +18,7 @@ * 这里把 antd 的那对引进来叫 AntRow/AntCol,铺列由本文件的 Layout 负责。 */ import { type CSSProperties, type ReactNode } from 'react' -import { useLocation, useNavigate } from 'react-router-dom' -import { navItemAt } from '../../app/layout/nav' +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 { ActionGroup } from './Controls' @@ -114,9 +113,18 @@ export function CodeBlock({ children, className }: { children: ReactNode; classN ) } -/** 窄屏时把动作条撑满一行,让两三颗按钮不会挤成一团中文碎渣 */ +/** 窄屏时把只读补充条撑满一行,让两三枚胶囊不会挤成一团中文碎渣 */ 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 已并进这里)。 * @@ -126,23 +134,28 @@ const WRAP_ACTIONS = 'max-lg:w-full max-lg:[&>button]:flex-1' * 眉标和标题讲的是同一件事(这一站叫什么),站次在侧栏高亮项、顶栏流程条、 * 项目概况抽屉里又各说了一遍(R18:每一级的信息只在该级说一遍); * ② 眉标那枚图标孤零零在第一行左端,离标题隔了一整行,对不上「这图形=菜单里那项」; + * 第十四轮(用户原话「不要图标」+ 门牌截图):反查菜单图形那一层整层删掉—— + * 标题左侧带底色的方块的语义是「图标 = 这一站」,但它和左栏高亮项说的是同一句话, + * 门牌里再摆一次就是给同一信息配第二个视觉锚点(R18),而且这块主色方块 + * 紧接着下面卡头的品牌 N、统计卡的色块,一屏三颗同形状的方块互相抢注意力。 * ③ 右端动作挂在**整块页头**的垂直中线上,七站的说明有长有短、有的两行有的一行, * 主按钮在每一页的 y 都不一样,概览页没有动作时那条中线还是空的。 * 做法:页头只留两层,第一行横向排满—— - * 第一行 = 菜单同款图标 + 一级标题 +(右端)整页成立的主操作; + * 第一行 = 一级标题 +(右端)整页成立的主操作; * 第二行 = 一句话职责说明(以及 meta 那种只读补充),横跨整行。 - * 图标不在页面里 import:由路由反查 `app/layout/nav.tsx` 那张菜单表(navItemAt), - * 菜单换图形当天页头跟着换,两边物理上不可能长得不一样。 * 第一行高度钉在 controlHeight,主操作与它垂直居中、右缘贴卡内边距—— * 七站的「新建 / 入队 / 批量放行 / 开始导出」因此必然落在同一条水平线上。 + * 标题左缘 = 卡内边距 = 下面每一张卡正文的左缘:门牌与正文同一条竖线对齐, + * 这件事在没有图标之前做不到(图标方块把标题整体右推 42px)。 * 为什么仍然是一张卡(2026-11 第十一轮的口径不变):页头与正文卡之间只有 16px 空白时, * 它读起来像「正文上面漏了半句话」;主色底纹 + 主色描边让它是全站唯一带主色 * 描边的卡,一眼就是「这一层的门牌」,主次不靠字号硬撑。 * 分工(UI规范 §2):PageHead 只放**整页成立**的动作(新建、入队、批量放行、开始导出); * PanelHead 只放**离开这一块就不成立**的动作;Tabs 右端不放按钮。 - * 窄屏:标题行与动作组各自满宽(WRAP_ACTIONS 让按钮等分),说明仍在最下面一行。 + * 窄屏:标题行与动作组各自满宽;整组横排连一整行都放不下时由 `ActionGroup` + * 翻成**竖排等宽**(换行的是整组,不是组里少一颗),说明仍在最下面一行。 */ -export function PageHead({ title, sub, meta, actions, icon, className }: { +export function PageHead({ title, sub, meta, actions, className }: { title?: ReactNode /** 标题下方的一句话职责说明(12px 次要色,最宽 72ch) */ sub?: ReactNode @@ -150,23 +163,18 @@ export function PageHead({ title, sub, meta, actions, icon, className }: { meta?: ReactNode /** 右端主操作:与标题同排、整体右对齐;窄屏整组满宽、按钮等分 */ actions?: ReactNode - /** 覆盖反查结果的图标(账号 / 用户管理 / 手册这种不在菜单里的页);传 null 明确不放图标 */ - icon?: ReactNode className?: string }) { - const location = useLocation() - /* 菜单表反查:`icon` 没写就用这一页在侧栏里的那枚图形 */ - const mark = icon === undefined ? (navItemAt(location.pathname)?.icon ?? null) : icon return ( + {/* 标题行里没有图形(第十四轮「不要图标」):只留一级标题,左缘就是卡内边距 */} - {mark ? {mark} : null} {title} - {/* auto={false}:页头的窄屏方案是「整组满宽 + 按钮等分」(WRAP_ACTIONS), - 不需要 ActionGroup 再把它翻成竖排一列 */} - {actions && {actions}} + {/* 自动档开着(第 17 轮):满宽那一行仍放不下整组时,ActionGroup 把这几颗 + 主操作翻成竖排等宽,读者看到的始终是「一整组」,不是 2 + 1 */} + {actions && {actions}} {/* 说明行 w-full:它必然掉到第二行,主操作因此永远和标题同一排 */} {(meta || sub) && ( diff --git a/frontend/src/components/ui/grid.tsx b/frontend/src/components/ui/grid.tsx index 1e13f5f..421fcc9 100644 --- a/frontend/src/components/ui/grid.tsx +++ b/frontend/src/components/ui/grid.tsx @@ -53,6 +53,21 @@ export function colSpans(cols: number, oneAt?: GridCollapse, steps?: GridStep[]) return out } +/** + * 吃掉所在行剩余宽度的档位。 + * + * 症状(2026-11 第七轮目视,分镜页筛选条):`Ctlbar cols={4}` 里 7 个块, + * 第二行只剩 3 个,末尾那格 ``(导出)坐在第 3 格里靠 `ml-auto` + * 贴到**格子的**右缘——停在整条的 75% 处,看着像掉在中间的一颗按钮。 + * 「贴右缘」这件事在自然排列里是 margin-left:auto,在栅格里必须是**格子本身 + * 伸缩到行尾**,否则右缘就是列边界,不是容器边界。 + * 做法:这一族格子不给 span,给 `flex: 1 1 auto`——同一行前面的格子都是固定百分比, + * 剩下的宽度全归它;折到窄档列数变了也一样成立(不需要按断点算剩几格)。 + * 用法见 Controls.Ctlbar:只有末尾那格是 BarRight 时才替换成这一档。 + */ +const FILL: ColAt = { flex: '1 1 auto' } +export const FILL_AT: Record = { xs: FILL, sm: FILL, md: FILL, lg: FILL, xl: FILL, xxl: FILL } + /** 把 N 个子节点铺进一行栅格(Grid / StatGrid / FormRow / Layout / Stack 共用) */ export function toCols(children: ReactNode, spans: Record, colClass?: string): ReactNode[] { /* Fragment 必须先摊平:`{cond && <>字段A 字段B}` 在 Children.toArray 里只是**一个**孩子, diff --git a/frontend/src/pages/Account.tsx b/frontend/src/pages/Account.tsx index 3e81425..83ea120 100644 --- a/frontend/src/pages/Account.tsx +++ b/frontend/src/pages/Account.tsx @@ -97,9 +97,8 @@ export default function Account() { return ( - {/* 这一页不在侧栏菜单里(从右上角头像进入),PageHead 反查不到菜单图形,自己补一枚 */} - } - actions={{role}} /> + {/* 门牌只有标题 + 右端只读身份标签:第十四轮起页头不再放任何前置图形 */} + {role}} /> {mustChange && 这个账号还在使用初始密码,请先修改密码再开始制作。} setNotice('')}>{notice} diff --git a/frontend/src/pages/Help.tsx b/frontend/src/pages/Help.tsx index 9306ec1..aecbce8 100644 --- a/frontend/src/pages/Help.tsx +++ b/frontend/src/pages/Help.tsx @@ -20,7 +20,7 @@ import { Block, Chip, ChipBar, Code, CodeBlock, Divider, ExtLink, Grid, Heading, LinkButton, Notice, PageHead, Panel, Paragraph, Table, Tag, TagGroup, Value, type Columns, cellWrap } from '../components/ui' -import { IconApi, IconBolt, IconBook, IconDashboard, IconImage, IconPlayCircle, IconVoice } from '../components/icons' +import { IconApi, IconBolt, IconDashboard, IconImage, IconPlayCircle, IconVoice } from '../components/icons' /** 正文皮肤:只在手册根上贴一次(行内加粗、链接里的代码色),段落不再各带一套 */ const SHELL = 'min-w-0 [&_b]:font-semibold [&_b]:text-text [&_a_code]:text-primary' /** 章节:锚点要躲开常驻顶栏(kit 的 HEADER_HEIGHT=56),滚动定位留两档余量 */ @@ -194,10 +194,9 @@ export default function Help() { 原先是一整块 primary 底纹的封面卡:整页只有它是彩色的,读者以为那是个提示条; 四张能力标签改成页头眉标,封面卡的底纹与描边一起删掉(§1 一屏最多一个语义底块, 本页后面还有 Notice 在用底纹,封面没有资格再占一次)。 */} - {/* 手册也不在侧栏菜单里:图形自己给(IconBook),门牌卡的样子与其它页一致 */} + {/* 门牌卡的样子与其它页一致:只有标题、说明、右端主操作,没有前置图形 */} } sub="从模型配置、资产管理、脚本导入,到分镜生成、自动质检、人工审核与长视频合成, 本手册按实际业务流程说明每个页面的用途与关键操作。所有截图均来自正在运行的系统。" meta={ 四类模型统一管理 diff --git a/frontend/src/pages/project/AgentConsole.tsx b/frontend/src/pages/project/AgentConsole.tsx index d3c12ae..28b59a2 100644 --- a/frontend/src/pages/project/AgentConsole.tsx +++ b/frontend/src/pages/project/AgentConsole.tsx @@ -21,7 +21,7 @@ import { notify } from '../../stores/notice' import { useProjectStore } from '../../stores/project' import { loadModels } from '../../stores/models' import { Select } from '../../components/forms' -import { Between, Block, Button, Check, Chip, ChipBar, DisclosureRow, Empty, Field, FieldBlock, FormGrid, FormRow, Heading, Layout, LinkButton, LiveDot, Mark, MUTED, Mono, Notice, Panel, Paragraph, Row, Tag, TextArea, TILE_HINT, Value } from '../../components/ui' +import { Between, Block, Button, Check, Chip, ChipBar, DisclosureRow, Empty, Field, FieldBlock, FormGrid, FormRow, Heading, Layout, LinkButton, LiveDot, MUTED, Mono, Notice, Panel, Paragraph, Row, Tag, TextArea, TILE_HINT, Value } from '../../components/ui' import { IconAudit, IconCheck, IconChevronRight, IconClose, IconNodeIndex, IconPlay, IconRetry, IconRobot, IconStoryboard } from '../../components/icons' /** 计划里的一步(白名单动作),status: pending/running/succeeded/skipped/failed */ type AgentStep = { @@ -541,12 +541,9 @@ export default function AgentConsole() { * 浅色主题里它把正文压成灰底(截图 1 就是浅色档),而 Card 的两套主题都是 antd 调好的。 */ - N - - 项目总控台 - - } + title={ + 项目总控台 + } extra={ {latest ? {latest.provider}/{latest.model} diff --git a/scripts/ui/aligncheck.py b/scripts/ui/aligncheck.py new file mode 100644 index 0000000..16dec65 --- /dev/null +++ b/scripts/ui/aligncheck.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +同一行必须同心:全站横排容器里落在**同一条视觉行**上的子件,中线 y 必须一致(≤1px)。 + +症状(2026-11 第十四轮 · 用户原话「垂直居中对齐,和其它子页面要一致。请检查。」+ + 调度中心工具条截图):卡头标题槽外面套的是一个**行内 span**,里面坐的却是 + `TagGroup`/`Flex` 这种块级 div——块级装在行内里会先撑出一段匿名行盒, + 于是那一排 25px 的只读胶囊整体浮到卡头中线上方 6.5px(同页其它单行卡头偏 0.5px)。 + 肉眼看到的就是「这排标签贴顶、下面空一截」,而它和别的子页面同类的行对不上。 +做法:把「同一行同心」写成一把可执行的尺,逐容器按 y 中心把可见子件**分组成视觉行**, + 每一行内所有子件的中线必须与该行中心相差 ≤1px;同时记录该行最高子件与 + 字体(字号/字重),用来抓「继承到标题档 600 字重」这一类隐性病。 + 覆盖:卡头(.ant-card-head-wrapper)、内容页门牌(.nex-pagehead 的第一行)、 + 控件栏(.nex-ctlbar)、卡内横排(.ant-card-body 里那些 align-items:center 的 Flex)。 +为什么只比中心不比高度:R3 允许同行出现 22/24/32 三档(标签 + 输入框 + 按钮), + 它们的**中心**必须一致,顶边一致反而错。 +为什么不查跨行:折行是 flex-wrap 的正常结果(R1),所以先按 y 分桶再逐桶判定。 +用法:.venv/bin/python -u scripts/ui/aligncheck.py [theme] [width];dev server 需在 :5173。 +退出码:有任何一处偏位 >1px 或卡头标题继承到 600 字重 → 1。 +""" +import sys +from playwright.sync_api import sync_playwright + +THEME = sys.argv[1] if len(sys.argv) > 1 else 'light' +WIDTH = int(sys.argv[2]) if len(sys.argv) > 2 else 1440 +TOL = 1.0 # 同一行允许的中线偏差(px):亚像素舍入留 1px +PAGES = [('总览', '/'), ('资产库', '/assets'), ('模型中心', '/models'), + ('①概览', '/projects/10/overview'), ('②资产', '/projects/10/library'), + ('③分镜', '/projects/10/storyboard'), ('④调度', '/projects/10/dispatch'), + ('⑤质检', '/projects/10/review'), ('⑥时间线', '/projects/10/timeline'), + ('⑦导出', '/projects/10/delivery'), ('账号', '/account'), ('手册', '/help'), + ('用户管理', '/users')] + +# 逐个容器把「直接可见子件」按中线 y 分桶(同一视觉行),桶内比中心。 +# 两条尺: +# ① 兄弟尺——同一容器里落在**同一条视觉行**上的子件,中线必须一致(按 y 分桶后逐桶比); +# ② 父子尺——单行容器的几何中心必须等于它**内容**的中心。 +# 抓的是「容器被一段下边距撑高、内容贴顶」这一类:调度中心那条工具条整排 +# 浮在卡头中线上方 6px,兄弟之间全都对得上,① 看不见它,只有 ② 抓得住。 +JS = """() => { + const SEL = ['.ant-card-head-wrapper', '.nex-pagehead .ant-card-body > .ant-flex', + '.nex-ctlbar', '.nex-taggroup', '.ant-tabs-nav-wrap']; + const PARENT = ['.ant-card-head-title', '.nex-pagehead-title', '.ant-card-extra', '.nex-ctlbar']; + const vis = (e) => { const r = e.getBoundingClientRect(); const s = getComputedStyle(e); + return r.width >= 1 && r.height >= 1 && s.visibility !== 'hidden' && s.display !== 'none'; }; + const box = (e) => { const r = e.getBoundingClientRect(), s = getComputedStyle(e); + return { y: r.y + r.height / 2, h: r.height, fs: s.fontSize, fw: s.fontWeight, + tag: (e.className && e.className.toString ? e.className.toString() : e.tagName).trim().split(/\\s+/)[0].slice(0, 30) }; }; + const rows = []; + const seen = new Set(); + // ── ② 父子尺:整页跑一遍(每个容器只看一次) + document.querySelectorAll(PARENT.join(',')).forEach((c) => { + if (!vis(c)) return; + const kids = [...c.querySelectorAll('*')].filter((k) => vis(k) && !k.querySelector(':scope > *')); + if (!kids.length) return; + const cb = box(c), ys = kids.map((k) => box(k)); + if (Math.max(...ys.map((b) => b.y)) - Math.min(...ys.map((b) => b.y)) > 8) return; // 多行不比 + const content = ys.reduce((t, b) => t + b.y, 0) / ys.length; + const d = Math.abs(cb.y - content); + const key = cb.tag + '@' + Math.round(cb.y); + if (d > __TOL__ && !seen.has(key)) { seen.add(key); rows.push({ host: '父·' + cb.tag.slice(0, 22), + worst: +d.toFixed(1), dev: '容器中心' + cb.y.toFixed(1) + ' vs 内容中心' + content.toFixed(1), bold: '' }); } + }); + document.querySelectorAll(SEL.join(',')).forEach((c) => { + if (!vis(c)) return; + const kids = [...c.querySelectorAll(':scope > *')].filter(vis); + if (kids.length < 2) return; + const items = kids.map((k) => box(k)); + const lines = []; + items.forEach((it) => { + const ln = lines.find((l) => Math.abs(l.c - it.y) < Math.max(6, Math.min(l.h, it.h) / 2)); + if (ln) { ln.p.push(it); ln.c = ln.p.reduce((s, p) => s + p.y, 0) / ln.p.length; + ln.h = Math.max(ln.h, it.h); } + else lines.push({ c: it.y, h: it.h, p: [it] }); + }); + lines.forEach((ln) => { if (ln.p.length < 2) return; + const worst = Math.max(...ln.p.map((p) => Math.abs(p.y - ln.c))); + const boldTag = ln.p.filter((p) => /^(ant-tag|nex-tag|nex-chip|ant-segmented)/.test(p.tag) && +p.fw >= 500) + .map((p) => p.tag + ' ' + p.fs + '/' + p.fw); + if (worst > __TOL__ || boldTag.length) + rows.push({ host: c.className.toString().slice(0, 40), worst: +worst.toFixed(1), + dev: ln.p.map((p) => p.tag + '@' + (p.y - ln.c).toFixed(1)).slice(0, 4).join(' '), + bold: [...new Set(boldTag)].join(' ') }); + }); + }); + return rows; +}""".replace("__TOL__", str(TOL)) + +bad = 0 +with sync_playwright() as pw: + b = pw.chromium.launch() + pg = b.new_page(viewport={'width': WIDTH, 'height': 1000}) + pg.goto('http://localhost:5173/login', wait_until='networkidle') + if pg.locator('#login-user').count(): + pg.fill('#login-user', 'admin'); pg.fill('#login-pass', 'admin1234') + pg.click('button[type=submit]'); pg.wait_for_timeout(1200) + pg.evaluate('t => localStorage.setItem("nex-the", t)', THEME) + for name, route in PAGES: + pg.goto('http://localhost:5173' + route, wait_until='networkidle') + pg.wait_for_timeout(2200) + rows = pg.evaluate(JS) + for r in rows: + bad += 1 + print('!! %-6s %-26s 同行偏位 %-5s %s %s' % (name, r['host'][:26], r['worst'], r['dev'], + ('字重:' + r['bold']) if r['bold'] else '')) + b.close() +print('%s:全站 %d 处同一行不同心 / 只读胶囊继承到标题字重' % ('未通过' if bad else '通过', bad)) +sys.exit(1 if bad else 0) diff --git a/scripts/ui/symmetrycheck.py b/scripts/ui/symmetrycheck.py new file mode 100644 index 0000000..88a2d65 --- /dev/null +++ b/scripts/ui/symmetrycheck.py @@ -0,0 +1,130 @@ +# -*- coding: utf-8 -*- +"""跨页页头一致性尺(第 10 道像素闸,2026-11 第十四轮)。 + +症状(用户原话「垂直居中对齐,和其它子页面要一致。请检查」): + aligncheck(§15.8)量的是**同一个容器内部**同一行的中线,它看不见的是 + 「每一页各自都对了,但页与页之间不一样」——七站的门牌标题行有的 32px 有的 40px、 + 主按钮在 A 页贴标题、在 B 页挂到整块页头的中线上,逐页看都不算错, + 连着切页就是晃。这一把尺量的是**跨页**:把 13 个页面同一个量的实测值收齐, + 要求每个量收敛到一个值(集合大小 == 1)。 + +量四件事(都在 1440 视口、明暗各跑一遍): + ① 门牌第一行:一级标题的中线 == `.nex-action-group` 的中线(Δ > 1px 点名); + ② 门牌标题行高 >= `--ant-control-height`(定高那一行是「七站主按钮同高」的几何前提); + ③ 标题里不许再有图形(svg / nex-*-mark / ant-avatar 一律点名,R20); + ④ 卡头:`.ant-card-head-title` 与 `.ant-card-extra` 同心;正文卡左缘 == 门牌标题左缘 + (门牌与正文同一条竖线,R20 删掉图标方块之后才成立)。 +最后打印三个跨页集合:门牌标题左缘 / 标题行中线 / 主操作右缘,每个都必须是单值。 + +退出码:任一点名 → 1(`SYM_TOTAL`)。 +用法:python scripts/ui/symmetrycheck.py [light|dark] [宽度] +""" +import sys +from playwright.sync_api import sync_playwright + +THEME = sys.argv[1] if len(sys.argv) > 1 else 'light' +WIDTH = int(sys.argv[2]) if len(sys.argv) > 2 else 1440 +PAGES = [('总览', '/'), ('资产库', '/assets'), ('模型中心', '/models'), + ('①概览', '/projects/10/overview'), ('②资产', '/projects/10/library'), + ('③分镜', '/projects/10/storyboard'), ('④调度', '/projects/10/dispatch'), + ('⑤质检', '/projects/10/review'), ('⑥时间线', '/projects/10/timeline'), + ('⑦导出', '/projects/10/delivery'), ('账号', '/account'), ('手册', '/help'), + ('用户管理', '/users')] + +JS = """() => { + const box = (e) => { const r = e.getBoundingClientRect(); return {l:r.left, r:r.right, t:r.top, b:r.bottom, w:r.width, h:r.height, cy:r.top + r.height/2}; }; + const vis = (e) => { const r = e.getBoundingClientRect(); const s = getComputedStyle(e); + return r.width > 1 && r.height > 1 && s.visibility !== 'hidden' && s.display !== 'none' && s.opacity !== '0'; }; + const out = {ch: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--ant-control-height'))}; + const ph = document.querySelector('.nex-pagehead'); + if (ph) { + const row = ph.querySelector('.ant-card-body > .ant-flex'); + const title = ph.querySelector('.nex-pagehead-title'); + if (row) out.row = box(row); + if (title) { out.title = box(title); out.titleText = title.innerText.trim().slice(0, 12); + out.glyph = [...title.children].filter(c => vis(c) && c.tagName !== 'SPAN' ? false : false).length; + // 标题行里除了文字还有没有别的可见图形(svg / 带底色方块) + out.marks = [...title.querySelectorAll('svg, .nex-stat-mark, .nex-toast-mark, .nex-brief-mark, .ant-avatar')] + .filter(vis).map(e => e.tagName + '.' + (e.getAttribute('class') || '').split(' ')[0]); } + // 动作组 = PageHead 第一行的直接子件 .nex-action-group(ActionGroup 唯一类名)。 + // 门牌里任何**不在第一行**的动作组(掉进说明那一行 / 挂在整块中线上)也要抓出来点名: + // 它就是「主按钮每页 y 都不一样」那个老破法的形状,只查直接子件会把它当成「本页没动作」放过。 + const ex = row ? [...row.querySelectorAll(':scope > .nex-action-group')].filter(vis) : []; + out.actions = ex.map(c => ({n: c.querySelectorAll('button, .ant-select').length, b: box(c), first: 'row'})); + const all = ph ? [...ph.querySelectorAll('.nex-action-group')].filter(vis) : []; + out.stray = all.filter((c) => !ex.includes(c) && !c.querySelector('.nex-action-group') + && !(ex.some((e) => e.contains(c)))).map((c) => ({ + n: c.querySelectorAll('button, .ant-select').length, b: box(c), first: 'stray'})); + } + // 正文第一张卡的正文左缘 + 每一张卡头的标题/extra 中线 + const cards = [...document.querySelectorAll('.ant-card')].filter(vis).slice(0, 6); + out.cards = cards.map((c) => { + const body = c.querySelector(':scope > .ant-card-body'); + const head = c.querySelector(':scope > .ant-card-head-wrapper'); + const o = {body: body ? box(body) : null}; + if (head) { const t = head.querySelector('.ant-card-head-title'), e = head.querySelector('.ant-card-extra'); + o.head = box(head); o.t = t && vis(t) ? box(t) : null; o.e = e && vis(e) ? box(e) : null; + o.ht = t ? t.innerText.trim().slice(0, 10) : ''; } + return o; + }); + return out; +}""" + +rows = [] +with sync_playwright() as pw: + b = pw.chromium.launch() + pg = b.new_page(viewport={'width': WIDTH, 'height': 1000}) + pg.goto('http://localhost:5173/login', wait_until='networkidle') + if pg.locator('#login-user').count(): + pg.fill('#login-user', 'admin'); pg.fill('#login-pass', 'admin1234') + pg.click('button[type=submit]'); pg.wait_for_timeout(1200) + pg.evaluate('t => localStorage.setItem("nex-the", t)', THEME) + for name, route in PAGES: + pg.goto('http://localhost:5173' + route, wait_until='networkidle') + pg.wait_for_timeout(2200) + rows.append((name, route, pg.evaluate(JS))) + b.close() + +bad = 0 +ctl = {d['ch'] for _, _, d in rows if d.get('ch')} +print('control-height tokens:', ctl) +titles, lefts, acts = [], [], [] +for name, route, d in rows: + ph, ti = d.get('row'), d.get('title') + line = [] + if not ti: + print(f'{name:6s} 无门牌'); continue + marks = d.get('marks') or [] + if marks: + line.append(f'标题里有图形 {marks}'); bad += 1 + if ph and abs(ti['l'] - ph['l']) > 1: + line.append(f"标题左缘比行首偏 {ti['l']-ph['l']:.1f}") + if ti['h'] < (d.get('ch') or 0) - 1: + line.append(f"标题行高 {ti['h']:.0f} < controlHeight {d.get('ch'):.0f}") + a = [x for x in (d.get('actions') or []) if x['b']['w'] > 20] + if a: + ac = a[-1]['b'] + line.append(f"标题行中线 {ti['cy']:.1f} 动作中线 {ac['cy']:.1f} Δ{ti['cy']-ac['cy']:+.1f} 右缘距卡内边 {ph['r']-ac['r']:.1f}") + if abs(ti['cy'] - ac['cy']) > 1: line.append('⚠不同心'); bad += 1 + acts.append(round(ac['r'], 1)); titles.append(round(ti['cy'], 1)) + elif d.get('stray'): + st = d['stray'][-1]['b'] + line.append(f"⚠主操作不在标题那一行(中线 {st['cy']:.1f} vs 标题 {ti['cy']:.1f})"); bad += 1 + else: + line.append('门牌无主操作') + lefts.append(round(ti['l'], 1)) + ch = [c for c in d.get('cards', []) if c.get('head')] + for c in ch[:2]: + if c.get('t') and c.get('e'): + dt = c['t']['cy'] - c['e']['cy'] + if abs(dt) > 1: + line.append(f"⚠卡头「{c['ht']}」标题/extra Δ{dt:+.1f}"); bad += 1 + if c.get('body') and abs(c['body']['l'] - ti['l']) > 1: + line.append(f"⚠门牌左缘与正文卡左缘差 {c['body']['l']-ti['l']:+.1f}"); bad += 1 + print(f'{name:6s} ' + ' | '.join(line)) +print('门牌左缘集合:', sorted(set(lefts)), ' 门牌中线集合:', sorted(set(titles)), ' 动作右缘集合:', sorted(set(acts))) +print('跨页最大跳动:', '标题中线', (max(titles)-min(titles)) if titles else 0, + '标题左缘', (max(lefts)-min(lefts)) if lefts else 0, + '动作右缘', (max(acts)-min(acts)) if acts else 0) +print('SYM_TOTAL', bad) +sys.exit(1 if bad else 0)