Files
halo-ops-audit/plugin-operation-audit/ui/src/views/AuditLogList.mobile.spec.ts
T
836061373 87ae0c79bb fix: 操作审计页移动端适配(窄屏筛选 2 列/隐藏题头/数据行堆叠)
桌面布局的 9 列筛选行在窄屏下每列仅剩数十像素(标签逐字换行、
输入框压扁),固定列宽列表合计约 61rem 必然横向溢出被截断。

≤1023px(手机横竖屏/平板竖屏/半屏小窗口)改为:
- 筛选栏 2 列、操作按钮独占整行;≤480px 手机竖屏单列
- 隐藏固定列宽列题头,entity 行纵向堆叠(覆盖组件内联 width)
- 截断类字段放宽到 100%,分页条允许换行
≥1024px 维持桌面布局不变。

新增 AuditLogList.mobile.spec.ts 结构性回归测试(8 项)。
2026-11-22 15:59:52 +08:00

111 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
// 移动端适配结构性回归测试:不渲染组件,仅检查 SFC 源码中的窄屏样式。
// 桌面布局的 9 列筛选行与固定列宽列表(约 61rem)在窄屏下必然溢出:
// 筛选标签逐字换行、输入框被压扁,数据行右侧被截断(需横向滚动才能看全)。
// 窄屏(≤1023px:手机横竖屏 / 平板竖屏 / 半屏小窗口)改为——
// 筛选 2 列(≤480px 单列)、隐藏列题头、entity 行纵向堆叠、分页条换行;
// ≥1024px 维持桌面布局不变。本测试防止移动端适配被误删或失效。
const sfc = readFileSync(fileURLToPath(new URL('./AuditLogList.vue', import.meta.url)), 'utf-8')
const MOBILE_QUERY = '@media (max-width: 1023px)'
/** 提取 max-width: 1023px 媒体查询块全文(大括号配平)。 */
function mobileBlock(): string {
const start = sfc.indexOf(MOBILE_QUERY)
expect(start, `缺少 ${MOBILE_QUERY} 媒体查询`).toBeGreaterThan(-1)
let depth = 0
let end = -1
for (let i = sfc.indexOf('{', start); i < sfc.length; i++) {
if (sfc[i] === '{') depth++
else if (sfc[i] === '}') {
depth--
if (depth === 0) {
end = i
break
}
}
}
return sfc.slice(start, end)
}
/** 在指定文本块内取某选择器的规则体(自 from 起首个匹配)。 */
function ruleIn(block: string, selector: string, from = 0): string {
const start = block.indexOf(`${selector} {`, from)
expect(start, `窄屏块中缺少 ${selector} 规则`).toBeGreaterThan(-1)
const end = block.indexOf('}', start)
return block.slice(start, end)
}
describe('AuditLogList 移动端适配', () => {
it('存在 ≤1023px 窄屏断点,且位于桌面规则之后(同特异性按顺序覆盖才生效)', () => {
const mediaStart = sfc.indexOf(MOBILE_QUERY)
const desktopGrid = sfc.indexOf('.filter-grid {')
expect(desktopGrid).toBeGreaterThan(-1)
expect(mediaStart).toBeGreaterThan(desktopGrid)
})
it('窄屏筛选栏改为 2 列,操作按钮独占整行并拉伸铺满', () => {
const grid = ruleIn(mobileBlock(), '.filter-grid')
expect(grid).toMatch(/grid-template-columns:\s*repeat\(2,\s*minmax\(0,\s*1fr\)\)/)
const actions = ruleIn(mobileBlock(), '.filter-actions')
expect(actions).toMatch(/grid-column:\s*1\s*\/\s*-1/)
const stretch = ruleIn(mobileBlock(), '.filter-actions > :deep(*)')
expect(stretch).toMatch(/flex:\s*1/)
})
it('手机竖屏(≤480px)筛选栏单列,datetime-local 不被压扁', () => {
const start = sfc.indexOf('@media (max-width: 480px)')
expect(start, '缺少 ≤480px 单列断点').toBeGreaterThan(-1)
expect(sfc.slice(start)).toMatch(
/grid-template-columns:\s*minmax\(0,\s*1fr\)/,
)
})
it('窄屏隐藏固定列宽列题头(堆叠布局下无从对齐)', () => {
const header = ruleIn(mobileBlock(), '.audit-header')
expect(header).toMatch(/display:\s*none/)
})
it('窄屏 entity 行纵向堆叠:tr/td 改块级、end 组不额外留顶部内边距', () => {
const block = mobileBlock()
expect(block).toMatch(/\.audit-row \{\s+display:\s*block;?\s+\}/)
const combined = ruleIn(
block,
'.audit-row :deep(.entity-start-wrapper),\n .audit-row :deep(.entity-end-wrapper)',
)
expect(combined).toMatch(/display:\s*block/)
// 独立的 end-wrapper 规则位于合并规则之后(合并规则同样以该选择器开头,须跳过)
const afterCombined = block.indexOf(combined) + combined.length
expect(ruleIn(block, '.audit-row :deep(.entity-end-wrapper)', afterCombined)).toMatch(
/padding-top:\s*0/,
)
expect(ruleIn(block, '.audit-row :deep(.entity-start)')).toMatch(/flex-wrap:\s*wrap/)
const end = ruleIn(block, '.audit-row :deep(.entity-end)')
expect(end).toMatch(/justify-content:\s*flex-start/)
expect(end).toMatch(/gap:\s*1rem/)
})
it('窄屏字段宽度覆盖组件内联 style(width: auto !important)且不超出行宽', () => {
// VEntityField 把 width prop 写成内联 style,仅 !important 样式表规则能覆盖
const wrapper = ruleIn(mobileBlock(), '.audit-row :deep(.entity-field-wrapper)')
expect(wrapper).toMatch(/width:\s*auto\s*!important/)
expect(wrapper).toMatch(/max-width:\s*100%/)
})
it('窄屏截断类字段放宽到 100%(路径/描述不再被 22rem/9.75rem 限宽截断)', () => {
const rule = ruleIn(mobileBlock(), '.row-sub,\n .action-desc')
expect(rule).toMatch(/max-width:\s*100%/)
})
it('窄屏分页条允许换行(总数与翻页控制器不横向溢出)', () => {
const rule = ruleIn(
mobileBlock(),
'.audit-pagination :deep(.pagination),\n .audit-pagination :deep(.pagination__controller)',
)
expect(rule).toMatch(/flex-wrap:\s*wrap/)
})
})