142 lines
8.4 KiB
Python
142 lines
8.4 KiB
Python
# -*- 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`);量到的门牌数掉到地板 → 2(闸门自己坏了,不算通过)。
|
||
用法:NEX_BASE=http://127.0.0.1:5173 python scripts/ui/symmetrycheck.py [light|dark] [宽度]
|
||
|
||
⚠ BASE 早先写死 `localhost:5173`:那台端口被另一个项目占着时,这把尺十三页一个门牌
|
||
都没量到,三个跨页集合全是空集、最大跳动 0,于是「空跑」冒充「一致」照样绿。
|
||
"""
|
||
import os
|
||
import sys
|
||
from playwright.sync_api import sync_playwright
|
||
|
||
BASE = os.environ.get('NEX_BASE', 'http://127.0.0.1:5173')
|
||
MIN_HEADS = int(os.environ.get('NEX_MIN_HEADS', '10')) # 13 页里 12 页该有门牌
|
||
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(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)
|
||
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_HEADS', len(lefts), '/', len(PAGES))
|
||
if len(lefts) < MIN_HEADS:
|
||
print(f'⚠ 只量到 {len(lefts)} 个门牌(底线 {MIN_HEADS})——BASE 指错端口或门牌结构变了,'
|
||
f'不算通过:NEX_BASE={BASE}')
|
||
sys.exit(2)
|
||
print('SYM_TOTAL', bad)
|
||
sys.exit(1 if bad else 0)
|