From 838592253a98d3fef281e84b0d3ab7ddff6b8e2c Mon Sep 17 00:00:00 2001 From: dap1 <15891557205@163.com> Date: Sat, 10 Jun 2023 13:04:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=93=8D=E4=BD=9C=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/src/hooks/useRender.ts | 20 +++ src/views/system/operatelog/LogInfoModal.vue | 27 ++++ src/views/system/operatelog/index.vue | 31 ++++- .../system/operatelog/operateLog.data.ts | 120 ++++++++++++++++-- 4 files changed, 183 insertions(+), 15 deletions(-) create mode 100644 src/views/system/operatelog/LogInfoModal.vue diff --git a/src/components/Table/src/hooks/useRender.ts b/src/components/Table/src/hooks/useRender.ts index a7e4eb1a..af1bc4a4 100644 --- a/src/components/Table/src/hooks/useRender.ts +++ b/src/components/Table/src/hooks/useRender.ts @@ -5,6 +5,7 @@ import { isArray, isString } from '@/utils/is' import { DictTag } from '@/components/DictTag' import { Icon } from '@/components/Icon' import TableImg from '../components/TableImg.vue' +import { JsonPreview } from '@/components/CodeEditor' export const useRender = { /** @@ -112,5 +113,24 @@ export const useRender = { if (text) { return h(Icon, { icon: text }) } + }, + /** + * 使用JsonPreview组件 方便预览JSON + * @param json json字符串/obj + * @returns 能转为json返回JsonPreview 否则返回自身 + */ + renderJsonPreview: (json: any) => { + if (!json) return '' + if (typeof json === 'object') { + return h(JsonPreview, { data: json }) + } + if (typeof json === 'string') { + try { + const data = JSON.parse(json) + return h(JsonPreview, { data }) + } catch (e) { + return json + } + } } } diff --git a/src/views/system/operatelog/LogInfoModal.vue b/src/views/system/operatelog/LogInfoModal.vue new file mode 100644 index 00000000..63d1971b --- /dev/null +++ b/src/views/system/operatelog/LogInfoModal.vue @@ -0,0 +1,27 @@ + + + + + diff --git a/src/views/system/operatelog/index.vue b/src/views/system/operatelog/index.vue index c5f28a83..93fbd163 100644 --- a/src/views/system/operatelog/index.vue +++ b/src/views/system/operatelog/index.vue @@ -4,16 +4,32 @@ + + diff --git a/src/views/system/operatelog/operateLog.data.ts b/src/views/system/operatelog/operateLog.data.ts index 8e0473c4..d509b9e3 100644 --- a/src/views/system/operatelog/operateLog.data.ts +++ b/src/views/system/operatelog/operateLog.data.ts @@ -1,5 +1,6 @@ import { BasicColumn, FormSchema, useRender } from '@/components/Table' import { DICT_TYPE, getDictOptions } from '@/utils/dict' +import { DescItem } from '@/components/Description/index' export const columns: BasicColumn[] = [ { @@ -10,7 +11,7 @@ export const columns: BasicColumn[] = [ { title: '操作模块', dataIndex: 'module', - width: 120 + width: 200 }, { title: '操作名', @@ -20,7 +21,7 @@ export const columns: BasicColumn[] = [ { title: '操作类型', dataIndex: 'type', - width: 180, + width: 120, customRender: ({ text }) => { return useRender.renderDict(text, DICT_TYPE.SYSTEM_OPERATE_TYPE) } @@ -30,10 +31,14 @@ export const columns: BasicColumn[] = [ dataIndex: 'userNickname', width: 120 }, + // { + // title: 'userAgent', + // dataIndex: 'userAgent', + // width: 400 + // }, { - title: 'userAgent', - dataIndex: 'userAgent', - width: 400 + title: '请求路径', + dataIndex: 'requestUrl' }, { title: '操作结果', @@ -43,14 +48,6 @@ export const columns: BasicColumn[] = [ return useRender.renderTag(text === 0 ? '成功' : '失败', text === 0 ? '#87d068' : '#f50') } }, - { - title: '操作日期', - dataIndex: 'startTime', - width: 180, - customRender: ({ text }) => { - return useRender.renderDate(text) - } - }, { title: '执行时长', dataIndex: 'duration', @@ -58,6 +55,14 @@ export const columns: BasicColumn[] = [ customRender: ({ text }) => { return useRender.renderText(text, 'ms') } + }, + { + title: '操作日期', + dataIndex: 'startTime', + width: 180, + customRender: ({ text }) => { + return useRender.renderDate(text) + } } ] @@ -102,3 +107,92 @@ export const searchFormSchema: FormSchema[] = [ colProps: { span: 8 } } ] + +const httpMethods = [ + { value: 'GET', color: '#108ee9' }, + { value: 'POST', color: '#2db7f5' }, + { value: 'PUT', color: 'warning' }, + { value: 'DELETE', color: '#f50' } +] + +export const infoSchema: DescItem[] = [ + { + field: 'module', + label: '操作模块' + }, + { + field: 'name', + label: '操作名' + }, + { + field: 'userNickname', + label: '操作人', + render(_, data) { + const { userNickname, userId } = data + return useRender.renderText(userNickname, 'uid: ' + userId) + } + }, + { + field: 'resultCode', + label: '请求结果', + render(value) { + return useRender.renderTag(value === 0 ? '成功' : '失败', value === 0 ? '#87d068' : '#f50') + } + }, + { + field: 'resultMsg', + label: '响应信息', + show(data) { + return data && data.resultMsg && data.resultMsg !== '' + } + }, + { + field: 'userIp', + label: '请求ip' + }, + { + field: 'startTime', + label: '请求时间', + render(value) { + return useRender.renderDate(value) + } + }, + { + field: 'requestUrl', + label: '请求路径' + }, + { + field: 'requestMethod', + label: '请求方法', + render(value) { + const current = httpMethods.find((item) => item.value === value.toUpperCase()) + if (current) { + return useRender.renderTag(value, current.color) + } + return value + } + }, + { + field: 'javaMethod', + label: '操作方法', + labelMinWidth: 80 + }, + { + field: 'javaMethodArgs', + label: '请求参数', + render(value) { + return useRender.renderJsonPreview(value) + } + }, + { + field: 'userAgent', + label: 'userAgent' + }, + { + field: 'duration', + label: '请求耗时', + render(value) { + return useRender.renderText(value, 'ms') + } + } +]