Compare commits
2
Commits
9e89ed75ed
...
34764c7641
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34764c7641 | ||
|
|
87ae0c79bb |
@@ -0,0 +1,128 @@
|
|||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
// 移动端适配结构性回归测试:不渲染组件,仅检查 SFC 源码。
|
||||||
|
// 固定列宽列表合计约 69.5rem,窄屏(≤1023px:手机横竖屏 / 平板竖屏 / 半屏小窗口)
|
||||||
|
// 下必然超出视口:题头与数据行置于同一横向滚动容器(.audit-list)整体左右滑动,
|
||||||
|
// 列对齐关系与桌面一致;筛选栏窄屏 2 列(≤480px 手机竖屏单列)、分页条允许换行;
|
||||||
|
// ≥1024px 维持桌面布局不变。
|
||||||
|
// 特别注意:VEntity 是多根 Fragment 组件(tr + 可选 footer tr),其 <tr> 拿不到
|
||||||
|
// 本组件的 scoped 作用域 ID,所有锚定 .audit-row / 行内元素 :deep 的 scoped 规则
|
||||||
|
// 永远失配(历史上「隐藏题头 + 数据行纵向堆叠」方案因此整批失效——窄屏下字段
|
||||||
|
// 仍按固定列宽横排并被视口截断),行内样式必须锚定自身元素 .audit-list 穿透,
|
||||||
|
// 本测试防止该失效方案被重新引入。
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 取全局(非媒体查询)样式中某选择器的规则体。 */
|
||||||
|
function styleRule(selector: string): string {
|
||||||
|
const start = sfc.indexOf(`${selector} {`)
|
||||||
|
expect(start, `缺少 ${selector} 样式规则`).toBeGreaterThan(-1)
|
||||||
|
const end = sfc.indexOf('}', start)
|
||||||
|
return sfc.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('题头与数据行置于同一横向滚动容器(.audit-list overflow-x: auto)', () => {
|
||||||
|
// 模板顺序:.audit-list 包裹 .audit-header 与全部 VEntity 数据行,
|
||||||
|
// 滑动时题头与数据列保持对齐
|
||||||
|
const listStart = sfc.indexOf('<div class="audit-list">')
|
||||||
|
expect(listStart, '缺少 .audit-list 滚动容器').toBeGreaterThan(-1)
|
||||||
|
const headerStart = sfc.indexOf('<div class="audit-header">')
|
||||||
|
const entityStart = sfc.indexOf('<VEntity')
|
||||||
|
const listEnd = sfc.indexOf('</div>\n </template>', listStart)
|
||||||
|
expect(headerStart).toBeGreaterThan(listStart)
|
||||||
|
expect(entityStart).toBeGreaterThan(headerStart)
|
||||||
|
expect(listEnd).toBeGreaterThan(entityStart)
|
||||||
|
const rule = styleRule('.audit-list')
|
||||||
|
expect(rule).toMatch(/overflow-x:\s*auto/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('窄屏不隐藏列题头(题头随容器滑动,列对齐关系不变)', () => {
|
||||||
|
// 历史方案曾在窄屏 display: none 隐藏题头,导致用户失去列语义,防止回归
|
||||||
|
const headerRule = styleRule('.audit-header')
|
||||||
|
expect(headerRule).not.toMatch(/display:\s*none/)
|
||||||
|
expect(mobileBlock()).not.toContain('.audit-header')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('题头在滚动容器内随内容延伸且列宽不收缩(滑动后下划线不断裂、不与数据列错位)', () => {
|
||||||
|
const header = styleRule('.audit-header')
|
||||||
|
expect(header).toMatch(/min-width:\s*max-content/)
|
||||||
|
const col = styleRule('.header-col')
|
||||||
|
expect(col).toMatch(/flex-shrink:\s*0/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('数据行保持固定列宽表格形态,无失效的行内堆叠样式', () => {
|
||||||
|
// VEntity 的 <tr> 拿不到本组件 scoped 作用域 ID,锚定 .audit-row 的规则永远失配;
|
||||||
|
// 窄屏块内不得出现任何 entity 行内 :deep 规则,全文件不得再有 .audit-row 选择器
|
||||||
|
// (选择器须位于行首或上一规则之后,注释中的历史说明不受限)
|
||||||
|
expect(mobileBlock()).not.toContain('entity-')
|
||||||
|
expect(sfc).not.toMatch(/(?:^|[},;])\s*\.audit-row[\s:{]/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('行悬停手型经自身元素 .audit-list 穿透到 VEntity 行', () => {
|
||||||
|
const rule = styleRule('.audit-list :deep(.entity-wrapper)')
|
||||||
|
expect(rule).toMatch(/cursor:\s*pointer/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('窄屏分页条允许换行(总数与翻页控制器不横向溢出)', () => {
|
||||||
|
const rule = ruleIn(
|
||||||
|
mobileBlock(),
|
||||||
|
'.audit-pagination :deep(.pagination),\n .audit-pagination :deep(.pagination__controller)',
|
||||||
|
)
|
||||||
|
expect(rule).toMatch(/flex-wrap:\s*wrap/)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -322,80 +322,86 @@ onMounted(fetchLogs)
|
|||||||
</template>
|
</template>
|
||||||
</VEmpty>
|
</VEmpty>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<!-- 列题头:分组结构与内边距镜像 entity 行的两个 td,列宽与各 VEntityField 的 width 一一对应 -->
|
<!-- 题头与数据行置于同一横向滚动容器:固定列宽合计约 69.5rem,
|
||||||
<div class="audit-header">
|
容器窄于列表(手机/竖屏平板/半屏窗口)时整体左右滑动看全六列,
|
||||||
<div class="header-start">
|
列对齐关系与桌面完全一致;容器够宽时无溢出、无滚动条,桌面观感不变。
|
||||||
<span class="header-col col-username">操作者 / 时间</span>
|
:deep 规则须锚定此容器(本组件自己的元素)才能穿透到 VEntity 行内,
|
||||||
<span class="header-col col-method">动作</span>
|
VEntity 是多根 Fragment 组件,其 <tr> 拿不到本组件的 scoped 作用域 ID -->
|
||||||
<span class="header-col col-resource">资源 / 路径</span>
|
<div class="audit-list">
|
||||||
<span class="header-col col-desc">描述</span>
|
<!-- 列题头:分组结构与内边距镜像 entity 行的两个 td,列宽与各 VEntityField 的 width 一一对应 -->
|
||||||
</div>
|
<div class="audit-header">
|
||||||
<div class="header-end">
|
<div class="header-start">
|
||||||
<span class="header-col col-status">结果</span>
|
<span class="header-col col-username">操作者 / 时间</span>
|
||||||
<span class="header-col col-ip">IP</span>
|
<span class="header-col col-method">动作</span>
|
||||||
|
<span class="header-col col-resource">资源 / 路径</span>
|
||||||
|
<span class="header-col col-desc">描述</span>
|
||||||
|
</div>
|
||||||
|
<div class="header-end">
|
||||||
|
<span class="header-col col-status">结果</span>
|
||||||
|
<span class="header-col col-ip">IP</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<VEntity
|
||||||
|
v-for="log in logs"
|
||||||
|
:key="log.metadata.name"
|
||||||
|
@click="openDetail(log)"
|
||||||
|
>
|
||||||
|
<template #start>
|
||||||
|
<VEntityField :title="displayUsername(log.spec.username)" width="12rem">
|
||||||
|
<template #description>
|
||||||
|
<span class="row-sub">{{ formatTime(log.metadata.creationTimestamp) }}</span>
|
||||||
|
</template>
|
||||||
|
</VEntityField>
|
||||||
|
<!-- 动作列:彩色徽标标注请求方法 -->
|
||||||
|
<VEntityField width="6rem">
|
||||||
|
<template #title>
|
||||||
|
<span class="method-badge" :class="methodBadgeClass(log.spec.method)">
|
||||||
|
{{ log.spec.method }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</VEntityField>
|
||||||
|
<VEntityField width="20rem">
|
||||||
|
<template #title>
|
||||||
|
<span class="resource-text">
|
||||||
|
{{ log.spec.resourceType }}
|
||||||
|
<template v-if="log.spec.resourceName">/ {{ log.spec.resourceName }}</template>
|
||||||
|
</span>
|
||||||
|
<!-- 行内快捷动作(功能评审 P1-1):查看该资源的历史操作;
|
||||||
|
stop 冒泡避免触发行点击的详情抽屉 -->
|
||||||
|
<a
|
||||||
|
v-if="log.spec.resourceName"
|
||||||
|
class="resource-history-link"
|
||||||
|
title="查看该资源的历史操作"
|
||||||
|
@click.stop="viewResourceHistory(log)"
|
||||||
|
>历史</a>
|
||||||
|
</template>
|
||||||
|
<template #description>
|
||||||
|
<span class="row-sub">{{ log.spec.path }}</span>
|
||||||
|
</template>
|
||||||
|
</VEntityField>
|
||||||
|
<!-- 描述列:该操作实际语义的中文描述(如 登录/新建用户/发布文章) -->
|
||||||
|
<VEntityField width="10rem">
|
||||||
|
<template #title>
|
||||||
|
<span class="action-desc">{{ describeOperation(log.spec) }}</span>
|
||||||
|
</template>
|
||||||
|
</VEntityField>
|
||||||
|
</template>
|
||||||
|
<template #end>
|
||||||
|
<!-- 结果列:登录失败记录(HTTP 200/302 也可能是失败,语义动作已标注)
|
||||||
|
显示红色「失败」,避免绿色 200/302 误读为登录成功;
|
||||||
|
徽标经 #title 插槽渲染(当前版本组件在无 title 时不渲染 #extra,
|
||||||
|
原先徽标实际不可见) -->
|
||||||
|
<VEntityField width="4rem">
|
||||||
|
<template #title>
|
||||||
|
<span class="status-badge" :class="resultBadge(log.spec).class">
|
||||||
|
{{ resultBadge(log.spec).text }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</VEntityField>
|
||||||
|
<VEntityField :title="log.spec.remoteIp" width="9rem" />
|
||||||
|
</template>
|
||||||
|
</VEntity>
|
||||||
</div>
|
</div>
|
||||||
<VEntity
|
|
||||||
v-for="log in logs"
|
|
||||||
:key="log.metadata.name"
|
|
||||||
class="audit-row"
|
|
||||||
@click="openDetail(log)"
|
|
||||||
>
|
|
||||||
<template #start>
|
|
||||||
<VEntityField :title="displayUsername(log.spec.username)" width="12rem">
|
|
||||||
<template #description>
|
|
||||||
<span class="row-sub">{{ formatTime(log.metadata.creationTimestamp) }}</span>
|
|
||||||
</template>
|
|
||||||
</VEntityField>
|
|
||||||
<!-- 动作列:彩色徽标标注请求方法 -->
|
|
||||||
<VEntityField width="6rem">
|
|
||||||
<template #title>
|
|
||||||
<span class="method-badge" :class="methodBadgeClass(log.spec.method)">
|
|
||||||
{{ log.spec.method }}
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</VEntityField>
|
|
||||||
<VEntityField width="20rem">
|
|
||||||
<template #title>
|
|
||||||
<span class="resource-text">
|
|
||||||
{{ log.spec.resourceType }}
|
|
||||||
<template v-if="log.spec.resourceName">/ {{ log.spec.resourceName }}</template>
|
|
||||||
</span>
|
|
||||||
<!-- 行内快捷动作(功能评审 P1-1):查看该资源的历史操作;
|
|
||||||
stop 冒泡避免触发行点击的详情抽屉 -->
|
|
||||||
<a
|
|
||||||
v-if="log.spec.resourceName"
|
|
||||||
class="resource-history-link"
|
|
||||||
title="查看该资源的历史操作"
|
|
||||||
@click.stop="viewResourceHistory(log)"
|
|
||||||
>历史</a>
|
|
||||||
</template>
|
|
||||||
<template #description>
|
|
||||||
<span class="row-sub">{{ log.spec.path }}</span>
|
|
||||||
</template>
|
|
||||||
</VEntityField>
|
|
||||||
<!-- 描述列:该操作实际语义的中文描述(如 登录/新建用户/发布文章) -->
|
|
||||||
<VEntityField width="10rem">
|
|
||||||
<template #title>
|
|
||||||
<span class="action-desc">{{ describeOperation(log.spec) }}</span>
|
|
||||||
</template>
|
|
||||||
</VEntityField>
|
|
||||||
</template>
|
|
||||||
<template #end>
|
|
||||||
<!-- 结果列:登录失败记录(HTTP 200/302 也可能是失败,语义动作已标注)
|
|
||||||
显示红色「失败」,避免绿色 200/302 误读为登录成功;
|
|
||||||
徽标经 #title 插槽渲染(当前版本组件在无 title 时不渲染 #extra,
|
|
||||||
原先徽标实际不可见) -->
|
|
||||||
<VEntityField width="4rem">
|
|
||||||
<template #title>
|
|
||||||
<span class="status-badge" :class="resultBadge(log.spec).class">
|
|
||||||
{{ resultBadge(log.spec).text }}
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</VEntityField>
|
|
||||||
<VEntityField :title="log.spec.remoteIp" width="9rem" />
|
|
||||||
</template>
|
|
||||||
</VEntity>
|
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<!-- 分页条置于卡片内部末尾:白底铺满整行,与上方列表左右对齐 -->
|
<!-- 分页条置于卡片内部末尾:白底铺满整行,与上方列表左右对齐 -->
|
||||||
@@ -475,6 +481,14 @@ onMounted(fetchLogs)
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
/* 题头与数据行共用横向滚动容器(同官方 EntityList 的 w-full overflow-x-auto):
|
||||||
|
固定列宽合计约 69.5rem,容器更窄(手机/竖屏平板/半屏窗口)时整体左右滑动;
|
||||||
|
容器够宽时不产生滚动条,桌面观感不变。
|
||||||
|
VEntity 行内样式一律经此自身元素 :deep 穿透:VEntity 是多根 Fragment 组件,
|
||||||
|
其 <tr> 拿不到本组件的 scoped 作用域 ID,锚定 .audit-row 的规则永远失配。 */
|
||||||
|
.audit-list {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
/* 列题头:VEntity 数据行由两个 td(entity-start-wrapper / entity-end-wrapper)组成,
|
/* 列题头:VEntity 数据行由两个 td(entity-start-wrapper / entity-end-wrapper)组成,
|
||||||
每个 td 自带 1rem 左右内边距,end 组紧跟 start 组之后(行宽由内容收缩,不铺满)。
|
每个 td 自带 1rem 左右内边距,end 组紧跟 start 组之后(行宽由内容收缩,不铺满)。
|
||||||
题头按同样结构分两组、各组自带 1rem 内边距,才能与数据列一一对齐;
|
题头按同样结构分两组、各组自带 1rem 内边距,才能与数据列一一对齐;
|
||||||
@@ -482,6 +496,9 @@ onMounted(fetchLogs)
|
|||||||
.audit-header {
|
.audit-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
/* 滚动容器内题头盒随内容延伸(否则下划线止于可视宽度,滑动后断裂);
|
||||||
|
容器更宽时仍为 100%,与桌面一致 */
|
||||||
|
min-width: max-content;
|
||||||
padding: 0.5rem 0;
|
padding: 0.5rem 0;
|
||||||
border-bottom: 1px solid #eaecf0;
|
border-bottom: 1px solid #eaecf0;
|
||||||
}
|
}
|
||||||
@@ -499,6 +516,8 @@ onMounted(fetchLogs)
|
|||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
color: #666;
|
color: #666;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
/* 列宽不参与 flex 收缩:窄屏下题头盒宽由内容决定,避免被压缩与数据列错位 */
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
.col-username { width: 12rem; }
|
.col-username { width: 12rem; }
|
||||||
.col-method { width: 6rem; }
|
.col-method { width: 6rem; }
|
||||||
@@ -511,7 +530,9 @@ onMounted(fetchLogs)
|
|||||||
/* 错误提示位于白卡上方,与卡片留出间距 */
|
/* 错误提示位于白卡上方,与卡片留出间距 */
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
.audit-row {
|
/* 行悬停手型:VEntity 多根组件的 tr 无法携带本组件 scoped 作用域 ID,
|
||||||
|
规则须锚定自身元素 .audit-list 再 :deep 穿透到行 */
|
||||||
|
.audit-list :deep(.entity-wrapper) {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.row-sub {
|
.row-sub {
|
||||||
@@ -575,4 +596,41 @@ onMounted(fetchLogs)
|
|||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
border-top: 1px solid #eaecf0;
|
border-top: 1px solid #eaecf0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ===== 移动端适配(窄屏:手机 / 竖屏平板 / 半屏小窗口) =====
|
||||||
|
桌面布局的 9 列筛选行在窄屏下每列仅剩数十像素(标签逐字换行、
|
||||||
|
输入框被压扁),窄屏改为筛选 2 列(≤480px 手机竖屏单列)。
|
||||||
|
列表保持题头 + 固定列宽的表格形态,由 .audit-list 整体左右滑动看全六列,
|
||||||
|
列对齐与桌面一致。数据行纵向堆叠方案不可行:VEntity 是多根 Fragment
|
||||||
|
组件,其 <tr> 拿不到本组件的 scoped 作用域 ID,所有锚定 .audit-row 的
|
||||||
|
行内 :deep 规则均失配(历史方案因此整批失效),且堆叠后题头无从对齐。
|
||||||
|
≥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-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