feat: 操作审计描述拆为独立列(置于资源/路径与结果之间)

动作列仅保留方法徽标并收窄至 6rem,describeOperation 推导的中文描述
移入新的描述列(宽 10rem,超宽截断),题头与数据行同步调整;
外观回归测试更新为六列结构。
This commit is contained in:
2026-11-21 20:33:58 +08:00
parent 8aae68c95c
commit 7cca63b9d9
2 changed files with 36 additions and 25 deletions
@@ -49,11 +49,12 @@ describe('AuditLogList 页面外观', () => {
expect(rule).toMatch(/border-top:\s*1px\s+solid\s+#eaecf0/) expect(rule).toMatch(/border-top:\s*1px\s+solid\s+#eaecf0/)
}) })
it('列表数据行上方渲染列题头,五个列标签齐全', () => { it('列表数据行上方渲染列题头,六个列标签齐全', () => {
expect(sfc).toContain('<div class="audit-header">') expect(sfc).toContain('<div class="audit-header">')
expect(sfc).toContain('操作者 / 时间') expect(sfc).toContain('操作者 / 时间')
expect(sfc).toContain('>动作 / 描述<') expect(sfc).toContain('>动作<')
expect(sfc).toContain('资源 / 路径') expect(sfc).toContain('资源 / 路径')
expect(sfc).toContain('>描述<')
expect(sfc).toContain('>结果<') expect(sfc).toContain('>结果<')
expect(sfc).toContain('>IP<') expect(sfc).toContain('>IP<')
}) })
@@ -61,8 +62,9 @@ describe('AuditLogList 页面外观', () => {
it('题头列宽与数据行 VEntityField 的 width 一一对应', () => { it('题头列宽与数据行 VEntityField 的 width 一一对应', () => {
const pairs: Array<[string, string]> = [ const pairs: Array<[string, string]> = [
['col-username', '12rem'], ['col-username', '12rem'],
['col-method', '10rem'], ['col-method', '6rem'],
['col-resource', '20rem'], ['col-resource', '20rem'],
['col-desc', '10rem'],
['col-status', '4rem'], ['col-status', '4rem'],
['col-ip', '9rem'], ['col-ip', '9rem'],
] ]
@@ -88,15 +90,24 @@ describe('AuditLogList 页面外观', () => {
expect(header).toMatch(/border-bottom:\s*1px\s+solid\s+#eaecf0/) expect(header).toMatch(/border-bottom:\s*1px\s+solid\s+#eaecf0/)
}) })
it('动作列渲染彩色徽标 + 中文操作描述,结果列徽标经 #title 渲染', () => { it('动作列渲染彩色徽标,描述独立成列且位于资源/路径与结果之间', () => {
// 组件(@halo-dev/components 2.26.0)在无 title/#title 时不渲染 #extra, // 组件(@halo-dev/components 2.26.0)在无 title/#title 时不渲染 #extra,
// 原先结果徽标实际不可见;原先方法列 title 与徽标重复渲染同一文案。 // 原先结果徽标实际不可见;原先方法列 title 与徽标重复渲染同一文案。
// 动作列在徽标后追加 describeOperation 推导的中文描述(登录/新建用户/发布文章等), // 描述原先与徽标同行挤在动作列,现拆为独立列(describeOperation 推导的
// 外层 .action-cell 行内排开并在列宽内截断。 // 中文描述,如 登录/新建用户/发布文章),题头与数据行均置于资源/路径之后、结果之前。
expect(sfc).not.toContain(':title="log.spec.method"') expect(sfc).not.toContain(':title="log.spec.method"')
expect(sfc).toMatch(/<template #title>\s+<span\s+class="action-cell"/) expect(sfc).not.toContain('action-cell')
expect(sfc).toMatch(/<span\s+class="method-badge"[\s\S]*?<\/span>\s+<span class="action-desc">/) expect(sfc).toMatch(/<template #title>\s+<span\s+class="method-badge"/)
expect(sfc).toContain('describeOperation(log.spec)') expect(sfc).toContain('describeOperation(log.spec)')
expect(sfc).toMatch(/<span class="action-desc">\{\{ describeOperation\(log\.spec\) \}\}<\/span>/)
expect(sfc).toMatch(/<template #title>\s+<span\s+class="status-badge"/) expect(sfc).toMatch(/<template #title>\s+<span\s+class="status-badge"/)
// 数据行内 resource-text(资源/路径列)在 action-desc(描述列)之前,
// action-desc(描述列)在 status-badge(结果列)之前
const resourceIdx = sfc.indexOf('class="resource-text"')
const descIdx = sfc.indexOf('class="action-desc"')
const statusIdx = sfc.indexOf('class="status-badge"')
expect(resourceIdx).toBeGreaterThan(-1)
expect(descIdx).toBeGreaterThan(resourceIdx)
expect(statusIdx).toBeGreaterThan(descIdx)
}) })
}) })
@@ -247,8 +247,9 @@ onMounted(fetchLogs)
<div class="audit-header"> <div class="audit-header">
<div class="header-start"> <div class="header-start">
<span class="header-col col-username">操作者 / 时间</span> <span class="header-col col-username">操作者 / 时间</span>
<span class="header-col col-method">动作 / 描述</span> <span class="header-col col-method">动作</span>
<span class="header-col col-resource">资源 / 路径</span> <span class="header-col col-resource">资源 / 路径</span>
<span class="header-col col-desc">描述</span>
</div> </div>
<div class="header-end"> <div class="header-end">
<span class="header-col col-status">结果</span> <span class="header-col col-status">结果</span>
@@ -267,14 +268,11 @@ onMounted(fetchLogs)
<span class="row-sub">{{ formatTime(log.metadata.creationTimestamp) }}</span> <span class="row-sub">{{ formatTime(log.metadata.creationTimestamp) }}</span>
</template> </template>
</VEntityField> </VEntityField>
<!-- 动作列:彩色徽标 + 该操作实际语义的中文描述(如 登录/新建用户/发布文章) --> <!-- 动作列:彩色徽标标注请求方法 -->
<VEntityField width="10rem"> <VEntityField width="6rem">
<template #title> <template #title>
<span class="action-cell"> <span class="method-badge" :class="methodBadgeClass(log.spec.method)">
<span class="method-badge" :class="methodBadgeClass(log.spec.method)"> {{ log.spec.method }}
{{ log.spec.method }}
</span>
<span class="action-desc">{{ describeOperation(log.spec) }}</span>
</span> </span>
</template> </template>
</VEntityField> </VEntityField>
@@ -289,6 +287,12 @@ onMounted(fetchLogs)
<span class="row-sub">{{ log.spec.path }}</span> <span class="row-sub">{{ log.spec.path }}</span>
</template> </template>
</VEntityField> </VEntityField>
<!-- 描述列:该操作实际语义的中文描述(如 登录/新建用户/发布文章) -->
<VEntityField width="10rem">
<template #title>
<span class="action-desc">{{ describeOperation(log.spec) }}</span>
</template>
</VEntityField>
</template> </template>
<template #end> <template #end>
<!-- 结果列:徽标经 #title 插槽渲染(当前版本组件在无 title 时 <!-- 结果列:徽标经 #title 插槽渲染(当前版本组件在无 title 时
@@ -411,8 +415,9 @@ onMounted(fetchLogs)
white-space: nowrap; white-space: nowrap;
} }
.col-username { width: 12rem; } .col-username { width: 12rem; }
.col-method { width: 10rem; } .col-method { width: 6rem; }
.col-resource { width: 20rem; } .col-resource { width: 20rem; }
.col-desc { width: 10rem; }
.col-status { width: 4rem; } .col-status { width: 4rem; }
.col-ip { width: 9rem; } .col-ip { width: 9rem; }
.audit-error { .audit-error {
@@ -445,15 +450,10 @@ onMounted(fetchLogs)
color: #fff; color: #fff;
background: #6b7280; background: #6b7280;
} }
/* 动作列:徽标 + 描述同行排开,超宽时描述截断(列宽固定 10rem) */ /* 描述列:中文操作描述,超宽时截断(列宽固定 10rem) */
.action-cell {
display: inline-flex;
align-items: center;
gap: 0.375rem;
max-width: 9.75rem;
overflow: hidden;
}
.action-desc { .action-desc {
display: inline-block;
max-width: 9.75rem;
font-size: 0.8125rem; font-size: 0.8125rem;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;