|
@@ -1,84 +1,84 @@
|
|
|
-import { PlusOutlined } from '@ant-design/icons';
|
|
|
-import { Button, Divider, message, Input, Drawer } from 'antd';
|
|
|
-import React, { useState, useRef } from 'react';
|
|
|
-import { PageContainer, FooterToolbar } from '@ant-design/pro-layout';
|
|
|
-import ProTable from '@ant-design/pro-table';
|
|
|
-import ProDescriptions from '@ant-design/pro-descriptions';
|
|
|
-import CreateForm from './components/CreateForm';
|
|
|
-import UpdateForm from './components/UpdateForm';
|
|
|
-import { queryRule, updateRule, addRule, removeRule } from './service';
|
|
|
+import { PlusOutlined } from '@ant-design/icons'
|
|
|
+import { Button, Divider, message, Input, Drawer } from 'antd'
|
|
|
+import React, { useState, useRef } from 'react'
|
|
|
+import { PageContainer, FooterToolbar } from '@ant-design/pro-layout'
|
|
|
+import ProTable from '@ant-design/pro-table'
|
|
|
+import ProDescriptions from '@ant-design/pro-descriptions'
|
|
|
+import CreateForm from './components/CreateForm'
|
|
|
+import UpdateForm from './components/UpdateForm'
|
|
|
+import { queryRule, updateRule, addRule, removeRule } from './service'
|
|
|
/**
|
|
|
* 添加节点
|
|
|
* @param fields
|
|
|
*/
|
|
|
|
|
|
-const handleAdd = async (fields) => {
|
|
|
- const hide = message.loading('正在添加');
|
|
|
+const handleAdd = async fields => {
|
|
|
+ const hide = message.loading('正在添加')
|
|
|
|
|
|
try {
|
|
|
- await addRule({ ...fields });
|
|
|
- hide();
|
|
|
- message.success('添加成功');
|
|
|
- return true;
|
|
|
+ await addRule({ ...fields })
|
|
|
+ hide()
|
|
|
+ message.success('添加成功')
|
|
|
+ return true
|
|
|
} catch (error) {
|
|
|
- hide();
|
|
|
- message.error('添加失败请重试!');
|
|
|
- return false;
|
|
|
+ hide()
|
|
|
+ message.error('添加失败请重试!')
|
|
|
+ return false
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
/**
|
|
|
* 更新节点
|
|
|
* @param fields
|
|
|
*/
|
|
|
|
|
|
-const handleUpdate = async (fields) => {
|
|
|
- const hide = message.loading('正在配置');
|
|
|
+const handleUpdate = async fields => {
|
|
|
+ const hide = message.loading('正在配置')
|
|
|
|
|
|
try {
|
|
|
await updateRule({
|
|
|
name: fields.name,
|
|
|
desc: fields.desc,
|
|
|
- key: fields.key,
|
|
|
- });
|
|
|
- hide();
|
|
|
- message.success('配置成功');
|
|
|
- return true;
|
|
|
+ key: fields.key
|
|
|
+ })
|
|
|
+ hide()
|
|
|
+ message.success('配置成功')
|
|
|
+ return true
|
|
|
} catch (error) {
|
|
|
- hide();
|
|
|
- message.error('配置失败请重试!');
|
|
|
- return false;
|
|
|
+ hide()
|
|
|
+ message.error('配置失败请重试!')
|
|
|
+ return false
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
/**
|
|
|
* 删除节点
|
|
|
* @param selectedRows
|
|
|
*/
|
|
|
|
|
|
-const handleRemove = async (selectedRows) => {
|
|
|
- const hide = message.loading('正在删除');
|
|
|
- if (!selectedRows) return true;
|
|
|
+const handleRemove = async selectedRows => {
|
|
|
+ const hide = message.loading('正在删除')
|
|
|
+ if (!selectedRows) return true
|
|
|
|
|
|
try {
|
|
|
await removeRule({
|
|
|
- key: selectedRows.map((row) => row.key),
|
|
|
- });
|
|
|
- hide();
|
|
|
- message.success('删除成功,即将刷新');
|
|
|
- return true;
|
|
|
+ key: selectedRows.map(row => row.key)
|
|
|
+ })
|
|
|
+ hide()
|
|
|
+ message.success('删除成功,即将刷新')
|
|
|
+ return true
|
|
|
} catch (error) {
|
|
|
- hide();
|
|
|
- message.error('删除失败,请重试');
|
|
|
- return false;
|
|
|
+ hide()
|
|
|
+ message.error('删除失败,请重试')
|
|
|
+ return false
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
const TableList = () => {
|
|
|
- const [createModalVisible, handleModalVisible] = useState(false);
|
|
|
- const [updateModalVisible, handleUpdateModalVisible] = useState(false);
|
|
|
- const [stepFormValues, setStepFormValues] = useState({});
|
|
|
- const actionRef = useRef();
|
|
|
- const [row, setRow] = useState();
|
|
|
- const [selectedRowsState, setSelectedRows] = useState([]);
|
|
|
+ const [ createModalVisible, handleModalVisible ] = useState(false)
|
|
|
+ const [ updateModalVisible, handleUpdateModalVisible ] = useState(false)
|
|
|
+ const [ stepFormValues, setStepFormValues ] = useState({})
|
|
|
+ const actionRef = useRef()
|
|
|
+ const [ row, setRow ] = useState()
|
|
|
+ const [ selectedRowsState, setSelectedRows ] = useState([])
|
|
|
const columns = [
|
|
|
{
|
|
|
title: '规则名称',
|
|
@@ -88,25 +88,25 @@ const TableList = () => {
|
|
|
rules: [
|
|
|
{
|
|
|
required: true,
|
|
|
- message: '规则名称为必填项',
|
|
|
- },
|
|
|
- ],
|
|
|
+ message: '规则名称为必填项'
|
|
|
+ }
|
|
|
+ ]
|
|
|
},
|
|
|
render: (dom, entity) => {
|
|
|
- return <a onClick={() => setRow(entity)}>{dom}</a>;
|
|
|
- },
|
|
|
+ return <a onClick={() => setRow(entity)}>{dom}</a>
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '描述',
|
|
|
dataIndex: 'desc',
|
|
|
- valueType: 'textarea',
|
|
|
+ valueType: 'textarea'
|
|
|
},
|
|
|
{
|
|
|
title: '服务调用次数',
|
|
|
dataIndex: 'callNo',
|
|
|
sorter: true,
|
|
|
hideInForm: true,
|
|
|
- renderText: (val) => `${val} 万`,
|
|
|
+ renderText: val => `${val} 万`
|
|
|
},
|
|
|
{
|
|
|
title: '状态',
|
|
@@ -115,21 +115,21 @@ const TableList = () => {
|
|
|
valueEnum: {
|
|
|
0: {
|
|
|
text: '关闭',
|
|
|
- status: 'Default',
|
|
|
+ status: 'Default'
|
|
|
},
|
|
|
1: {
|
|
|
text: '运行中',
|
|
|
- status: 'Processing',
|
|
|
+ status: 'Processing'
|
|
|
},
|
|
|
2: {
|
|
|
text: '已上线',
|
|
|
- status: 'Success',
|
|
|
+ status: 'Success'
|
|
|
},
|
|
|
3: {
|
|
|
text: '异常',
|
|
|
- status: 'Error',
|
|
|
- },
|
|
|
- },
|
|
|
+ status: 'Error'
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '上次调度时间',
|
|
@@ -138,18 +138,18 @@ const TableList = () => {
|
|
|
valueType: 'dateTime',
|
|
|
hideInForm: true,
|
|
|
renderFormItem: (item, { defaultRender, ...rest }, form) => {
|
|
|
- const status = form.getFieldValue('status');
|
|
|
+ const status = form.getFieldValue('status')
|
|
|
|
|
|
if (`${status}` === '0') {
|
|
|
- return false;
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
if (`${status}` === '3') {
|
|
|
- return <Input {...rest} placeholder="请输入异常原因!" />;
|
|
|
+ return <Input {...rest} placeholder="请输入异常原因!" />
|
|
|
}
|
|
|
|
|
|
- return defaultRender(item);
|
|
|
- },
|
|
|
+ return defaultRender(item)
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '操作',
|
|
@@ -159,18 +159,17 @@ const TableList = () => {
|
|
|
<>
|
|
|
<a
|
|
|
onClick={() => {
|
|
|
- handleUpdateModalVisible(true);
|
|
|
- setStepFormValues(record);
|
|
|
- }}
|
|
|
- >
|
|
|
+ handleUpdateModalVisible(true)
|
|
|
+ setStepFormValues(record)
|
|
|
+ }}>
|
|
|
配置
|
|
|
</a>
|
|
|
<Divider type="vertical" />
|
|
|
<a href="">订阅警报</a>
|
|
|
</>
|
|
|
- ),
|
|
|
- },
|
|
|
- ];
|
|
|
+ )
|
|
|
+ }
|
|
|
+ ]
|
|
|
return (
|
|
|
<PageContainer>
|
|
|
<ProTable
|
|
@@ -178,17 +177,17 @@ const TableList = () => {
|
|
|
actionRef={actionRef}
|
|
|
rowKey="key"
|
|
|
search={{
|
|
|
- labelWidth: 120,
|
|
|
+ labelWidth: 120
|
|
|
}}
|
|
|
toolBarRender={() => [
|
|
|
<Button type="primary" onClick={() => handleModalVisible(true)}>
|
|
|
- <PlusOutlined /> 新建
|
|
|
- </Button>,
|
|
|
+ <PlusOutlined /><span>新建</span>
|
|
|
+ </Button>
|
|
|
]}
|
|
|
request={(params, sorter, filter) => queryRule({ ...params, sorter, filter })}
|
|
|
columns={columns}
|
|
|
rowSelection={{
|
|
|
- onChange: (_, selectedRows) => setSelectedRows(selectedRows),
|
|
|
+ onChange: (_, selectedRows) => setSelectedRows(selectedRows)
|
|
|
}}
|
|
|
/>
|
|
|
{selectedRowsState?.length > 0 && (
|
|
@@ -198,9 +197,8 @@ const TableList = () => {
|
|
|
已选择{' '}
|
|
|
<a
|
|
|
style={{
|
|
|
- fontWeight: 600,
|
|
|
- }}
|
|
|
- >
|
|
|
+ fontWeight: 600
|
|
|
+ }}>
|
|
|
{selectedRowsState.length}
|
|
|
</a>{' '}
|
|
|
项
|
|
@@ -208,15 +206,13 @@ const TableList = () => {
|
|
|
服务调用次数总计 {selectedRowsState.reduce((pre, item) => pre + item.callNo, 0)} 万
|
|
|
</span>
|
|
|
</div>
|
|
|
- }
|
|
|
- >
|
|
|
+ }>
|
|
|
<Button
|
|
|
onClick={async () => {
|
|
|
- await handleRemove(selectedRowsState);
|
|
|
- setSelectedRows([]);
|
|
|
- actionRef.current?.reloadAndRest?.();
|
|
|
- }}
|
|
|
- >
|
|
|
+ await handleRemove(selectedRowsState)
|
|
|
+ setSelectedRows([])
|
|
|
+ actionRef.current?.reloadAndRest?.()
|
|
|
+ }}>
|
|
|
批量删除
|
|
|
</Button>
|
|
|
<Button type="primary">批量审批</Button>
|
|
@@ -224,14 +220,14 @@ const TableList = () => {
|
|
|
)}
|
|
|
<CreateForm onCancel={() => handleModalVisible(false)} modalVisible={createModalVisible}>
|
|
|
<ProTable
|
|
|
- onSubmit={async (value) => {
|
|
|
- const success = await handleAdd(value);
|
|
|
+ onSubmit={async value => {
|
|
|
+ const success = await handleAdd(value)
|
|
|
|
|
|
if (success) {
|
|
|
- handleModalVisible(false);
|
|
|
+ handleModalVisible(false)
|
|
|
|
|
|
if (actionRef.current) {
|
|
|
- actionRef.current.reload();
|
|
|
+ actionRef.current.reload()
|
|
|
}
|
|
|
}
|
|
|
}}
|
|
@@ -242,21 +238,21 @@ const TableList = () => {
|
|
|
</CreateForm>
|
|
|
{stepFormValues && Object.keys(stepFormValues).length ? (
|
|
|
<UpdateForm
|
|
|
- onSubmit={async (value) => {
|
|
|
- const success = await handleUpdate(value);
|
|
|
+ onSubmit={async value => {
|
|
|
+ const success = await handleUpdate(value)
|
|
|
|
|
|
if (success) {
|
|
|
- handleUpdateModalVisible(false);
|
|
|
- setStepFormValues({});
|
|
|
+ handleUpdateModalVisible(false)
|
|
|
+ setStepFormValues({})
|
|
|
|
|
|
if (actionRef.current) {
|
|
|
- actionRef.current.reload();
|
|
|
+ actionRef.current.reload()
|
|
|
}
|
|
|
}
|
|
|
}}
|
|
|
onCancel={() => {
|
|
|
- handleUpdateModalVisible(false);
|
|
|
- setStepFormValues({});
|
|
|
+ handleUpdateModalVisible(false)
|
|
|
+ setStepFormValues({})
|
|
|
}}
|
|
|
updateModalVisible={updateModalVisible}
|
|
|
values={stepFormValues}
|
|
@@ -267,26 +263,25 @@ const TableList = () => {
|
|
|
width={600}
|
|
|
visible={!!row}
|
|
|
onClose={() => {
|
|
|
- setRow(undefined);
|
|
|
+ setRow(undefined)
|
|
|
}}
|
|
|
- closable={false}
|
|
|
- >
|
|
|
+ closable={false}>
|
|
|
{row?.name && (
|
|
|
<ProDescriptions
|
|
|
column={2}
|
|
|
title={row?.name}
|
|
|
request={async () => ({
|
|
|
- data: row || {},
|
|
|
+ data: row || {}
|
|
|
})}
|
|
|
params={{
|
|
|
- id: row?.name,
|
|
|
+ id: row?.name
|
|
|
}}
|
|
|
columns={columns}
|
|
|
/>
|
|
|
)}
|
|
|
</Drawer>
|
|
|
</PageContainer>
|
|
|
- );
|
|
|
-};
|
|
|
+ )
|
|
|
+}
|
|
|
|
|
|
-export default TableList;
|
|
|
+export default TableList
|