import React, { useState, useRef, useEffect } from 'react'; import { useIntl, FormattedMessage, useAccess } from '@umijs/max'; import type { FormInstance } from 'antd'; import { Button, message, Modal } from 'antd'; import { ActionType, FooterToolbar, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components'; import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { getOperlogList, removeOperlog, addOperlog, updateOperlog, cleanAllOperlog, exportOperlog } from '@/services/monitor/operlog'; import UpdateForm from './detail'; import { getDictValueEnum } from '@/services/system/dict'; import DictTag from '@/components/DictTag'; /** * 添加节点 * * @param fields */ const handleAdd = async (fields: API.Monitor.Operlog) => { const hide = message.loading('正在添加'); try { const resp = await addOperlog({ ...fields }); hide(); if (resp.code === 200) { message.success('添加成功'); } else { message.error(resp.msg); } return true; } catch (error) { hide(); message.error('添加失败请重试!'); return false; } }; /** * 更新节点 * * @param fields */ const handleUpdate = async (fields: API.Monitor.Operlog) => { const hide = message.loading('正在更新'); try { const resp = await updateOperlog(fields); hide(); if (resp.code === 200) { message.success('更新成功'); } else { message.error(resp.msg); } return true; } catch (error) { hide(); message.error('配置失败请重试!'); return false; } }; /** * 删除节点 * * @param selectedRows */ const handleRemove = async (selectedRows: API.Monitor.Operlog[]) => { const hide = message.loading('正在删除'); if (!selectedRows) return true; try { const resp = await removeOperlog(selectedRows.map((row) => row.operId).join(',')); hide(); if (resp.code === 200) { message.success('删除成功,即将刷新'); } else { message.error(resp.msg); } return true; } catch (error) { hide(); message.error('删除失败,请重试'); return false; } }; /** * 清空所有记录 * */ const handleCleanAll = async () => { const hide = message.loading('正在清空'); try { const resp = await cleanAllOperlog(); hide(); if (resp.code === 200) { message.success('清空成功,即将刷新'); } else { message.error(resp.msg); } return true; } catch (error) { hide(); message.error('清空失败,请重试'); return false; } }; /** * 导出数据 * * */ const handleExport = async () => { const hide = message.loading('正在导出'); try { await exportOperlog(); hide(); message.success('导出成功'); return true; } catch (error) { hide(); message.error('导出失败,请重试'); return false; } }; const OperlogTableList: React.FC = () => { const formTableRef = useRef(); const [modalVisible, setModalVisible] = useState(false); const actionRef = useRef(); const [currentRow, setCurrentRow] = useState(); const [selectedRows, setSelectedRows] = useState([]); const [businessTypeOptions, setBusinessTypeOptions] = useState([]); const [operatorTypeOptions, setOperatorTypeOptions] = useState([]); const [statusOptions, setStatusOptions] = useState([]); const access = useAccess(); /** 国际化配置 */ const intl = useIntl(); useEffect(() => { getDictValueEnum('sys_oper_type', true).then((data) => { setBusinessTypeOptions(data); }); getDictValueEnum('sys_oper_type', true).then((data) => { setOperatorTypeOptions(data); }); getDictValueEnum('sys_common_status', true).then((data) => { setStatusOptions(data); }); }, []); const columns: ProColumns[] = [ { title: , dataIndex: 'operId', valueType: 'text', hideInSearch: true, }, { title: , dataIndex: 'title', valueType: 'text', }, { title: , dataIndex: 'businessType', valueType: 'select', valueEnum: businessTypeOptions, render: (_, record) => { return (); }, }, { title: , dataIndex: 'requestMethod', valueType: 'text', }, { title: , dataIndex: 'operatorType', valueType: 'select', valueEnum: operatorTypeOptions, render: (_, record) => { return (); }, }, { title: , dataIndex: 'operName', valueType: 'text', }, { title: , dataIndex: 'operIp', valueType: 'text', }, { title: , dataIndex: 'operLocation', valueType: 'text', }, { title: , dataIndex: 'status', valueType: 'select', valueEnum: statusOptions, render: (_, record) => { return (); }, }, { title: , dataIndex: 'operTime', valueType: 'dateTime', }, { title: , dataIndex: 'option', width: '120px', valueType: 'option', render: (_, record) => [ , ], }, ]; return (
headerTitle={intl.formatMessage({ id: 'pages.searchTable.title', defaultMessage: '信息', })} actionRef={actionRef} formRef={formTableRef} rowKey="operId" key="operlogList" search={{ labelWidth: 120, }} toolBarRender={() => [ , , , , ]} request={(params) => getOperlogList({ ...params } as API.Monitor.OperlogListParams).then((res) => { const result = { data: res.rows, total: res.total, success: true, }; return result; }) } columns={columns} rowSelection={{ onChange: (_, selectedRows) => { setSelectedRows(selectedRows); }, }} />
{selectedRows?.length > 0 && ( {selectedRows.length} } > )} { let success = false; if (values.operId) { success = await handleUpdate({ ...values } as API.Monitor.Operlog); } else { success = await handleAdd({ ...values } as API.Monitor.Operlog); } if (success) { setModalVisible(false); setCurrentRow(undefined); if (actionRef.current) { actionRef.current.reload(); } } }} onCancel={() => { setModalVisible(false); setCurrentRow(undefined); }} open={modalVisible} values={currentRow || {}} businessTypeOptions={businessTypeOptions} operatorTypeOptions={operatorTypeOptions} statusOptions={statusOptions} />
); }; export default OperlogTableList;