/** * 操作记录页面 * 与 GVA sysOperationRecord.vue 保持一致的功能 */ import { DeleteOutlined, SearchOutlined, ReloadOutlined } from '@ant-design/icons'; import { PageContainer, ProTable } from '@ant-design/pro-components'; import type { ProColumns, ActionType } from '@ant-design/pro-components'; import { Button, message, Popconfirm, Space, Tag, Popover, Typography } from 'antd'; import { useRef, useState } from 'react'; import { getSysOperationRecordList, deleteSysOperationRecord, deleteSysOperationRecordByIds, } from '@/services/system/operationRecord'; import dayjs from 'dayjs'; const { Text } = Typography; const OperationRecordPage: React.FC = () => { const actionRef = useRef(); const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 格式化JSON显示 const formatBody = (value: string) => { try { return JSON.stringify(JSON.parse(value), null, 2); } catch { return value; } }; // 删除单条记录 const handleDelete = async (id: number) => { const res = await deleteSysOperationRecord({ ID: id }); if (res.code === 0) { message.success('删除成功'); actionRef.current?.reload(); } }; // 批量删除 const handleBatchDelete = async () => { if (selectedRowKeys.length === 0) { message.warning('请选择要删除的记录'); return; } const res = await deleteSysOperationRecordByIds({ ids: selectedRowKeys }); if (res.code === 0) { message.success('删除成功'); setSelectedRowKeys([]); actionRef.current?.reload(); } }; const columns: ProColumns[] = [ { title: '操作人', dataIndex: ['user', 'userName'], width: 140, search: false, render: (_, record) => ( {record.user?.userName}({record.user?.nickName}) ), }, { title: '日期', dataIndex: 'CreatedAt', width: 180, search: false, render: (_, record) => dayjs(record.CreatedAt).format('YYYY-MM-DD HH:mm:ss'), }, { title: '状态码', dataIndex: 'status', width: 100, render: (_, record) => {record.status}, }, { title: '请求IP', dataIndex: 'ip', width: 120, search: false, }, { title: '请求方法', dataIndex: 'method', width: 100, }, { title: '请求路径', dataIndex: 'path', width: 240, ellipsis: true, }, { title: '请求', dataIndex: 'body', width: 80, search: false, render: (_, record) => ( record.body ? (
{formatBody(record.body)}
} trigger="click" >
) : ), }, { title: '响应', dataIndex: 'resp', width: 80, search: false, render: (_, record) => ( record.resp ? (
{formatBody(record.resp)}
} trigger="click" >
) : ), }, { title: '操作', valueType: 'option', width: 100, render: (_, record) => ( handleDelete(record.ID!)}> ), }, ]; return ( headerTitle="操作记录" actionRef={actionRef} rowKey="ID" columns={columns} rowSelection={{ selectedRowKeys, onChange: (keys) => setSelectedRowKeys(keys as number[]), }} toolBarRender={() => [ , ]} request={async (params) => { const res = await getSysOperationRecordList({ page: params.current, pageSize: params.pageSize, method: params.method, path: params.path, status: params.status ? Number(params.status) : undefined, }); return { data: res.data?.list || [], total: res.data?.total || 0, success: res.code === 0, }; }} pagination={{ defaultPageSize: 10, showSizeChanger: true, pageSizeOptions: ['10', '30', '50', '100'], }} /> ); }; export default OperationRecordPage;