Compare commits
6
Commits
bf7573034a
...
7280ccb5f3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7280ccb5f3 | ||
|
|
cdbea79ba6 | ||
|
|
8cc66a5693 | ||
|
|
c2e38d7c44 | ||
|
|
68f362cb42 | ||
|
|
f4be39d065 |
@@ -0,0 +1,92 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
// 结构性回归测试:不渲染组件,仅检查 SFC 源码中的页面布局样式。
|
||||
// 操作审计页需保持控制台默认灰底(.audit-page 不自行设置背景色),
|
||||
// 筛选栏、数据列表、分页条合并为同一张白色卡片:区块之间不留灰缝,
|
||||
// 分页条白底随卡片铺满整行、与上方列表左右对齐(与控制台其他列表页观感一致);
|
||||
// 数据行上方有列题头,题头列宽与数据行各字段固定宽度一一对应;
|
||||
// flex: 1 撑满 main-content 剩余高度,使灰底延伸到页面底部。
|
||||
// 历史上 .audit-page 曾整体铺白导致页面与其他页面观感不一致,
|
||||
// 分页条曾左右各留 1rem 导致白底与上方卡片错位,
|
||||
// 卡片之间曾留 1rem 间距导致白色断开,本测试防止回归。
|
||||
const sfc = readFileSync(fileURLToPath(new URL('./AuditLogList.vue', import.meta.url)), 'utf-8')
|
||||
|
||||
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('.audit-page 撑满控制台内容区剩余高度且不铺白(保持默认灰底)', () => {
|
||||
const rule = styleRule('.audit-page')
|
||||
expect(rule).toMatch(/flex:\s*1/)
|
||||
expect(rule).not.toMatch(/background\s*:/)
|
||||
})
|
||||
|
||||
it('.audit-body 不设区块间距(筛选/数据/分页之间白色连成一体)', () => {
|
||||
const rule = styleRule('.audit-body')
|
||||
expect(rule).not.toMatch(/gap\s*:/)
|
||||
})
|
||||
|
||||
it('筛选栏与数据列表合并为同一张 VCard', () => {
|
||||
expect(sfc.match(/<VCard/g)?.length).toBe(1)
|
||||
})
|
||||
|
||||
it('.audit-filter .filter-grid 筛选字段与操作按钮排成一行(7 列 + auto 按钮)', () => {
|
||||
const rule = styleRule('.filter-grid')
|
||||
expect(rule).toMatch(/grid-template-columns:\s*repeat\(7,\s*minmax\(0,\s*1fr\)\)\s+auto/)
|
||||
})
|
||||
|
||||
it('.audit-pagination 白底铺满整行(不再左右缩进 1rem),仅以 1px 分隔线与列表相接', () => {
|
||||
const rule = styleRule('.audit-pagination')
|
||||
expect(rule).not.toMatch(/padding:\s*0\s+1rem/)
|
||||
expect(rule).toMatch(/padding:\s*1rem/)
|
||||
expect(rule).toMatch(/border-top:\s*1px\s+solid\s+#eaecf0/)
|
||||
})
|
||||
|
||||
it('列表数据行上方渲染列题头,五个列标签齐全', () => {
|
||||
expect(sfc).toContain('<div class="audit-header">')
|
||||
expect(sfc).toContain('操作者 / 时间')
|
||||
expect(sfc).toContain('>动作<')
|
||||
expect(sfc).toContain('资源 / 路径')
|
||||
expect(sfc).toContain('>结果<')
|
||||
expect(sfc).toContain('>IP<')
|
||||
})
|
||||
|
||||
it('题头列宽与数据行 VEntityField 的 width 一一对应', () => {
|
||||
const pairs: Array<[string, string]> = [
|
||||
['col-username', '12rem'],
|
||||
['col-method', '6rem'],
|
||||
['col-resource', '20rem'],
|
||||
['col-status', '4rem'],
|
||||
['col-ip', '9rem'],
|
||||
]
|
||||
for (const [cls, width] of pairs) {
|
||||
expect(sfc, `缺少题头列 ${cls}`).toMatch(new RegExp(`\\.${cls} \\{ width: ${width};? \\}`))
|
||||
expect(sfc, `缺少数据列 width="${width}"`).toContain(`width="${width}"`)
|
||||
}
|
||||
})
|
||||
|
||||
it('题头分组间距与 entity 行一致(start 间距 1rem、end 间距 1.5rem 且右对齐)', () => {
|
||||
const start = styleRule('.header-start')
|
||||
expect(start).toMatch(/gap:\s*1rem/)
|
||||
const end = styleRule('.header-end')
|
||||
expect(end).toMatch(/gap:\s*1\.5rem/)
|
||||
expect(end).toMatch(/margin-left:\s*auto/)
|
||||
const header = styleRule('.audit-header')
|
||||
expect(header).toMatch(/padding:\s*0\.5rem\s+1rem/)
|
||||
expect(header).toMatch(/border-bottom:\s*1px\s+solid\s+#eaecf0/)
|
||||
})
|
||||
|
||||
it('动作列仅保留彩色徽标、结果列徽标经 #title 渲染', () => {
|
||||
// 组件(@halo-dev/components 2.26.0)在无 title/#title 时不渲染 #extra,
|
||||
// 原先结果徽标实际不可见;原先方法列 title 与徽标重复渲染同一文案。
|
||||
expect(sfc).not.toContain(':title="log.spec.method"')
|
||||
expect(sfc).toMatch(/<template #title>\s+<span\s+class="method-badge"/)
|
||||
expect(sfc).toMatch(/<template #title>\s+<span\s+class="status-badge"/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
// 结构性回归测试:不渲染组件,仅检查 SFC 源码中 VPagination 的绑定形态。
|
||||
// Halo @halo-dev/components 的 VPagination 默认文案即 Halo 控制台风格:
|
||||
// totalLabel = `共 ${total} 项数据`、pageLabel = `页`、sizeLabel = `条 / 页`。
|
||||
// 历史上这里覆盖为「页码 / 每页条数 / 共 N 条」,导致分页行与控制台其他页面不一致,
|
||||
// 本测试防止该覆盖回归。
|
||||
const sfc = readFileSync(fileURLToPath(new URL('./AuditLogList.vue', import.meta.url)), 'utf-8')
|
||||
|
||||
describe('AuditLogList 分页文案', () => {
|
||||
it('使用 VPagination 默认文案(不覆盖 pageLabel / sizeLabel / totalLabel)', () => {
|
||||
expect(sfc).toContain('<VPagination')
|
||||
expect(sfc).not.toMatch(/page-label|pageLabel/)
|
||||
expect(sfc).not.toMatch(/size-label|sizeLabel/)
|
||||
expect(sfc).not.toMatch(/total-label|totalLabel/)
|
||||
})
|
||||
|
||||
it('不再出现旧文案(页码 / 每页条数 / 共 N 条)', () => {
|
||||
expect(sfc).not.toContain('页码')
|
||||
expect(sfc).not.toContain('每页条数')
|
||||
expect(sfc).not.toMatch(/共 \$\{total\} 条/)
|
||||
})
|
||||
|
||||
it('分页控件仍在 total > 0 时渲染,且保留每页条数选项', () => {
|
||||
expect(sfc).toMatch(/v-if="total > 0" class="audit-pagination"/)
|
||||
expect(sfc).toMatch(/:size-options="\[10, 20, 50\]"/)
|
||||
})
|
||||
})
|
||||
@@ -163,8 +163,13 @@ onMounted(fetchLogs)
|
||||
</VPageHeader>
|
||||
|
||||
<div class="audit-body">
|
||||
<VAlert v-if="error" class="audit-error" type="error" :closable="true" :title="error" />
|
||||
|
||||
<!-- 筛选栏、数据列表、分页条合并为一张白卡:区块之间不再露出灰缝,
|
||||
分页条白底随卡片铺满整行、与上方列表左右对齐(文字位置保持不变) -->
|
||||
<VCard :body-class="['!p-0']">
|
||||
<!-- 筛选栏(只读查询,无任何修改/删除入口) -->
|
||||
<VCard :body-class="['audit-filter']">
|
||||
<div class="audit-filter">
|
||||
<div class="filter-grid">
|
||||
<label class="filter-item">
|
||||
<span>操作者</span>
|
||||
@@ -221,11 +226,8 @@ onMounted(fetchLogs)
|
||||
<VButton size="sm" :disabled="!hasActiveFilter" @click="resetFilter">重置</VButton>
|
||||
</div>
|
||||
</div>
|
||||
</VCard>
|
||||
</div>
|
||||
|
||||
<VAlert v-if="error" class="audit-error" type="error" :closable="true" :title="error" />
|
||||
|
||||
<VCard :body-class="['!p-0']">
|
||||
<VLoading v-if="loading && !logs.length" />
|
||||
<template v-else>
|
||||
<VEmpty
|
||||
@@ -240,6 +242,18 @@ onMounted(fetchLogs)
|
||||
</template>
|
||||
</VEmpty>
|
||||
<template v-else>
|
||||
<!-- 列题头:列宽与下方数据行各 VEntityField 的 width 一一对应 -->
|
||||
<div class="audit-header">
|
||||
<div class="header-start">
|
||||
<span class="header-col col-username">操作者 / 时间</span>
|
||||
<span class="header-col col-method">动作</span>
|
||||
<span class="header-col col-resource">资源 / 路径</span>
|
||||
</div>
|
||||
<div class="header-end">
|
||||
<span class="header-col col-status">结果</span>
|
||||
<span class="header-col col-ip">IP</span>
|
||||
</div>
|
||||
</div>
|
||||
<VEntity
|
||||
v-for="log in logs"
|
||||
:key="log.metadata.name"
|
||||
@@ -247,19 +261,20 @@ onMounted(fetchLogs)
|
||||
@click="openDetail(log)"
|
||||
>
|
||||
<template #start>
|
||||
<VEntityField :title="displayUsername(log.spec.username)">
|
||||
<VEntityField :title="displayUsername(log.spec.username)" width="12rem">
|
||||
<template #description>
|
||||
<span class="row-sub">{{ formatTime(log.metadata.creationTimestamp) }}</span>
|
||||
</template>
|
||||
</VEntityField>
|
||||
<VEntityField :title="log.spec.method">
|
||||
<template #extra>
|
||||
<!-- 动作列:仅保留彩色徽标(原先 title 与徽标重复渲染两个相同文案) -->
|
||||
<VEntityField width="6rem">
|
||||
<template #title>
|
||||
<span class="method-badge" :class="methodBadgeClass(log.spec.method)">
|
||||
{{ log.spec.method }}
|
||||
</span>
|
||||
</template>
|
||||
</VEntityField>
|
||||
<VEntityField>
|
||||
<VEntityField width="20rem">
|
||||
<template #title>
|
||||
<span class="resource-text">
|
||||
{{ log.spec.resourceType }}
|
||||
@@ -272,8 +287,10 @@ onMounted(fetchLogs)
|
||||
</VEntityField>
|
||||
</template>
|
||||
<template #end>
|
||||
<VEntityField>
|
||||
<template #extra>
|
||||
<!-- 结果列:徽标经 #title 插槽渲染(当前版本组件在无 title 时
|
||||
不渲染 #extra,原先徽标实际不可见) -->
|
||||
<VEntityField width="4rem">
|
||||
<template #title>
|
||||
<span
|
||||
class="status-badge"
|
||||
:class="isSuccessful(log.spec.statusCode) ? 'status-ok' : 'status-fail'"
|
||||
@@ -282,24 +299,21 @@ onMounted(fetchLogs)
|
||||
</span>
|
||||
</template>
|
||||
</VEntityField>
|
||||
<VEntityField :title="log.spec.remoteIp" />
|
||||
<VEntityField :title="log.spec.remoteIp" width="9rem" />
|
||||
</template>
|
||||
</VEntity>
|
||||
</template>
|
||||
</template>
|
||||
</VCard>
|
||||
|
||||
<!-- 分页条置于卡片内部末尾:白底铺满整行,与上方列表左右对齐 -->
|
||||
<div v-if="total > 0" class="audit-pagination">
|
||||
<VPagination
|
||||
v-model:page="page"
|
||||
v-model:size="size"
|
||||
:total="total"
|
||||
:page-label="'页码'"
|
||||
:size-label="'每页条数'"
|
||||
:total-label="`共 ${total} 条`"
|
||||
:size-options="[10, 20, 50]"
|
||||
/>
|
||||
</div>
|
||||
</VCard>
|
||||
</div>
|
||||
|
||||
<AuditLogDetail v-model:visible="detailVisible" :log="selectedLog" />
|
||||
@@ -311,12 +325,14 @@ onMounted(fetchLogs)
|
||||
--audit-green: #4ccba0;
|
||||
--audit-dark: #0e1731;
|
||||
--audit-red: #d71d1d;
|
||||
/* 保持控制台默认灰底,内容以白色卡片呈现(与控制台其他页面观感一致) */
|
||||
flex: 1;
|
||||
}
|
||||
.audit-body {
|
||||
padding: 1rem 1.25rem 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
/* 筛选、数据、分页合并为一张白卡,区块之间不留灰缝 */
|
||||
}
|
||||
.audit-logo {
|
||||
display: inline-flex;
|
||||
@@ -334,7 +350,8 @@ onMounted(fetchLogs)
|
||||
}
|
||||
.filter-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
/* 7 个筛选字段 + 自动宽度的操作按钮,全部排成一行 */
|
||||
grid-template-columns: repeat(7, minmax(0, 1fr)) auto;
|
||||
gap: 0.75rem 1rem;
|
||||
align-items: end;
|
||||
}
|
||||
@@ -364,8 +381,36 @@ onMounted(fetchLogs)
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
/* 列题头:左右内边距与 entity 行(1rem)一致,列宽与数据行字段宽度一一对应 */
|
||||
.audit-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0.5rem 1rem;
|
||||
border-bottom: 1px solid #eaecf0;
|
||||
}
|
||||
.header-start {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
.header-end {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
margin-left: auto;
|
||||
}
|
||||
.header-col {
|
||||
font-size: 0.75rem;
|
||||
color: #666;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.col-username { width: 12rem; }
|
||||
.col-method { width: 6rem; }
|
||||
.col-resource { width: 20rem; }
|
||||
.col-status { width: 4rem; }
|
||||
.col-ip { width: 9rem; }
|
||||
.audit-error {
|
||||
--tw-ring-color: transparent;
|
||||
/* 错误提示位于白卡上方,与卡片留出间距 */
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.audit-row {
|
||||
cursor: pointer;
|
||||
@@ -407,8 +452,9 @@ onMounted(fetchLogs)
|
||||
.status-ok { color: #0f766e; background: rgba(76, 203, 160, 0.15); }
|
||||
.status-fail { color: var(--audit-red); background: rgba(215, 29, 29, 0.12); }
|
||||
.audit-pagination {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding-bottom: 1rem;
|
||||
/* 在白卡内铺满整行:白底与上方列表左右对齐;上下各留 1rem,
|
||||
文字的垂直位置与原分页条一致;上边缘 1px 分隔线同控制台卡片 footer 观感 */
|
||||
padding: 1rem;
|
||||
border-top: 1px solid #eaecf0;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user