feat: 列表行内「查看该资源历史」快捷动作(P1-1,纯前端)
- AuditLogList 资源列行内新增「历史」小链接(仅有资源名称的记录展示), 点击预填资源类型 + 资源名关键字(关键字匹配资源名称/路径)并刷新列表, 停止冒泡避免触发行点击的详情抽屉 - 不新增后端参数,与现有筛选/导出条件共用同一套状态(buildQuery 不变) - 新增 vitest 结构性回归测试(预填与请求参数生成/行内渲染/冒泡阻止)
This commit is contained in:
@@ -19,6 +19,8 @@ Halo 2.x 操作审计插件:回答"**谁、在什么时候、对什么资源
|
|||||||
中文操作描述由同一套推导生成,贯穿列表、详情与导出 CSV,历史记录同样适用。
|
中文操作描述由同一套推导生成,贯穿列表、详情与导出 CSV,历史记录同样适用。
|
||||||
- **审计日志查看**:Console 左侧菜单"操作审计"——列表 + 八维筛选(操作者/资源类型/动作/
|
- **审计日志查看**:Console 左侧菜单"操作审计"——列表 + 八维筛选(操作者/资源类型/动作/
|
||||||
语义动作/结果/时间区间/关键字)+ 分页 + 只读详情抽屉(含原始 JSON)。不提供任何删除/修改入口。
|
语义动作/结果/时间区间/关键字)+ 分页 + 只读详情抽屉(含原始 JSON)。不提供任何删除/修改入口。
|
||||||
|
有资源名称的记录行内提供「历史」快捷动作:一键预填资源类型 + 资源名关键字并刷新列表,
|
||||||
|
直接回答"这个资源被谁改过"(功能评审 P1-1)。
|
||||||
- **导出 CSV**:列表页「导出」按钮按当前筛选条件导出全部记录——后端全量流式生成
|
- **导出 CSV**:列表页「导出」按钮按当前筛选条件导出全部记录——后端全量流式生成
|
||||||
(UTF-8 BOM + `\r\n`,Excel/WPS 双击打开中文不乱码),列与界面一致(操作时间、操作者、
|
(UTF-8 BOM + `\r\n`,Excel/WPS 双击打开中文不乱码),列与界面一致(操作时间、操作者、
|
||||||
尝试用户、动作、资源类型、资源名称、路径、操作描述、变更、结果、状态码、来源 IP、
|
尝试用户、动作、资源类型、资源名称、路径、操作描述、变更、结果、状态码、来源 IP、
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
// 结构性回归测试:不渲染组件,仅检查 SFC 源码中的资源历史快捷链路。
|
||||||
|
// 「查看该资源历史」为列表行内快捷动作(功能评审 P1-1):产品定位第一个典型场景
|
||||||
|
// ("这篇文章谁改过的")——点击预填 resourceType + 资源名关键字(关键字匹配资源
|
||||||
|
// 名称/路径)并刷新列表;不新增后端参数,与现有筛选/导出条件共用同一套状态。
|
||||||
|
const sfc = readFileSync(fileURLToPath(new URL('./AuditLogList.vue', import.meta.url)), 'utf-8')
|
||||||
|
|
||||||
|
describe('AuditLogList 查看该资源历史', () => {
|
||||||
|
it('行内快捷动作:仅在有资源名称的记录上渲染,stop 冒泡避免触发详情抽屉', () => {
|
||||||
|
const rowStart = sfc.indexOf('<VEntity')
|
||||||
|
const rowEnd = sfc.indexOf('</VEntity>', rowStart)
|
||||||
|
const row = sfc.slice(rowStart, rowEnd)
|
||||||
|
expect(row).toContain('v-if="log.spec.resourceName"')
|
||||||
|
expect(row).toContain('@click.stop="viewResourceHistory(log)"')
|
||||||
|
expect(row).toContain('查看该资源的历史操作')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('预填筛选:资源类型 + 资源名关键字,并走统一查询入口刷新列表', () => {
|
||||||
|
const fnStart = sfc.indexOf('function viewResourceHistory(log: AuditLog)')
|
||||||
|
expect(fnStart).toBeGreaterThan(-1)
|
||||||
|
const fn = sfc.slice(fnStart, sfc.indexOf('</script>', fnStart))
|
||||||
|
expect(fn).toContain('filterResourceType.value = log.spec.resourceType')
|
||||||
|
expect(fn).toContain("filterKeyword.value = log.spec.resourceName ?? ''")
|
||||||
|
expect(fn).toContain('applyFilters()')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('不新增后端参数:复用现有 resourceType fieldSelector 与 keyword 模糊匹配', () => {
|
||||||
|
// 与现有筛选/导出条件共用同一套状态——buildQuery 生成相同参数形态
|
||||||
|
expect(sfc).toContain("params.append('fieldSelector', `spec.resourceType=${filterResourceType.value}`)")
|
||||||
|
expect(sfc).toContain("params.set('keyword', filterKeyword.value.trim())")
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -176,6 +176,17 @@ function resetFilter() {
|
|||||||
filterEndTime.value = ''
|
filterEndTime.value = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看该资源历史(功能评审 P1-1):行内快捷动作——预填资源类型 + 资源名关键字
|
||||||
|
* (关键字匹配资源名称/路径)并刷新列表,与现有筛选/导出条件共用同一套状态,
|
||||||
|
* 不新增后端参数。仅在有资源名称的记录上提供(集合级/登录操作无可回溯的具体资源)。
|
||||||
|
*/
|
||||||
|
function viewResourceHistory(log: AuditLog) {
|
||||||
|
filterResourceType.value = log.spec.resourceType
|
||||||
|
filterKeyword.value = log.spec.resourceName ?? ''
|
||||||
|
applyFilters()
|
||||||
|
}
|
||||||
|
|
||||||
watch([filterUsername, filterResourceType, filterMethod, filterAction, filterResult], () => {
|
watch([filterUsername, filterResourceType, filterMethod, filterAction, filterResult], () => {
|
||||||
page.value = 1
|
page.value = 1
|
||||||
fetchLogs()
|
fetchLogs()
|
||||||
@@ -348,6 +359,14 @@ onMounted(fetchLogs)
|
|||||||
{{ log.spec.resourceType }}
|
{{ log.spec.resourceType }}
|
||||||
<template v-if="log.spec.resourceName">/ {{ log.spec.resourceName }}</template>
|
<template v-if="log.spec.resourceName">/ {{ log.spec.resourceName }}</template>
|
||||||
</span>
|
</span>
|
||||||
|
<!-- 行内快捷动作(功能评审 P1-1):查看该资源的历史操作;
|
||||||
|
stop 冒泡避免触发行点击的详情抽屉 -->
|
||||||
|
<a
|
||||||
|
v-if="log.spec.resourceName"
|
||||||
|
class="resource-history-link"
|
||||||
|
title="查看该资源的历史操作"
|
||||||
|
@click.stop="viewResourceHistory(log)"
|
||||||
|
>历史</a>
|
||||||
</template>
|
</template>
|
||||||
<template #description>
|
<template #description>
|
||||||
<span class="row-sub">{{ log.spec.path }}</span>
|
<span class="row-sub">{{ log.spec.path }}</span>
|
||||||
@@ -506,6 +525,16 @@ onMounted(fetchLogs)
|
|||||||
.resource-text {
|
.resource-text {
|
||||||
font-size: 0.8125rem;
|
font-size: 0.8125rem;
|
||||||
}
|
}
|
||||||
|
/* 行内快捷动作:查看该资源历史(P1-1),主题绿小链接 */
|
||||||
|
.resource-history-link {
|
||||||
|
margin-left: 0.375rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: var(--audit-green);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.resource-history-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
.method-badge {
|
.method-badge {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0.1rem 0.4rem;
|
padding: 0.1rem 0.4rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user