mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
feat(m10): add audit event search and CSV export
This commit is contained in:
@@ -117,12 +117,28 @@ export function patchContractStatus(id, body) {
|
||||
|
||||
/**
|
||||
* M10-F01 审计分页:`GET /api/v1/audit-events`。
|
||||
* @param {{ entityType: string, entityId: string | number, page?: number, size?: number }} params
|
||||
* @param {{ entityType?: string, entityId?: string | number, page?: number, size?: number }} params
|
||||
*/
|
||||
export function listAuditEvents(params) {
|
||||
return axios.get("/api/v1/audit-events", { params });
|
||||
}
|
||||
|
||||
/**
|
||||
* M10-F02 审计检索:`GET /api/v1/audit-events`(无分页)。
|
||||
* @param {{ entityType?: string, entityId?: string | number, from?: string, to?: string }} params
|
||||
*/
|
||||
export function searchAuditEvents(params) {
|
||||
return axios.get("/api/v1/audit-events", { params });
|
||||
}
|
||||
|
||||
/**
|
||||
* M10-F03 审计导出 CSV:`GET /api/v1/audit-events/export`。
|
||||
* @param {{ entityType?: string, entityId?: string | number, from?: string, to?: string }} params
|
||||
*/
|
||||
export function exportAuditEvents(params) {
|
||||
return axios.get("/api/v1/audit-events/export", { params, responseType: 'blob' });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ page?: number, size?: number, projectId?: string | number, keyword?: string }} params
|
||||
*/
|
||||
|
||||
@@ -182,6 +182,12 @@ const routes = [
|
||||
component: () => import("../views/ProjectHealthView.vue"),
|
||||
meta: { roles: ["SYS_ADMIN"], title: "项目健康度" },
|
||||
},
|
||||
{
|
||||
path: "audit",
|
||||
name: "audit",
|
||||
component: () => import("../views/AuditSearchView.vue"),
|
||||
meta: { roles: ["SYS_ADMIN"], title: "审计日志" },
|
||||
},
|
||||
],
|
||||
},
|
||||
{ path: "/403", name: "forbidden", component: () => import("../views/ForbiddenView.vue") },
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
<template>
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<div class="toolbar">
|
||||
<span class="title">审计日志</span>
|
||||
<div class="actions">
|
||||
<el-input v-model="filters.entityType" clearable placeholder="实体类型" class="filter-item" />
|
||||
<el-input v-model="filters.entityId" clearable placeholder="实体 ID" class="filter-item" />
|
||||
<el-input v-model="filters.userId" clearable placeholder="操作者" class="filter-item" />
|
||||
<el-date-picker
|
||||
v-model="dateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
value-format="YYYY-MM-DD"
|
||||
class="filter-item"
|
||||
/>
|
||||
<el-button type="primary" :loading="loading" @click="load">查询</el-button>
|
||||
<el-button :loading="exporting" @click="onExport">导出 CSV</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" :data="rows" stripe style="width: 100%">
|
||||
<el-table-column label="时间" min-width="180">
|
||||
<template #default="{ row }">{{ row.createdAt }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="actorUserId" label="操作者" min-width="140" />
|
||||
<el-table-column prop="action" label="动作" min-width="100" />
|
||||
<el-table-column prop="entityType" label="实体类型" min-width="120" />
|
||||
<el-table-column prop="entityId" label="实体 ID" width="100" />
|
||||
<el-table-column prop="fieldName" label="摘要" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column label="详情" min-width="200" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.oldValue }} → {{ row.newValue }}</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pager">
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
background
|
||||
@current-change="load"
|
||||
@size-change="onSizeChange"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { useAuthStore } from "../stores/auth";
|
||||
import { listAuditEvents, exportAuditEvents } from "../api/platform";
|
||||
import { apiErrorMessage } from "../utils/apiErrorMessage";
|
||||
|
||||
const auth = useAuthStore();
|
||||
|
||||
const loading = ref(false);
|
||||
const exporting = ref(false);
|
||||
const rows = ref([]);
|
||||
const total = ref(0);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const dateRange = ref(null);
|
||||
|
||||
const filters = reactive({
|
||||
entityType: "",
|
||||
entityId: "",
|
||||
userId: "",
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
auth.restoreAxiosAuth();
|
||||
load();
|
||||
});
|
||||
|
||||
function onSizeChange() {
|
||||
page.value = 1;
|
||||
load();
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params = {
|
||||
page: page.value - 1,
|
||||
size: pageSize.value,
|
||||
};
|
||||
if (filters.entityType) params.entityType = filters.entityType.trim();
|
||||
if (filters.entityId) params.entityId = filters.entityId.trim();
|
||||
if (filters.userId) params.userId = filters.userId.trim();
|
||||
if (dateRange.value) {
|
||||
params.from = dateRange.value[0];
|
||||
params.to = dateRange.value[1];
|
||||
}
|
||||
const { data } = await listAuditEvents(params);
|
||||
const body = data && typeof data === "object" ? data : {};
|
||||
rows.value = Array.isArray(body.content) ? body.content : [];
|
||||
total.value = Number(body.totalElements ?? body.total ?? 0);
|
||||
} catch (e) {
|
||||
ElMessage.error(apiErrorMessage(e, "加载审计日志失败"));
|
||||
rows.value = [];
|
||||
total.value = 0;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function onExport() {
|
||||
exporting.value = true;
|
||||
try {
|
||||
const params = {};
|
||||
if (filters.entityType) params.entityType = filters.entityType.trim();
|
||||
if (filters.entityId) params.entityId = filters.entityId.trim();
|
||||
if (filters.userId) params.userId = filters.userId.trim();
|
||||
if (dateRange.value) {
|
||||
params.from = dateRange.value[0];
|
||||
params.to = dateRange.value[1];
|
||||
}
|
||||
const res = await exportAuditEvents(params);
|
||||
const blob = new Blob([res.data], { type: "text/csv;charset=utf-8" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = `audit-events-${new Date().toISOString().slice(0, 10)}.csv`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
ElMessage.success("导出成功");
|
||||
} catch (e) {
|
||||
ElMessage.error(apiErrorMessage(e, "导出失败"));
|
||||
} finally {
|
||||
exporting.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
.title {
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.filter-item {
|
||||
width: 160px;
|
||||
}
|
||||
.pager {
|
||||
margin-top: 16px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user