#!/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 分桶再逐桶判定。 用法:NEX_BASE=http://127.0.0.1:5173 .venv/bin/python -u scripts/ui/aligncheck.py [theme] [width]。 退出码:有任何一处偏位 >1px 或卡头标题继承到 600 字重 → 1; 量到的容器数掉到地板(< MIN_PROBED)→ 2,闸门自己坏了,不算通过。 ⚠ 2026-11-06 踩过:BASE 早先写死 `localhost:5173`,那台端口上跑的是**另一个项目**, 十三页全都「没有对齐容器」,这把于是空跑成 0 处偏位还照样绿。凡是「0 = 通过」的尺 都必须自报样本数——和 footercheck 的 FOOTER_PROBED 同一个道理。 """ import os import sys from playwright.sync_api import sync_playwright BASE = os.environ.get("NEX_BASE", "http://127.0.0.1:5173") MIN_PROBED = int(os.environ.get("NEX_MIN_PROBED", "40")) 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(); let seen2 = 0; // 量到的容器数(判据能不能算数,全看这个) // ── ② 父子尺:整页跑一遍(每个容器只看一次) document.querySelectorAll(PARENT.join(',')).forEach((c) => { if (!vis(c)) return; seen2 += 1; 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; seen2 += 1; 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, probed: seen2 }; }""".replace("__TOL__", str(TOL)) bad = 0 probed = 0 with sync_playwright() as pw: b = pw.chromium.launch() pg = b.new_page(viewport={'width': WIDTH, 'height': 1000}) pg.goto(BASE + '/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(BASE + route, wait_until='networkidle') pg.wait_for_timeout(2200) got = pg.evaluate(JS) probed += got.get('probed', 0) rows = got.get('rows', []) 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('ALIGN_PROBED', probed) if probed < MIN_PROBED: print(f'⚠ 只量到 {probed} 个容器(底线 {MIN_PROBED})——BASE 指错端口或选择器漂了,' f'不算通过:NEX_BASE={BASE}') sys.exit(2) print('%s:全站 %d 处同一行不同心 / 只读胶囊继承到标题字重' % ('未通过' if bad else '通过', bad)) sys.exit(1 if bad else 0)