import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { dirname, join } from 'node:path' /** * 弹层层级:Element 弹层 z-index 自 2000 递增,低于本站自定义浮层(常驻警告/代理余量 3000、 * 更新门与铃铛面板 3200、铃铛日期面板 3300)。症状两种、同一根因: * ① 浮层里的日期/下拉面板点开看不到(面板落在浮层背景之下); * ② 浮层里触发的消息/确认框被压住(成本护栏 CostGuardAlert 的「继续任务」反馈)。 * * 这条判据钉的不是某个数字,而是**不变式**:popper 高于全部自定义浮层、低于 ElMessage, * ElMessage 低于消息盒。数字随便调,只要序还在就不会复现。 * 缺 !important 等于整条规则不生效——层级写在 Element 的内联 style 上,必须盖得住。 */ const here = dirname(fileURLToPath(import.meta.url)) const ROOT = join(here, '..') const read = (rel: string) => readFileSync(join(ROOT, rel), 'utf8').replace(/\r\n/g, '\n') const mainCss = read('src/styles/main.css') function zOf(selector: string): number { const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') const matched = mainCss.match(new RegExp(`${escaped}\\s*\\{[^}]*z-index:\\s*(\\d+)\\s*!important`)) assert.ok(matched, `${selector} 需带 !important 的 z-index(不盖内联层级会静默失效)`) return Number(matched[1]) } test('弹层抬升序:popper < ElMessage < 消息盒', () => { const popper = zOf('.el-popper') const message = zOf('.el-message') const messageBox = zOf('.el-overlay.is-message-box') assert.ok(popper < message, `popper(${popper}) 需低于 ElMessage(${message}),否则下拉会挡住提示`) assert.ok(message < messageBox, `ElMessage(${message}) 需低于消息盒(${messageBox}),否则确认框被提示遮住`) }) test('popper 高于本站全部自定义浮层(3000/3200/3300)', () => { const popper = zOf('.el-popper') assert.ok(popper > 3300, `popper(${popper}) 需高于铃铛日期面板等 3300 级浮层,否则浮层里的下拉/日历点开是空的`) }) test('ElMessage 高于本站全部自定义浮层', () => { const message = zOf('.el-message') assert.ok(message > 3300, `ElMessage(${message}) 需高于 3000/3200 级浮层(成本护栏内触发的提示)`) }) test('自定义浮层仍是已知的 3000/3200/3300 档(改了要同步本判据)', () => { const overlays: Array<{ file: string; pattern: RegExp; expected: number }> = [ { file: 'src/shared/components/CostGuardAlert.vue', pattern: /\.cost-guard-stack\s*\{[^}]*z-index:\s*(\d+)/, expected: 3000 }, { file: 'src/shared/components/ProxyBalanceAlert.vue', pattern: /z-index:\s*(\d+)/, expected: 3000 }, { file: 'src/shared/components/notification-bell.css', pattern: /z-index:\s*(\d+)/, expected: 3200 }, { file: 'src/shared/components/notification-bell-popover.css', pattern: /\.bell-date-popper\s*\{[^}]*z-index:\s*(\d+)/, expected: 3300 }, ] for (const { file, pattern, expected } of overlays) { const matched = read(file).match(pattern) assert.ok(matched, `${file} 未找到浮层层级定义`) assert.equal(Number(matched[1]), expected, `${file} 浮层层级变了:新档位需回看 main.css 的 3500/4000/4100 是否仍在其上`) } })