diff --git a/z_ele/src/api/system/operation-record/index.ts b/z_ele/src/api/system/operation-record/index.ts index c2eda50..2e8c413 100644 --- a/z_ele/src/api/system/operation-record/index.ts +++ b/z_ele/src/api/system/operation-record/index.ts @@ -7,7 +7,7 @@ import type { OperationRecord, OperationRecordParam } from './model'; */ export async function pageOperationRecords(params: OperationRecordParam) { const res = await request.get>>( - '/system/request-record/page', + '/system/operate-record/page', { params } ); if (res.data.code === 0) { @@ -15,17 +15,3 @@ export async function pageOperationRecords(params: OperationRecordParam) { } return Promise.reject(new Error(res.data.message)); } - -/** - * 查询操作日志列表 - */ -export async function listOperationRecords(params?: OperationRecordParam) { - const res = await request.get>( - '/system/request-record', - { params } - ); - if (res.data.code === 0 && res.data.data) { - return res.data.data; - } - return Promise.reject(new Error(res.data.message)); -} diff --git a/z_ele/src/api/system/operation-record/model/index.ts b/z_ele/src/api/system/operation-record/model/index.ts index c7e9c7f..7d7ace6 100644 --- a/z_ele/src/api/system/operation-record/model/index.ts +++ b/z_ele/src/api/system/operation-record/model/index.ts @@ -8,38 +8,16 @@ export interface OperationRecord { id?: number; /** 用户id */ userId?: number; - /** 操作模块 */ - module: string; + /** 操作数据 */ + data: string; /** 操作功能 */ description: string; - /** 请求地址 */ - url: string; - /** 请求方式 */ - requestMethod: string; - /** 调用方法 */ - method: string; - /** 请求参数 */ - params: string; - /** 返回结果 */ - result: string; - /** 异常信息 */ - error: string; - /** 消耗时间, 单位毫秒 */ - spendTime: number; - /** 操作系统 */ - os: string; - /** 设备名称 */ - device: string; - /** 浏览器类型 */ - browser: string; - /** ip地址 */ - ip: string; - /** 状态, 0成功, 1异常 */ - status: number; + /** ContextId */ + contextId: string; /** 操作时间 */ createTime: string; - /** 用户昵称 */ - nickname: string; + /** 地址 */ + location: string; /** 用户账号 */ username: string; } @@ -51,11 +29,9 @@ export interface OperationRecordParam extends PageParam { /** 用户昵称 */ username?: string; /** 操作模块 */ - module?: string; + location?: string; /** 开始时间 */ createTimeStart?: string; /** 截至时间 */ createTimeEnd?: string; - /** 状态 */ - status?: number; } diff --git a/z_ele/src/utils/common.ts b/z_ele/src/utils/common.ts index d6187d8..4d91f6b 100644 --- a/z_ele/src/utils/common.ts +++ b/z_ele/src/utils/common.ts @@ -220,7 +220,6 @@ export function doWithTransition( }); } - /** * 将字节数转换为易读的存储单位(GB, MB, KB, B) * @param bytes 字节数量 @@ -250,3 +249,78 @@ export function formatBytes(bytes: number, precision: number = 2): string { return `${formattedValue}${unit}`; } + +/** + * 格式化JSON字符串 + * @param {string} jsonString - 需要格式化的JSON字符串 + * @param {number} indentSpaces - 缩进空格数(默认为2) + * @returns {string} 格式化后的JSON字符串 + * @throws {Error} 当输入不是有效的JSON时抛出错误 + */ +export function formatJson(jsonString, indentSpaces = 2) { + // 验证输入是否为字符串 + + // 解析JSON字符串为JavaScript对象 + let parsedObj; + if (typeof jsonString === 'string') { + // throw new Error('输入必须是字符串'); + try { + parsedObj = JSON.parse(jsonString); + } catch (e: any) { + throw new Error('无效的JSON格式: ' + e.message); + } + } else { + parsedObj = jsonString; + } + + // 递归函数来处理格式化 + function format(obj, depth) { + // 处理基本类型 + if (obj === null) { + return 'null'; + } + + if (typeof obj === 'boolean' || typeof obj === 'number') { + return obj.toString(); + } + + if (typeof obj === 'string') { + return '"' + obj + '"'; + } + + // 处理数组 + if (Array.isArray(obj)) { + if (obj.length === 0) { + return '[]'; + } + + const indent = ' '.repeat(depth * indentSpaces); + const innerIndent = ' '.repeat((depth + 1) * indentSpaces); + const items: any = []; + + for (let i = 0; i < obj.length; i++) { + items.push(innerIndent + format(obj[i], depth + 1)); + } + + return '[\n' + items.join(',\n') + '\n' + indent + ']'; + } + + // 处理对象 + const indent = ' '.repeat(depth * indentSpaces); + const innerIndent = ' '.repeat((depth + 1) * indentSpaces); + const keys = Object.keys(obj); + + if (keys.length === 0) { + return '{}'; + } + + const items: any = []; + for (const key of keys) { + items.push(innerIndent + '"' + key + '": ' + format(obj[key], depth + 1)); + } + + return '{\n' + items.join(',\n') + '\n' + indent + '}'; + } + + return format(parsedObj, 0); +} diff --git a/z_ele/src/views/system/operation-record/components/operation-record-detail.vue b/z_ele/src/views/system/operation-record/components/operation-record-detail.vue index 405a2b3..96e9e8c 100644 --- a/z_ele/src/views/system/operation-record/components/operation-record-detail.vue +++ b/z_ele/src/views/system/operation-record/components/operation-record-detail.vue @@ -8,102 +8,49 @@ class="detail-table" > -
{{ data.nickname }}({{ data.username }})
+
{{ data.contextId }}
- -
{{ data.ip }}
+ +
{{ data.location }}
- -
{{ data.module }}
-
- +
{{ data.description }}
{{ data.createTime }}
- -
{{ data.spendTime / 1000 }}s
+ +
{{ data.event }}
- -
{{ data.requestMethod }}
-
- - - 正常 - - - 异常 - - - -
{{ data.url }}
-
- -
{{ data.method }}
-
- - - {{ data.params }} - - - - - {{ data.result }} - - - - - {{ data.error }} - + + diff --git a/z_ele/src/views/system/operation-record/components/operation-record-search.vue b/z_ele/src/views/system/operation-record/components/operation-record-search.vue index c00047b..2a77168 100644 --- a/z_ele/src/views/system/operation-record/components/operation-record-search.vue +++ b/z_ele/src/views/system/operation-record/components/operation-record-search.vue @@ -13,7 +13,7 @@ - + - -