feat: 操作审计动作列与详情增加中文操作描述(登录/新建用户/发布文章等)
- utils/audit.ts 新增 describeOperation 纯函数:由 method/resourceType/path 推导中文短语(登录、登出、认证操作、动词+资源中文名、子动作拼接如 发布文章/启用插件、完整短语如修改密码),纯展示层推导,历史记录同样适用 - 列表动作列在徽标后渲染描述(列宽 6rem→10rem),题头改为「动作 / 描述」 - 详情抽屉顶部新增「描述」行 - 新增 utils/audit.spec.ts 10 项用例覆盖全部推导与回退路径, 外观回归测试同步列宽与动作列结构
This commit is contained in:
@@ -3,6 +3,7 @@ import { computed } from 'vue'
|
||||
import { VButton, VSpace } from '@halo-dev/components'
|
||||
import type { AuditLog } from '@/utils/audit'
|
||||
import {
|
||||
describeOperation,
|
||||
displayUsername,
|
||||
formatTime,
|
||||
isSuccessful,
|
||||
@@ -61,6 +62,10 @@ const rawJson = computed(() =>
|
||||
<dt>操作者</dt>
|
||||
<dd>{{ displayUsername(log.spec.username) }}</dd>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<dt>描述</dt>
|
||||
<dd>{{ describeOperation(log.spec) }}</dd>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<dt>动作</dt>
|
||||
<dd>
|
||||
|
||||
@@ -52,7 +52,7 @@ describe('AuditLogList 页面外观', () => {
|
||||
it('列表数据行上方渲染列题头,五个列标签齐全', () => {
|
||||
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('>IP<')
|
||||
@@ -61,7 +61,7 @@ describe('AuditLogList 页面外观', () => {
|
||||
it('题头列宽与数据行 VEntityField 的 width 一一对应', () => {
|
||||
const pairs: Array<[string, string]> = [
|
||||
['col-username', '12rem'],
|
||||
['col-method', '6rem'],
|
||||
['col-method', '10rem'],
|
||||
['col-resource', '20rem'],
|
||||
['col-status', '4rem'],
|
||||
['col-ip', '9rem'],
|
||||
@@ -88,11 +88,15 @@ describe('AuditLogList 页面外观', () => {
|
||||
expect(header).toMatch(/border-bottom:\s*1px\s+solid\s+#eaecf0/)
|
||||
})
|
||||
|
||||
it('动作列仅保留彩色徽标、结果列徽标经 #title 渲染', () => {
|
||||
it('动作列渲染彩色徽标 + 中文操作描述,结果列徽标经 #title 渲染', () => {
|
||||
// 组件(@halo-dev/components 2.26.0)在无 title/#title 时不渲染 #extra,
|
||||
// 原先结果徽标实际不可见;原先方法列 title 与徽标重复渲染同一文案。
|
||||
// 动作列在徽标后追加 describeOperation 推导的中文描述(登录/新建用户/发布文章等),
|
||||
// 外层 .action-cell 行内排开并在列宽内截断。
|
||||
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="action-cell"/)
|
||||
expect(sfc).toMatch(/<span\s+class="method-badge"[\s\S]*?<\/span>\s+<span class="action-desc">/)
|
||||
expect(sfc).toContain('describeOperation(log.spec)')
|
||||
expect(sfc).toMatch(/<template #title>\s+<span\s+class="status-badge"/)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from '@halo-dev/components'
|
||||
import type { AuditLog, ListResult } from '@/utils/audit'
|
||||
import {
|
||||
describeOperation,
|
||||
displayUsername,
|
||||
formatTime,
|
||||
isSuccessful,
|
||||
@@ -246,7 +247,7 @@ onMounted(fetchLogs)
|
||||
<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-method">动作 / 描述</span>
|
||||
<span class="header-col col-resource">资源 / 路径</span>
|
||||
</div>
|
||||
<div class="header-end">
|
||||
@@ -266,11 +267,14 @@ onMounted(fetchLogs)
|
||||
<span class="row-sub">{{ formatTime(log.metadata.creationTimestamp) }}</span>
|
||||
</template>
|
||||
</VEntityField>
|
||||
<!-- 动作列:仅保留彩色徽标(原先 title 与徽标重复渲染两个相同文案) -->
|
||||
<VEntityField width="6rem">
|
||||
<!-- 动作列:彩色徽标 + 该操作实际语义的中文描述(如 登录/新建用户/发布文章) -->
|
||||
<VEntityField width="10rem">
|
||||
<template #title>
|
||||
<span class="method-badge" :class="methodBadgeClass(log.spec.method)">
|
||||
{{ log.spec.method }}
|
||||
<span class="action-cell">
|
||||
<span class="method-badge" :class="methodBadgeClass(log.spec.method)">
|
||||
{{ log.spec.method }}
|
||||
</span>
|
||||
<span class="action-desc">{{ describeOperation(log.spec) }}</span>
|
||||
</span>
|
||||
</template>
|
||||
</VEntityField>
|
||||
@@ -407,7 +411,7 @@ onMounted(fetchLogs)
|
||||
white-space: nowrap;
|
||||
}
|
||||
.col-username { width: 12rem; }
|
||||
.col-method { width: 6rem; }
|
||||
.col-method { width: 10rem; }
|
||||
.col-resource { width: 20rem; }
|
||||
.col-status { width: 4rem; }
|
||||
.col-ip { width: 9rem; }
|
||||
@@ -441,6 +445,20 @@ onMounted(fetchLogs)
|
||||
color: #fff;
|
||||
background: #6b7280;
|
||||
}
|
||||
/* 动作列:徽标 + 描述同行排开,超宽时描述截断(列宽固定 10rem) */
|
||||
.action-cell {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
max-width: 9.75rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
.action-desc {
|
||||
font-size: 0.8125rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.method-post { background: #1e7ee0; }
|
||||
.method-put { background: #d97706; }
|
||||
.method-delete { background: var(--audit-red); }
|
||||
|
||||
Reference in New Issue
Block a user