feat:增加 api 访问日志、错误日志
							parent
							
								
									5fbbfdd3ba
								
							
						
					
					
						commit
						1b8dcfcc3b
					
				| 
						 | 
					@ -0,0 +1,42 @@
 | 
				
			||||||
 | 
					import type { PageParam, PageResult } from '@vben/request';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { requestClient } from '#/api/request';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export namespace InfraApiAccessLogApi {
 | 
				
			||||||
 | 
					  /** API 访问日志信息 */
 | 
				
			||||||
 | 
					  export interface SystemApiAccessLog {
 | 
				
			||||||
 | 
					    id: number;
 | 
				
			||||||
 | 
					    traceId: string;
 | 
				
			||||||
 | 
					    userId: number;
 | 
				
			||||||
 | 
					    userType: number;
 | 
				
			||||||
 | 
					    applicationName: string;
 | 
				
			||||||
 | 
					    requestMethod: string;
 | 
				
			||||||
 | 
					    requestParams: string;
 | 
				
			||||||
 | 
					    responseBody: string;
 | 
				
			||||||
 | 
					    requestUrl: string;
 | 
				
			||||||
 | 
					    userIp: string;
 | 
				
			||||||
 | 
					    userAgent: string;
 | 
				
			||||||
 | 
					    operateModule: string;
 | 
				
			||||||
 | 
					    operateName: string;
 | 
				
			||||||
 | 
					    operateType: number;
 | 
				
			||||||
 | 
					    beginTime: string;
 | 
				
			||||||
 | 
					    endTime: string;
 | 
				
			||||||
 | 
					    duration: number;
 | 
				
			||||||
 | 
					    resultCode: number;
 | 
				
			||||||
 | 
					    resultMsg: string;
 | 
				
			||||||
 | 
					    createTime: string;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 查询 API 访问日志列表 */
 | 
				
			||||||
 | 
					export function getApiAccessLogPage(params: PageParam) {
 | 
				
			||||||
 | 
					  return requestClient.get<PageResult<InfraApiAccessLogApi.SystemApiAccessLog>>(
 | 
				
			||||||
 | 
					    '/infra/api-access-log/page',
 | 
				
			||||||
 | 
					    { params }
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 导出 API 访问日志 */
 | 
				
			||||||
 | 
					export function exportApiAccessLog(params: any) {
 | 
				
			||||||
 | 
					  return requestClient.download('/infra/api-access-log/export-excel', { params });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,51 @@
 | 
				
			||||||
 | 
					import type { PageParam, PageResult } from '@vben/request';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { requestClient } from '#/api/request';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export namespace InfraApiErrorLogApi {
 | 
				
			||||||
 | 
					  /** API 错误日志信息 */
 | 
				
			||||||
 | 
					  export interface SystemApiErrorLog {
 | 
				
			||||||
 | 
					    id: number;
 | 
				
			||||||
 | 
					    traceId: string;
 | 
				
			||||||
 | 
					    userId: number;
 | 
				
			||||||
 | 
					    userType: number;
 | 
				
			||||||
 | 
					    applicationName: string;
 | 
				
			||||||
 | 
					    requestMethod: string;
 | 
				
			||||||
 | 
					    requestParams: string;
 | 
				
			||||||
 | 
					    requestUrl: string;
 | 
				
			||||||
 | 
					    userIp: string;
 | 
				
			||||||
 | 
					    userAgent: string;
 | 
				
			||||||
 | 
					    exceptionTime: string;
 | 
				
			||||||
 | 
					    exceptionName: string;
 | 
				
			||||||
 | 
					    exceptionMessage: string;
 | 
				
			||||||
 | 
					    exceptionRootCauseMessage: string;
 | 
				
			||||||
 | 
					    exceptionStackTrace: string;
 | 
				
			||||||
 | 
					    exceptionClassName: string;
 | 
				
			||||||
 | 
					    exceptionFileName: string;
 | 
				
			||||||
 | 
					    exceptionMethodName: string;
 | 
				
			||||||
 | 
					    exceptionLineNumber: number;
 | 
				
			||||||
 | 
					    processUserId: number;
 | 
				
			||||||
 | 
					    processStatus: number;
 | 
				
			||||||
 | 
					    processTime: string;
 | 
				
			||||||
 | 
					    resultCode: number;
 | 
				
			||||||
 | 
					    createTime: string;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 查询 API 错误日志列表 */
 | 
				
			||||||
 | 
					export function getApiErrorLogPage(params: PageParam) {
 | 
				
			||||||
 | 
					  return requestClient.get<PageResult<InfraApiErrorLogApi.SystemApiErrorLog>>(
 | 
				
			||||||
 | 
					    '/infra/api-error-log/page',
 | 
				
			||||||
 | 
					    { params }
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 更新 API 错误日志的处理状态 */
 | 
				
			||||||
 | 
					export function updateApiErrorLogStatus(id: number, processStatus: number) {
 | 
				
			||||||
 | 
					  return requestClient.put(`/infra/api-error-log/update-status?id=${id}&processStatus=${processStatus}`);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 导出 API 错误日志 */
 | 
				
			||||||
 | 
					export function exportApiErrorLog(params: any) {
 | 
				
			||||||
 | 
					  return requestClient.download('/infra/api-error-log/export-excel', { params });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -2,19 +2,19 @@ import { requestClient } from '#/api/request';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export namespace SystemPermissionApi {
 | 
					export namespace SystemPermissionApi {
 | 
				
			||||||
  /** 分配用户角色请求 */
 | 
					  /** 分配用户角色请求 */
 | 
				
			||||||
  export interface AssignUserRoleReqVO {
 | 
					  export interface SystemAssignUserRoleReqVO {
 | 
				
			||||||
    userId: number;
 | 
					    userId: number;
 | 
				
			||||||
    roleIds: number[];
 | 
					    roleIds: number[];
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 分配角色菜单请求 */
 | 
					  /** 分配角色菜单请求 */
 | 
				
			||||||
  export interface AssignRoleMenuReqVO {
 | 
					  export interface SystemAssignRoleMenuReqVO {
 | 
				
			||||||
    roleId: number;
 | 
					    roleId: number;
 | 
				
			||||||
    menuIds: number[];
 | 
					    menuIds: number[];
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 分配角色数据权限请求 */
 | 
					  /** 分配角色数据权限请求 */
 | 
				
			||||||
  export interface AssignRoleDataScopeReqVO {
 | 
					  export interface SystemAssignRoleDataScopeReqVO {
 | 
				
			||||||
    roleId: number;
 | 
					    roleId: number;
 | 
				
			||||||
    dataScope: number;
 | 
					    dataScope: number;
 | 
				
			||||||
    dataScopeDeptIds: number[];
 | 
					    dataScopeDeptIds: number[];
 | 
				
			||||||
| 
						 | 
					@ -30,14 +30,14 @@ export async function getRoleMenuList(roleId: number) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** 赋予角色菜单权限 */
 | 
					/** 赋予角色菜单权限 */
 | 
				
			||||||
export async function assignRoleMenu(
 | 
					export async function assignRoleMenu(
 | 
				
			||||||
  data: SystemPermissionApi.AssignRoleMenuReqVO,
 | 
					  data: SystemPermissionApi.SystemAssignRoleMenuReqVO,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  return requestClient.post('/system/permission/assign-role-menu', data);
 | 
					  return requestClient.post('/system/permission/assign-role-menu', data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** 赋予角色数据权限 */
 | 
					/** 赋予角色数据权限 */
 | 
				
			||||||
export async function assignRoleDataScope(
 | 
					export async function assignRoleDataScope(
 | 
				
			||||||
  data: SystemPermissionApi.AssignRoleDataScopeReqVO,
 | 
					  data: SystemPermissionApi.SystemAssignRoleDataScopeReqVO,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  return requestClient.post('/system/permission/assign-role-data-scope', data);
 | 
					  return requestClient.post('/system/permission/assign-role-data-scope', data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -51,7 +51,7 @@ export async function getUserRoleList(userId: number) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** 赋予用户角色 */
 | 
					/** 赋予用户角色 */
 | 
				
			||||||
export async function assignUserRole(
 | 
					export async function assignUserRole(
 | 
				
			||||||
  data: SystemPermissionApi.AssignUserRoleReqVO,
 | 
					  data: SystemPermissionApi.SystemAssignUserRoleReqVO,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
  return requestClient.post('/system/permission/assign-user-role', data);
 | 
					  return requestClient.post('/system/permission/assign-user-role', data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,175 @@
 | 
				
			||||||
 | 
					import type { VbenFormSchema } from '#/adapter/form';
 | 
				
			||||||
 | 
					import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					import type { InfraApiAccessLogApi } from '#/api/infra/api-access-log';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import {DICT_TYPE, getDictOptions} from '#/utils/dict';
 | 
				
			||||||
 | 
					import { getRangePickerDefaultProps } from '#/utils/date';
 | 
				
			||||||
 | 
					import { useAccess } from '@vben/access';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const { hasAccessByCodes } = useAccess();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 列表的搜索表单 */
 | 
				
			||||||
 | 
					export function useGridFormSchema(): VbenFormSchema[] {
 | 
				
			||||||
 | 
					  return [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'userId',
 | 
				
			||||||
 | 
					      label: '用户编号',
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请输入用户编号',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'userType',
 | 
				
			||||||
 | 
					      label: '用户类型',
 | 
				
			||||||
 | 
					      component: 'Select',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        options: getDictOptions(DICT_TYPE.USER_TYPE, 'number'),
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请选择用户类型',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'applicationName',
 | 
				
			||||||
 | 
					      label: '应用名',
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请输入应用名',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'beginTime',
 | 
				
			||||||
 | 
					      label: '请求时间',
 | 
				
			||||||
 | 
					      component: 'RangePicker',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        ...getRangePickerDefaultProps(),
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'duration',
 | 
				
			||||||
 | 
					      label: '执行时长',
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请输入执行时长',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'resultCode',
 | 
				
			||||||
 | 
					      label: '结果码',
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请输入结果码',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 列表的字段 */
 | 
				
			||||||
 | 
					export function useGridColumns<T = InfraApiAccessLogApi.SystemApiAccessLog>(
 | 
				
			||||||
 | 
					  onActionClick: OnActionClickFn<T>,
 | 
				
			||||||
 | 
					): VxeTableGridOptions['columns'] {
 | 
				
			||||||
 | 
					  return [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'id',
 | 
				
			||||||
 | 
					      title: '日志编号',
 | 
				
			||||||
 | 
					      minWidth: 100,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'userId',
 | 
				
			||||||
 | 
					      title: '用户编号',
 | 
				
			||||||
 | 
					      minWidth: 100,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'userType',
 | 
				
			||||||
 | 
					      title: '用户类型',
 | 
				
			||||||
 | 
					      minWidth: 120,
 | 
				
			||||||
 | 
					      cellRender: {
 | 
				
			||||||
 | 
					        name: 'CellDict',
 | 
				
			||||||
 | 
					        props: { type: DICT_TYPE.USER_TYPE },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'applicationName',
 | 
				
			||||||
 | 
					      title: '应用名',
 | 
				
			||||||
 | 
					      minWidth: 150,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'requestMethod',
 | 
				
			||||||
 | 
					      title: '请求方法',
 | 
				
			||||||
 | 
					      minWidth: 80,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'requestUrl',
 | 
				
			||||||
 | 
					      title: '请求地址',
 | 
				
			||||||
 | 
					      minWidth: 300,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'beginTime',
 | 
				
			||||||
 | 
					      title: '请求时间',
 | 
				
			||||||
 | 
					      minWidth: 180,
 | 
				
			||||||
 | 
					      formatter: 'formatDateTime',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'duration',
 | 
				
			||||||
 | 
					      title: '执行时长',
 | 
				
			||||||
 | 
					      minWidth: 120,
 | 
				
			||||||
 | 
					      formatter: ({ row }) => `${row.duration} ms`,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'resultCode',
 | 
				
			||||||
 | 
					      title: '操作结果',
 | 
				
			||||||
 | 
					      minWidth: 150,
 | 
				
			||||||
 | 
					      formatter: ({ row }) => {
 | 
				
			||||||
 | 
					        return row.resultCode === 0
 | 
				
			||||||
 | 
					          ? '成功'
 | 
				
			||||||
 | 
					          : `失败(${row.resultMsg})`;
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'operateModule',
 | 
				
			||||||
 | 
					      title: '操作模块',
 | 
				
			||||||
 | 
					      minWidth: 150,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'operateName',
 | 
				
			||||||
 | 
					      title: '操作名',
 | 
				
			||||||
 | 
					      minWidth: 220,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'operateType',
 | 
				
			||||||
 | 
					      title: '操作类型',
 | 
				
			||||||
 | 
					      minWidth: 120,
 | 
				
			||||||
 | 
					      cellRender: {
 | 
				
			||||||
 | 
					        name: 'CellDict',
 | 
				
			||||||
 | 
					        props: { type: DICT_TYPE.INFRA_OPERATE_TYPE },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'operation',
 | 
				
			||||||
 | 
					      title: '操作',
 | 
				
			||||||
 | 
					      minWidth: 80,
 | 
				
			||||||
 | 
					      align: 'center',
 | 
				
			||||||
 | 
					      fixed: 'right',
 | 
				
			||||||
 | 
					      cellRender: {
 | 
				
			||||||
 | 
					        attrs: {
 | 
				
			||||||
 | 
					          nameField: 'id',
 | 
				
			||||||
 | 
					          nameTitle: 'API访问日志',
 | 
				
			||||||
 | 
					          onClick: onActionClick,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        name: 'CellOperation',
 | 
				
			||||||
 | 
					        options: [
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            code: 'view',
 | 
				
			||||||
 | 
					            text: '详情',
 | 
				
			||||||
 | 
					            show: hasAccessByCodes(['infra:api-access-log:query']),
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,96 @@
 | 
				
			||||||
 | 
					<script lang="ts" setup>
 | 
				
			||||||
 | 
					import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					import type { InfraApiAccessLogApi } from '#/api/infra/api-access-log';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { Page, useVbenModal } from '@vben/common-ui';
 | 
				
			||||||
 | 
					import { Button } from 'ant-design-vue';
 | 
				
			||||||
 | 
					import { Download } from '@vben/icons';
 | 
				
			||||||
 | 
					import Detail from './modules/detail.vue';
 | 
				
			||||||
 | 
					import { DocAlert } from '#/components/doc-alert';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { $t } from '#/locales';
 | 
				
			||||||
 | 
					import { useVbenVxeGrid } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					import { exportApiAccessLog, getApiAccessLogPage } from '#/api/infra/api-access-log';
 | 
				
			||||||
 | 
					import { downloadByData } from '#/utils/download';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useGridColumns, useGridFormSchema } from './data';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [DetailModal, detailModalApi] = useVbenModal({
 | 
				
			||||||
 | 
					  connectedComponent: Detail,
 | 
				
			||||||
 | 
					  destroyOnClose: true,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 刷新表格 */
 | 
				
			||||||
 | 
					function onRefresh() {
 | 
				
			||||||
 | 
					  gridApi.query();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 导出表格 */
 | 
				
			||||||
 | 
					async function onExport() {
 | 
				
			||||||
 | 
					  const data = await exportApiAccessLog(await gridApi.formApi.getValues());
 | 
				
			||||||
 | 
					  downloadByData(data, 'API 访问日志.xls');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 查看 API 访问日志详情 */
 | 
				
			||||||
 | 
					function onView(row: InfraApiAccessLogApi.SystemApiAccessLog) {
 | 
				
			||||||
 | 
					  detailModalApi.setData(row).open();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 表格操作按钮的回调函数 */
 | 
				
			||||||
 | 
					function onActionClick({
 | 
				
			||||||
 | 
					  code,
 | 
				
			||||||
 | 
					  row,
 | 
				
			||||||
 | 
					}: OnActionClickParams<InfraApiAccessLogApi.SystemApiAccessLog>) {
 | 
				
			||||||
 | 
					  switch (code) {
 | 
				
			||||||
 | 
					    case 'view': {
 | 
				
			||||||
 | 
					      onView(row);
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [Grid, gridApi] = useVbenVxeGrid({
 | 
				
			||||||
 | 
					  formOptions: {
 | 
				
			||||||
 | 
					    schema: useGridFormSchema(),
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  gridOptions: {
 | 
				
			||||||
 | 
					    columns: useGridColumns(onActionClick),
 | 
				
			||||||
 | 
					    height: 'auto',
 | 
				
			||||||
 | 
					    keepSource: true,
 | 
				
			||||||
 | 
					    proxyConfig: {
 | 
				
			||||||
 | 
					      ajax: {
 | 
				
			||||||
 | 
					        query: async ({ page }, formValues) => {
 | 
				
			||||||
 | 
					          return await getApiAccessLogPage({
 | 
				
			||||||
 | 
					            pageNo: page.currentPage,
 | 
				
			||||||
 | 
					            pageSize: page.pageSize,
 | 
				
			||||||
 | 
					            ...formValues,
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    rowConfig: {
 | 
				
			||||||
 | 
					      keyField: 'id',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    toolbarConfig: {
 | 
				
			||||||
 | 
					      refresh: { code: 'query' },
 | 
				
			||||||
 | 
					      search: true,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  } as VxeTableGridOptions<InfraApiAccessLogApi.SystemApiAccessLog>,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <Page auto-content-height>
 | 
				
			||||||
 | 
					    <DocAlert title="系统日志" url="https://doc.iocoder.cn/system-log/" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <DetailModal @success="onRefresh" />
 | 
				
			||||||
 | 
					    <Grid table-title="API 访问日志列表">
 | 
				
			||||||
 | 
					      <template #toolbar-tools>
 | 
				
			||||||
 | 
					        <Button type="primary" class="ml-2" @click="onExport" v-access:code="['infra:api-access-log:export']">
 | 
				
			||||||
 | 
					          <Download class="size-5" />
 | 
				
			||||||
 | 
					          {{ $t('ui.actionTitle.export') }}
 | 
				
			||||||
 | 
					        </Button>
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					    </Grid>
 | 
				
			||||||
 | 
					  </Page>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,86 @@
 | 
				
			||||||
 | 
					<script lang="ts" setup>
 | 
				
			||||||
 | 
					import type { InfraApiAccessLogApi } from '#/api/infra/api-access-log';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useVbenModal } from '@vben/common-ui';
 | 
				
			||||||
 | 
					import { Descriptions } from 'ant-design-vue';
 | 
				
			||||||
 | 
					import { DictTag } from '#/components/dict-tag';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { ref } from 'vue';
 | 
				
			||||||
 | 
					import { formatDateTime } from '@vben/utils';
 | 
				
			||||||
 | 
					import { DICT_TYPE } from '#/utils/dict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const formData = ref<InfraApiAccessLogApi.SystemApiAccessLog>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [Modal, modalApi] = useVbenModal({
 | 
				
			||||||
 | 
					  async onOpenChange(isOpen: boolean) {
 | 
				
			||||||
 | 
					    if (!isOpen) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // 加载数据
 | 
				
			||||||
 | 
					    const data = modalApi.getData<InfraApiAccessLogApi.SystemApiAccessLog>();
 | 
				
			||||||
 | 
					    if (!data || !data.id) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    modalApi.lock();
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      formData.value = data;
 | 
				
			||||||
 | 
					    } finally {
 | 
				
			||||||
 | 
					      modalApi.lock(false);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <Modal title="API 访问日志详情" class="w-1/2" :show-cancel-button="false" :show-confirm-button="false">
 | 
				
			||||||
 | 
					    <Descriptions bordered :column="1" size="middle" class="mx-4" :label-style="{ width: '110px' }">
 | 
				
			||||||
 | 
					      <Descriptions.Item label="日志编号">
 | 
				
			||||||
 | 
					        {{ formData?.id }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="链路追踪">
 | 
				
			||||||
 | 
					        {{ formData?.traceId }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="应用名">
 | 
				
			||||||
 | 
					        {{ formData?.applicationName }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="用户信息">
 | 
				
			||||||
 | 
					        {{ formData?.userId }}
 | 
				
			||||||
 | 
					        <DictTag :type="DICT_TYPE.USER_TYPE" :value="formData?.userType" />
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="用户IP">
 | 
				
			||||||
 | 
					        {{ formData?.userIp }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="用户UA">
 | 
				
			||||||
 | 
					        {{ formData?.userAgent }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="请求信息">
 | 
				
			||||||
 | 
					        {{ formData?.requestMethod }} {{ formData?.requestUrl }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="请求参数">
 | 
				
			||||||
 | 
					        {{ formData?.requestParams }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="请求结果">
 | 
				
			||||||
 | 
					        {{ formData?.responseBody }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="请求时间">
 | 
				
			||||||
 | 
					        {{ formatDateTime(formData?.beginTime || '') }} ~ {{ formatDateTime(formData?.endTime || '') }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="请求耗时">{{ formData?.duration }} ms</Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="操作结果">
 | 
				
			||||||
 | 
					        <div v-if="formData?.resultCode === 0">正常</div>
 | 
				
			||||||
 | 
					        <div v-else-if="formData?.resultCode > 0">
 | 
				
			||||||
 | 
					          失败 | {{ formData?.resultCode }} | {{ formData?.resultMsg }}
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="操作模块">
 | 
				
			||||||
 | 
					        {{ formData?.operateModule }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="操作名">
 | 
				
			||||||
 | 
					        {{ formData?.operateName }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="操作类型">
 | 
				
			||||||
 | 
					        <DictTag :type="DICT_TYPE.INFRA_OPERATE_TYPE" :value="formData?.operateType" />
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					    </Descriptions>
 | 
				
			||||||
 | 
					  </Modal>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,164 @@
 | 
				
			||||||
 | 
					import type { VbenFormSchema } from '#/adapter/form';
 | 
				
			||||||
 | 
					import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					import type { InfraApiErrorLogApi } from '#/api/infra/api-error-log';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import {DICT_TYPE, getDictOptions} from '#/utils/dict';
 | 
				
			||||||
 | 
					import { getRangePickerDefaultProps } from '#/utils/date';
 | 
				
			||||||
 | 
					import { useAccess } from '@vben/access';
 | 
				
			||||||
 | 
					import { InfraApiErrorLogProcessStatusEnum } from '#/utils/constants';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const { hasAccessByCodes } = useAccess();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 列表的搜索表单 */
 | 
				
			||||||
 | 
					export function useGridFormSchema(): VbenFormSchema[] {
 | 
				
			||||||
 | 
					  return [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'userId',
 | 
				
			||||||
 | 
					      label: '用户编号',
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请输入用户编号',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'userType',
 | 
				
			||||||
 | 
					      label: '用户类型',
 | 
				
			||||||
 | 
					      component: 'Select',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        options: getDictOptions(DICT_TYPE.USER_TYPE, 'number'),
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请选择用户类型',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'applicationName',
 | 
				
			||||||
 | 
					      label: '应用名',
 | 
				
			||||||
 | 
					      component: 'Input',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请输入应用名',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'exceptionTime',
 | 
				
			||||||
 | 
					      label: '异常时间',
 | 
				
			||||||
 | 
					      component: 'RangePicker',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        ...getRangePickerDefaultProps(),
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      fieldName: 'processStatus',
 | 
				
			||||||
 | 
					      label: '处理状态',
 | 
				
			||||||
 | 
					      component: 'Select',
 | 
				
			||||||
 | 
					      componentProps: {
 | 
				
			||||||
 | 
					        options: getDictOptions(DICT_TYPE.INFRA_API_ERROR_LOG_PROCESS_STATUS, 'number'),
 | 
				
			||||||
 | 
					        allowClear: true,
 | 
				
			||||||
 | 
					        placeholder: '请选择处理状态',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      defaultValue: InfraApiErrorLogProcessStatusEnum.INIT,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 列表的字段 */
 | 
				
			||||||
 | 
					export function useGridColumns<T = InfraApiErrorLogApi.SystemApiErrorLog>(
 | 
				
			||||||
 | 
					  onActionClick: OnActionClickFn<T>,
 | 
				
			||||||
 | 
					): VxeTableGridOptions['columns'] {
 | 
				
			||||||
 | 
					  return [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'id',
 | 
				
			||||||
 | 
					      title: '日志编号',
 | 
				
			||||||
 | 
					      minWidth: 100,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'userId',
 | 
				
			||||||
 | 
					      title: '用户编号',
 | 
				
			||||||
 | 
					      minWidth: 100,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'userType',
 | 
				
			||||||
 | 
					      title: '用户类型',
 | 
				
			||||||
 | 
					      minWidth: 120,
 | 
				
			||||||
 | 
					      cellRender: {
 | 
				
			||||||
 | 
					        name: 'CellDict',
 | 
				
			||||||
 | 
					        props: { type: DICT_TYPE.USER_TYPE },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'applicationName',
 | 
				
			||||||
 | 
					      title: '应用名',
 | 
				
			||||||
 | 
					      minWidth: 150,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'requestMethod',
 | 
				
			||||||
 | 
					      title: '请求方法',
 | 
				
			||||||
 | 
					      minWidth: 80,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'requestUrl',
 | 
				
			||||||
 | 
					      title: '请求地址',
 | 
				
			||||||
 | 
					      minWidth: 200,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'exceptionTime',
 | 
				
			||||||
 | 
					      title: '异常发生时间',
 | 
				
			||||||
 | 
					      minWidth: 180,
 | 
				
			||||||
 | 
					      formatter: 'formatDateTime',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'exceptionName',
 | 
				
			||||||
 | 
					      title: '异常名',
 | 
				
			||||||
 | 
					      minWidth: 180,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'processStatus',
 | 
				
			||||||
 | 
					      title: '处理状态',
 | 
				
			||||||
 | 
					      minWidth: 120,
 | 
				
			||||||
 | 
					      cellRender: {
 | 
				
			||||||
 | 
					        name: 'CellDict',
 | 
				
			||||||
 | 
					        props: { type: DICT_TYPE.INFRA_API_ERROR_LOG_PROCESS_STATUS },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      field: 'operation',
 | 
				
			||||||
 | 
					      title: '操作',
 | 
				
			||||||
 | 
					      minWidth: 200,
 | 
				
			||||||
 | 
					      align: 'center',
 | 
				
			||||||
 | 
					      fixed: 'right',
 | 
				
			||||||
 | 
					      cellRender: {
 | 
				
			||||||
 | 
					        attrs: {
 | 
				
			||||||
 | 
					          nameField: 'id',
 | 
				
			||||||
 | 
					          nameTitle: 'API错误日志',
 | 
				
			||||||
 | 
					          onClick: onActionClick,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        name: 'CellOperation',
 | 
				
			||||||
 | 
					        options: [
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            code: 'view',
 | 
				
			||||||
 | 
					            text: '详情',
 | 
				
			||||||
 | 
					            show: hasAccessByCodes(['infra:api-error-log:query']),
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            code: 'done',
 | 
				
			||||||
 | 
					            text: '已处理',
 | 
				
			||||||
 | 
					            show: (row: InfraApiErrorLogApi.SystemApiErrorLog) => {
 | 
				
			||||||
 | 
					              return row.processStatus === InfraApiErrorLogProcessStatusEnum.INIT &&
 | 
				
			||||||
 | 
					                hasAccessByCodes(['infra:api-error-log:update-status']);
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            code: 'ignore',
 | 
				
			||||||
 | 
					            text: '已忽略',
 | 
				
			||||||
 | 
					            show: (row: InfraApiErrorLogApi.SystemApiErrorLog) => {
 | 
				
			||||||
 | 
					              return row.processStatus === InfraApiErrorLogProcessStatusEnum.INIT &&
 | 
				
			||||||
 | 
					                hasAccessByCodes(['infra:api-error-log:update-status']);
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,122 @@
 | 
				
			||||||
 | 
					<script lang="ts" setup>
 | 
				
			||||||
 | 
					import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					import type { InfraApiErrorLogApi } from '#/api/infra/api-error-log';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { Page, useVbenModal } from '@vben/common-ui';
 | 
				
			||||||
 | 
					import {Button, message, Modal} from 'ant-design-vue';
 | 
				
			||||||
 | 
					import { Download } from '@vben/icons';
 | 
				
			||||||
 | 
					import Detail from './modules/detail.vue';
 | 
				
			||||||
 | 
					import { DocAlert } from '#/components/doc-alert';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { $t } from '#/locales';
 | 
				
			||||||
 | 
					import { useVbenVxeGrid } from '#/adapter/vxe-table';
 | 
				
			||||||
 | 
					import { exportApiErrorLog, getApiErrorLogPage, updateApiErrorLogStatus } from '#/api/infra/api-error-log';
 | 
				
			||||||
 | 
					import { downloadByData } from '#/utils/download';
 | 
				
			||||||
 | 
					import { InfraApiErrorLogProcessStatusEnum } from '#/utils/constants';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useGridColumns, useGridFormSchema } from './data';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [DetailModal, detailModalApi] = useVbenModal({
 | 
				
			||||||
 | 
					  connectedComponent: Detail,
 | 
				
			||||||
 | 
					  destroyOnClose: true,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 刷新表格 */
 | 
				
			||||||
 | 
					function onRefresh() {
 | 
				
			||||||
 | 
					  gridApi.query();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 导出表格 */
 | 
				
			||||||
 | 
					async function onExport() {
 | 
				
			||||||
 | 
					  const data = await exportApiErrorLog(await gridApi.formApi.getValues());
 | 
				
			||||||
 | 
					  downloadByData(data, 'API 错误日志.xls');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 查看 API 错误日志详情 */
 | 
				
			||||||
 | 
					function onView(row: InfraApiErrorLogApi.SystemApiErrorLog) {
 | 
				
			||||||
 | 
					  detailModalApi.setData(row).open();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 处理已处理 / 已忽略的操作 */
 | 
				
			||||||
 | 
					async function onProcess(id: number, processStatus: number) {
 | 
				
			||||||
 | 
					  Modal.confirm({
 | 
				
			||||||
 | 
					    title: '确认操作',
 | 
				
			||||||
 | 
					    content: `确认标记为${InfraApiErrorLogProcessStatusEnum.DONE ? '已处理' : '已忽略'}?`,
 | 
				
			||||||
 | 
					    onOk: async () => {
 | 
				
			||||||
 | 
					      await updateApiErrorLogStatus(id, processStatus);
 | 
				
			||||||
 | 
					      // 关闭并提示
 | 
				
			||||||
 | 
					      message.success({
 | 
				
			||||||
 | 
					        content: $t('ui.actionMessage.operationSuccess'),
 | 
				
			||||||
 | 
					        key: 'action_process_msg',
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					      await onRefresh();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 表格操作按钮的回调函数 */
 | 
				
			||||||
 | 
					function onActionClick({
 | 
				
			||||||
 | 
					  code,
 | 
				
			||||||
 | 
					  row,
 | 
				
			||||||
 | 
					}: OnActionClickParams<InfraApiErrorLogApi.SystemApiErrorLog>) {
 | 
				
			||||||
 | 
					  switch (code) {
 | 
				
			||||||
 | 
					    case 'view': {
 | 
				
			||||||
 | 
					      onView(row);
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    case 'done': {
 | 
				
			||||||
 | 
					      onProcess(row.id, InfraApiErrorLogProcessStatusEnum.DONE);
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    case 'ignore': {
 | 
				
			||||||
 | 
					      onProcess(row.id, InfraApiErrorLogProcessStatusEnum.IGNORE);
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [Grid, gridApi] = useVbenVxeGrid({
 | 
				
			||||||
 | 
					  formOptions: {
 | 
				
			||||||
 | 
					    schema: useGridFormSchema(),
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  gridOptions: {
 | 
				
			||||||
 | 
					    columns: useGridColumns(onActionClick),
 | 
				
			||||||
 | 
					    height: 'auto',
 | 
				
			||||||
 | 
					    keepSource: true,
 | 
				
			||||||
 | 
					    proxyConfig: {
 | 
				
			||||||
 | 
					      ajax: {
 | 
				
			||||||
 | 
					        query: async ({ page }, formValues) => {
 | 
				
			||||||
 | 
					          return await getApiErrorLogPage({
 | 
				
			||||||
 | 
					            pageNo: page.currentPage,
 | 
				
			||||||
 | 
					            pageSize: page.pageSize,
 | 
				
			||||||
 | 
					            ...formValues,
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    rowConfig: {
 | 
				
			||||||
 | 
					      keyField: 'id',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    toolbarConfig: {
 | 
				
			||||||
 | 
					      refresh: { code: 'query' },
 | 
				
			||||||
 | 
					      search: true,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  } as VxeTableGridOptions<InfraApiErrorLogApi.SystemApiErrorLog>,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <Page auto-content-height>
 | 
				
			||||||
 | 
					    <DocAlert title="系统日志" url="https://doc.iocoder.cn/system-log/" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <DetailModal @success="onRefresh" />
 | 
				
			||||||
 | 
					    <Grid table-title="API 错误日志列表">
 | 
				
			||||||
 | 
					      <template #toolbar-tools>
 | 
				
			||||||
 | 
					        <Button type="primary" class="ml-2" @click="onExport" v-access:code="['infra:api-error-log:export']">
 | 
				
			||||||
 | 
					          <Download class="size-5" />
 | 
				
			||||||
 | 
					          {{ $t('ui.actionTitle.export') }}
 | 
				
			||||||
 | 
					        </Button>
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
 | 
					    </Grid>
 | 
				
			||||||
 | 
					  </Page>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,89 @@
 | 
				
			||||||
 | 
					<script lang="ts" setup>
 | 
				
			||||||
 | 
					import type { InfraApiErrorLogApi } from '#/api/infra/api-error-log';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { useVbenModal } from '@vben/common-ui';
 | 
				
			||||||
 | 
					import { Descriptions, Input } from 'ant-design-vue';
 | 
				
			||||||
 | 
					import { DictTag } from '#/components/dict-tag';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { ref } from 'vue';
 | 
				
			||||||
 | 
					import { formatDateTime } from '@vben/utils';
 | 
				
			||||||
 | 
					import { DICT_TYPE } from '#/utils/dict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const formData = ref<InfraApiErrorLogApi.SystemApiErrorLog>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const [Modal, modalApi] = useVbenModal({
 | 
				
			||||||
 | 
					  async onOpenChange(isOpen: boolean) {
 | 
				
			||||||
 | 
					    if (!isOpen) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // 加载数据
 | 
				
			||||||
 | 
					    const data = modalApi.getData<InfraApiErrorLogApi.SystemApiErrorLog>();
 | 
				
			||||||
 | 
					    if (!data || !data.id) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    modalApi.lock();
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      formData.value = data;
 | 
				
			||||||
 | 
					    } finally {
 | 
				
			||||||
 | 
					      modalApi.lock(false);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <Modal title="API错误日志详情" class="w-1/2" :show-cancel-button="false" :show-confirm-button="false">
 | 
				
			||||||
 | 
					    <Descriptions bordered :column="1" size="middle" class="mx-4" :label-style="{ width: '110px' }">
 | 
				
			||||||
 | 
					      <Descriptions.Item label="日志编号">
 | 
				
			||||||
 | 
					        {{ formData?.id }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="链路追踪">
 | 
				
			||||||
 | 
					        {{ formData?.traceId }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="应用名">
 | 
				
			||||||
 | 
					        {{ formData?.applicationName }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="用户编号">
 | 
				
			||||||
 | 
					        {{ formData?.userId }}
 | 
				
			||||||
 | 
					        <DictTag :type="DICT_TYPE.USER_TYPE" :value="formData?.userType" />
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="用户IP">
 | 
				
			||||||
 | 
					        {{ formData?.userIp }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="用户UA">
 | 
				
			||||||
 | 
					        {{ formData?.userAgent }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="请求信息">
 | 
				
			||||||
 | 
					        {{ formData?.requestMethod }} {{ formData?.requestUrl }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="请求参数">
 | 
				
			||||||
 | 
					        {{ formData?.requestParams }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="异常时间">
 | 
				
			||||||
 | 
					        {{ formatDateTime(formData?.exceptionTime || '') }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="异常名">
 | 
				
			||||||
 | 
					        {{ formData?.exceptionName }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item v-if="formData?.exceptionStackTrace" label="异常堆栈">
 | 
				
			||||||
 | 
					        <Input.TextArea
 | 
				
			||||||
 | 
					          :value="formData?.exceptionStackTrace"
 | 
				
			||||||
 | 
					          :autoSize="{ maxRows: 20 }"
 | 
				
			||||||
 | 
					          readonly
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item label="处理状态">
 | 
				
			||||||
 | 
					        <DictTag
 | 
				
			||||||
 | 
					          :type="DICT_TYPE.INFRA_API_ERROR_LOG_PROCESS_STATUS"
 | 
				
			||||||
 | 
					          :value="formData?.processStatus"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item v-if="formData?.processUserId" label="处理人">
 | 
				
			||||||
 | 
					        {{ formData?.processUserId }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					      <Descriptions.Item v-if="formData?.processTime" label="处理时间">
 | 
				
			||||||
 | 
					        {{ formatDateTime(formData?.processTime || '') }}
 | 
				
			||||||
 | 
					      </Descriptions.Item>
 | 
				
			||||||
 | 
					    </Descriptions>
 | 
				
			||||||
 | 
					  </Modal>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
		Loading…
	
		Reference in New Issue