feat(admin): AuditLogs + RuntimeLogs views + RBAC role management

This commit is contained in:
Simon
2026-07-09 13:46:20 +08:00
parent d480aa4c1d
commit db70a3a6a8
10 changed files with 957 additions and 27 deletions
+78 -1
View File
@@ -5,6 +5,21 @@
// 所有函数返回 axios response,调用方从 response 获取业务数据
import apiClient from './index'
import axios from 'axios'
// 运行期日志下载使用独立 axios 实例:响应为 blob(文件流),
// 不能走 apiClient 的 JSON 信封拦截器(会把 blob 当成 {code,message,data} 解析而报错)。
const downloadClient = axios.create({
baseURL: '/api',
timeout: 30000,
})
downloadClient.interceptors.request.use((config) => {
const token = localStorage.getItem('admin_token')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})
import type {
DashboardOverview,
ConfigGroup,
@@ -29,6 +44,7 @@ import type {
RoleRevokeRequest,
RoleMappingRule,
RoleMappingRuleRequest,
EmployeeSearchResponse,
} from '@/types'
// ==========================================================================
@@ -387,6 +403,13 @@ export function assignRole(
return apiClient.post('/admin/roles/assign', data)
}
/** 员工目录搜索(分配角色时按姓名/账号自动补全) */
export function searchEmployees(
q: string
): Promise<{ data: { code: number; data: EmployeeSearchResponse; message: string } }> {
return apiClient.get('/admin/roles/employees/search', { params: { q } })
}
/** 撤销用户角色 */
export function revokeRole(
data: RoleRevokeRequest
@@ -454,14 +477,65 @@ export function getAgentPerformance(params?: {
// P2: 系统日志
// ==========================================================================
/** 获取系统日志(配置变更日志) */
/** 获取系统日志(配置变更历史),支持配置键/操作人/时间范围筛选 */
export function getSystemLogs(params?: {
page?: number
page_size?: number
config_key?: string
changed_by?: string
from?: string
to?: string
}): Promise<{ data: { code: number; data: { items: any[]; total: number; page: number; page_size: number }; message: string } }> {
return apiClient.get('/admin/system-logs', { params })
}
// ==========================================================================
// 安全审计日志 (B) — 复用既有后端 GET /admin/audit-logs
// ==========================================================================
/** 获取安全审计日志(分页 + 操作人/操作类型/时间范围筛选) */
export function getAuditLogs(params?: {
employee_id?: string
action?: string
from?: string
to?: string
page?: number
page_size?: number
}): Promise<{ data: { code: number; data: { items: any[]; total: number; page: number; page_size: number }; message: string } }> {
return apiClient.get('/admin/audit-logs', { params })
}
// ==========================================================================
// 运行期日志 (D) — 新增后端 GET /admin/runtime-logs
// ==========================================================================
/** 获取运行期日志(分页 + 级别/时间/关键字筛选) */
export function getRuntimeLogs(params?: {
level?: string
from?: string
to?: string
keyword?: string
page?: number
page_size?: number
}): Promise<{ data: { code: number; data: { items: any[]; total: number; page: number; page_size: number }; message: string } }> {
return apiClient.get('/admin/runtime-logs', { params })
}
/** 下载运行期日志(命中行文本,blob 流,responseType: blob */
export function getRuntimeLogDownload(params?: {
level?: string
from?: string
to?: string
keyword?: string
}): Promise<Blob> {
return downloadClient
.get('/admin/runtime-logs', {
params: { ...params, download: true },
responseType: 'blob',
})
.then((res) => res.data as Blob)
}
// ==========================================================================
// P2: 满意度评价统计
// ==========================================================================
@@ -633,4 +707,7 @@ export const adminApi = {
getAgentPerformance,
getSystemLogs,
getEvaluationStats,
getAuditLogs,
getRuntimeLogs,
getRuntimeLogDownload,
}