fix: 操作审计页移动端适配(窄屏筛选 2 列/隐藏题头/数据行堆叠)
桌面布局的 9 列筛选行在窄屏下每列仅剩数十像素(标签逐字换行、 输入框压扁),固定列宽列表合计约 61rem 必然横向溢出被截断。 ≤1023px(手机横竖屏/平板竖屏/半屏小窗口)改为: - 筛选栏 2 列、操作按钮独占整行;≤480px 手机竖屏单列 - 隐藏固定列宽列题头,entity 行纵向堆叠(覆盖组件内联 width) - 截断类字段放宽到 100%,分页条允许换行 ≥1024px 维持桌面布局不变。 新增 AuditLogList.mobile.spec.ts 结构性回归测试(8 项)。
This commit is contained in:
@@ -0,0 +1,110 @@
|
|||||||
|
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/)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -575,4 +575,70 @@ onMounted(fetchLogs)
|
|||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
border-top: 1px solid #eaecf0;
|
border-top: 1px solid #eaecf0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===== 移动端适配(窄屏:手机 / 竖屏平板 / 半屏小窗口) =====
|
||||||
|
桌面布局的 9 列筛选行在窄屏下每列仅剩数十像素(标签逐字换行、
|
||||||
|
输入框被压扁),列表固定列宽合计约 61rem 必然横向溢出被截断。
|
||||||
|
窄屏改为:筛选 2 列(更窄单列)、隐藏列题头、数据行字段纵向堆叠。
|
||||||
|
断点取 1023px:覆盖手机横竖屏与平板竖屏;≥1024px 维持桌面布局不变。
|
||||||
|
媒体查询置于文件末尾,同特异性规则按顺序覆盖桌面样式。 */
|
||||||
|
@media (max-width: 1023px) {
|
||||||
|
.audit-body {
|
||||||
|
padding: 0.75rem 0.75rem 1.5rem;
|
||||||
|
}
|
||||||
|
.filter-grid {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
.filter-actions {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
}
|
||||||
|
.filter-actions > :deep(*) {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
/* 固定列宽的题头在纵向堆叠布局下无从对齐,隐藏 */
|
||||||
|
.audit-header {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
/* entity 行由「表格行 + 固定列宽字段」改为纵向堆叠的块:
|
||||||
|
tr/td 改块级、字段换行排列;组件通过内联 style 写死字段宽度,
|
||||||
|
样式表须用 !important 才能覆盖内联样式 */
|
||||||
|
.audit-row {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.audit-row :deep(.entity-start-wrapper),
|
||||||
|
.audit-row :deep(.entity-end-wrapper) {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.audit-row :deep(.entity-end-wrapper) {
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
.audit-row :deep(.entity-start) {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.audit-row :deep(.entity-end) {
|
||||||
|
justify-content: flex-start;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
.audit-row :deep(.entity-field-wrapper) {
|
||||||
|
width: auto !important;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
.row-sub,
|
||||||
|
.action-desc {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
/* 分页条(总数 + 翻页/条数控制器)窄屏下换行铺开,不横向溢出 */
|
||||||
|
.audit-pagination :deep(.pagination),
|
||||||
|
.audit-pagination :deep(.pagination__controller) {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
/* 手机竖屏:单列筛选,datetime-local 等宽控件不再被压扁 */
|
||||||
|
.filter-grid {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user