diff --git a/src/components/DictTag/index.tsx b/src/components/DictTag/index.tsx index 2b2a791..dfbbc3f 100644 --- a/src/components/DictTag/index.tsx +++ b/src/components/DictTag/index.tsx @@ -59,7 +59,7 @@ const DictTag: React.FC = (props) => { return ''; } if (props.enums) { - const item = props.enums[value]; + const item = props.enums[value] || {}; return item.label; } if (props.options) { @@ -81,7 +81,7 @@ const DictTag: React.FC = (props) => { return 'default'; } if (props.enums) { - const item = props.enums[value]; + const item = props.enums[value] || {}; return item.listClass || 'default'; } if (props.options) { @@ -112,4 +112,4 @@ const DictTag: React.FC = (props) => { } -export default DictTag; \ No newline at end of file +export default DictTag; diff --git a/src/pages/Monitor/Mobilelog/detail.tsx b/src/pages/Monitor/Mobilelog/detail.tsx new file mode 100644 index 0000000..2c6e4a6 --- /dev/null +++ b/src/pages/Monitor/Mobilelog/detail.tsx @@ -0,0 +1,113 @@ +import React from 'react'; +import { Descriptions, Modal } from 'antd'; +import { useIntl, FormattedMessage } from '@umijs/max'; +import { DictValueEnumObj } from '@/components/DictTag'; +import { getValueEnumLabel } from '@/utils/options'; + +export type MobilelogFormData = Record & Partial; + +export type MobilelogFormProps = { + onCancel: (flag?: boolean, formVals?: MobilelogFormData) => void; + onSubmit: (values: MobilelogFormData) => Promise; + open: boolean; + values: Partial; + businessTypeOptions: DictValueEnumObj; + operatorTypeOptions: DictValueEnumObj; + statusOptions: DictValueEnumObj; +}; + +const OperlogDetailForm: React.FC = (props) => { + + const { values, businessTypeOptions, operatorTypeOptions, statusOptions, } = props; + + const intl = useIntl(); + const handleOk = () => {}; + const handleCancel = () => { + props.onCancel(); + }; + + return ( + + + } + > + {`${values.title}/${getValueEnumLabel(businessTypeOptions, values.businessType)}`} + + } + > + {values.requestMethod} + + } + > + {`${values.operName}/${values.operIp}`} + + } + > + {getValueEnumLabel(operatorTypeOptions, values.operatorType)} + + } + > + {values.method} + + } + > + {values.operUrl} + + } + > + {values.operParam} + + } + > + {values.jsonResult} + + } + > + {values.errorMsg} + + } + > + {getValueEnumLabel(statusOptions, values.status)} + + } + > + {values.operTime?.toString()} + + + + ); +}; + +export default OperlogDetailForm; diff --git a/src/pages/Monitor/Mobilelog/index.tsx b/src/pages/Monitor/Mobilelog/index.tsx new file mode 100644 index 0000000..c771c6a --- /dev/null +++ b/src/pages/Monitor/Mobilelog/index.tsx @@ -0,0 +1,304 @@ +import React, { useState, useRef, useEffect, useMemo } from 'react'; +import {addMobilelog, getMobileLogList, removeMobilelog, updateMobilelog} from "@/services/monitor/mobilelog"; +import { ActionType, FooterToolbar, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components'; +import { useIntl, FormattedMessage, useAccess } from '@umijs/max'; +import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; +import { Button, message, Modal } from 'antd'; +import DictTag from "@/components/DictTag"; +import {getDictValueEnum} from "@/services/system/dict"; +import UpdateForm from './detail'; +import {addOperlog, removeOperlog, updateOperlog} from "@/services/monitor/operlog"; +/** + * 添加节点 + * + * @param fields + */ +const handleAdd = async (fields: API.Monitor.Operlog) => { + const hide = message.loading('正在添加'); + try { + const resp = await addMobilelog({ ...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 updateMobilelog(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 removeMobilelog(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 MobileLog: React.FC = () => { + // ref + const formTableRef = useRef(); + const access = useAccess(); + const actionRef = useRef(); + // status + const [params, useParams] = useState({}) + const [modalVisible, setModalVisible] = useState(false); + const [currentRow, setCurrentRow] = useState(); + const [selectedRows, setSelectedRows] = useState([]); + // 枚举 + const [businessTypeOptions, setBusinessTypeOptions] = useState([]); + const [operatorTypeOptions, setOperatorTypeOptions] = useState([]); + const [statusOptions, setStatusOptions] = useState([]); + + // 初始化 + 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[] = useMemo(() => [ + { + 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) => [ + , + ], + }, + ], [businessTypeOptions, operatorTypeOptions, statusOptions]) + + return <> + +
+ { + setSelectedRows(selectedRows); + }, + }} + request={(params) => + getMobileLogList({ ...params } as API.Monitor.MobilelogListParams).then((res) => { + const result = { + data: res.rows, + total: res.total, + success: true, + }; + return result; + }) + } + toolBarRender={() => [ + // , + , + , + ]} + /> +
+ { + let success = false; + if (values.operId) { + success = await handleUpdate({ ...values } as API.Monitor.Mobilelog); + } else { + success = await handleAdd({ ...values } as API.Monitor.Mobilelog); + } + 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 MobileLog diff --git a/src/pages/Monitor/Operlog/index.tsx b/src/pages/Monitor/Operlog/index.tsx index 9440bc8..179daa7 100644 --- a/src/pages/Monitor/Operlog/index.tsx +++ b/src/pages/Monitor/Operlog/index.tsx @@ -233,17 +233,17 @@ const OperlogTableList: React.FC = () => { labelWidth: 120, }} toolBarRender={() => [ - , + // ,