|
|
@ -1,103 +1,21 @@ |
|
|
import { addRule, removeRule, rule, updateRule } from '@/services/ant-design-pro/api'; |
|
|
import { removeRule, rule } from '@/services/ant-design-pro/api'; |
|
|
import { PlusOutlined } from '@ant-design/icons'; |
|
|
|
|
|
import type { ActionType, ProColumns, ProDescriptionsItemProps } from '@ant-design/pro-components'; |
|
|
import type { ActionType, ProColumns, ProDescriptionsItemProps } from '@ant-design/pro-components'; |
|
|
import { |
|
|
import { |
|
|
FooterToolbar, |
|
|
FooterToolbar, |
|
|
ModalForm, |
|
|
|
|
|
PageContainer, |
|
|
PageContainer, |
|
|
ProDescriptions, |
|
|
ProDescriptions, |
|
|
ProFormText, |
|
|
|
|
|
ProFormTextArea, |
|
|
|
|
|
ProTable, |
|
|
ProTable, |
|
|
} from '@ant-design/pro-components'; |
|
|
} from '@ant-design/pro-components'; |
|
|
import { FormattedMessage, useIntl } from '@umijs/max'; |
|
|
import { FormattedMessage, useIntl, useRequest } from '@umijs/max'; |
|
|
import { Button, Drawer, Input, message } from 'antd'; |
|
|
import { Button, Drawer, Input, message } from 'antd'; |
|
|
import React, { useRef, useState } from 'react'; |
|
|
import React, { useCallback, useRef, useState } from 'react'; |
|
|
import type { FormValueType } from './components/UpdateForm'; |
|
|
import CreateForm from './components/CreateForm'; |
|
|
import UpdateForm from './components/UpdateForm'; |
|
|
import UpdateForm from './components/UpdateForm'; |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @en-US Add node |
|
|
|
|
|
* @zh-CN 添加节点 |
|
|
|
|
|
* @param fields |
|
|
|
|
|
*/ |
|
|
|
|
|
const handleAdd = async (fields: API.RuleListItem) => { |
|
|
|
|
|
const hide = message.loading('正在添加'); |
|
|
|
|
|
try { |
|
|
|
|
|
await addRule({ ...fields }); |
|
|
|
|
|
hide(); |
|
|
|
|
|
message.success('Added successfully'); |
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
hide(); |
|
|
|
|
|
message.error('Adding failed, please try again!'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @en-US Update node |
|
|
|
|
|
* @zh-CN 更新节点 |
|
|
|
|
|
* |
|
|
|
|
|
* @param fields |
|
|
|
|
|
*/ |
|
|
|
|
|
const handleUpdate = async (fields: FormValueType) => { |
|
|
|
|
|
const hide = message.loading('Configuring'); |
|
|
|
|
|
try { |
|
|
|
|
|
await updateRule({ |
|
|
|
|
|
name: fields.name, |
|
|
|
|
|
desc: fields.desc, |
|
|
|
|
|
key: fields.key, |
|
|
|
|
|
}); |
|
|
|
|
|
hide(); |
|
|
|
|
|
|
|
|
|
|
|
message.success('Configuration is successful'); |
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
hide(); |
|
|
|
|
|
message.error('Configuration failed, please try again!'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Delete node |
|
|
|
|
|
* @zh-CN 删除节点 |
|
|
|
|
|
* |
|
|
|
|
|
* @param selectedRows |
|
|
|
|
|
*/ |
|
|
|
|
|
const handleRemove = async (selectedRows: API.RuleListItem[]) => { |
|
|
|
|
|
const hide = message.loading('正在删除'); |
|
|
|
|
|
if (!selectedRows) return true; |
|
|
|
|
|
try { |
|
|
|
|
|
await removeRule({ |
|
|
|
|
|
key: selectedRows.map((row) => row.key), |
|
|
|
|
|
}); |
|
|
|
|
|
hide(); |
|
|
|
|
|
message.success('Deleted successfully and will refresh soon'); |
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
hide(); |
|
|
|
|
|
message.error('Delete failed, please try again'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const TableList: React.FC = () => { |
|
|
const TableList: React.FC = () => { |
|
|
/** |
|
|
const actionRef = useRef<ActionType>(); |
|
|
* @en-US Pop-up window of new window |
|
|
|
|
|
* @zh-CN 新建窗口的弹窗 |
|
|
|
|
|
* */ |
|
|
|
|
|
const [createModalOpen, handleModalOpen] = useState<boolean>(false); |
|
|
|
|
|
/** |
|
|
|
|
|
* @en-US The pop-up window of the distribution update window |
|
|
|
|
|
* @zh-CN 分布更新窗口的弹窗 |
|
|
|
|
|
* */ |
|
|
|
|
|
const [updateModalOpen, handleUpdateModalOpen] = useState<boolean>(false); |
|
|
|
|
|
|
|
|
|
|
|
const [showDetail, setShowDetail] = useState<boolean>(false); |
|
|
const [showDetail, setShowDetail] = useState<boolean>(false); |
|
|
|
|
|
|
|
|
const actionRef = useRef<ActionType>(); |
|
|
|
|
|
const [currentRow, setCurrentRow] = useState<API.RuleListItem>(); |
|
|
const [currentRow, setCurrentRow] = useState<API.RuleListItem>(); |
|
|
const [selectedRowsState, setSelectedRows] = useState<API.RuleListItem[]>([]); |
|
|
const [selectedRowsState, setSelectedRows] = useState<API.RuleListItem[]>([]); |
|
|
|
|
|
|
|
|
@ -107,6 +25,21 @@ const TableList: React.FC = () => { |
|
|
* */ |
|
|
* */ |
|
|
const intl = useIntl(); |
|
|
const intl = useIntl(); |
|
|
|
|
|
|
|
|
|
|
|
const [messageApi, contextHolder] = message.useMessage(); |
|
|
|
|
|
|
|
|
|
|
|
const { run: delRun, loading } = useRequest(removeRule, { |
|
|
|
|
|
manual: true, |
|
|
|
|
|
onSuccess: () => { |
|
|
|
|
|
setSelectedRows([]); |
|
|
|
|
|
actionRef.current?.reloadAndRest?.(); |
|
|
|
|
|
|
|
|
|
|
|
messageApi.success('Deleted successfully and will refresh soon'); |
|
|
|
|
|
}, |
|
|
|
|
|
onError: () => { |
|
|
|
|
|
messageApi.error('Delete failed, please try again'); |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const columns: ProColumns<API.RuleListItem>[] = [ |
|
|
const columns: ProColumns<API.RuleListItem>[] = [ |
|
|
{ |
|
|
{ |
|
|
title: ( |
|
|
title: ( |
|
|
@ -222,15 +155,16 @@ const TableList: React.FC = () => { |
|
|
dataIndex: 'option', |
|
|
dataIndex: 'option', |
|
|
valueType: 'option', |
|
|
valueType: 'option', |
|
|
render: (_, record) => [ |
|
|
render: (_, record) => [ |
|
|
<a |
|
|
<UpdateForm |
|
|
|
|
|
trigger={ |
|
|
|
|
|
<a> |
|
|
|
|
|
<FormattedMessage id="pages.searchTable.config" defaultMessage="Configuration" /> |
|
|
|
|
|
</a> |
|
|
|
|
|
} |
|
|
key="config" |
|
|
key="config" |
|
|
onClick={() => { |
|
|
onOk={actionRef.current?.reload} |
|
|
handleUpdateModalOpen(true); |
|
|
values={record} |
|
|
setCurrentRow(record); |
|
|
/>, |
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<FormattedMessage id="pages.searchTable.config" defaultMessage="Configuration" /> |
|
|
|
|
|
</a>, |
|
|
|
|
|
<a key="subscribeAlert" href="https://procomponents.ant.design/"> |
|
|
<a key="subscribeAlert" href="https://procomponents.ant.design/"> |
|
|
<FormattedMessage |
|
|
<FormattedMessage |
|
|
id="pages.searchTable.subscribeAlert" |
|
|
id="pages.searchTable.subscribeAlert" |
|
|
@ -241,8 +175,32 @@ const TableList: React.FC = () => { |
|
|
}, |
|
|
}, |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Delete node |
|
|
|
|
|
* @zh-CN 删除节点 |
|
|
|
|
|
* |
|
|
|
|
|
* @param selectedRows |
|
|
|
|
|
*/ |
|
|
|
|
|
const handleRemove = useCallback( |
|
|
|
|
|
async (selectedRows: API.RuleListItem[]) => { |
|
|
|
|
|
if (!selectedRows?.length) { |
|
|
|
|
|
messageApi.warning('请选择删除项'); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await delRun({ |
|
|
|
|
|
data: { |
|
|
|
|
|
key: selectedRows.map((row) => row.key), |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
[delRun], |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<PageContainer> |
|
|
<PageContainer> |
|
|
|
|
|
{contextHolder} |
|
|
<ProTable<API.RuleListItem, API.PageParams> |
|
|
<ProTable<API.RuleListItem, API.PageParams> |
|
|
headerTitle={intl.formatMessage({ |
|
|
headerTitle={intl.formatMessage({ |
|
|
id: 'pages.searchTable.title', |
|
|
id: 'pages.searchTable.title', |
|
|
@ -253,17 +211,7 @@ const TableList: React.FC = () => { |
|
|
search={{ |
|
|
search={{ |
|
|
labelWidth: 120, |
|
|
labelWidth: 120, |
|
|
}} |
|
|
}} |
|
|
toolBarRender={() => [ |
|
|
toolBarRender={() => [<CreateForm key="create" reload={actionRef.current?.reload} />]} |
|
|
<Button |
|
|
|
|
|
type="primary" |
|
|
|
|
|
key="primary" |
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
handleModalOpen(true); |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<PlusOutlined /> <FormattedMessage id="pages.searchTable.new" defaultMessage="New" /> |
|
|
|
|
|
</Button>, |
|
|
|
|
|
]} |
|
|
|
|
|
request={rule} |
|
|
request={rule} |
|
|
columns={columns} |
|
|
columns={columns} |
|
|
rowSelection={{ |
|
|
rowSelection={{ |
|
|
@ -292,10 +240,9 @@ const TableList: React.FC = () => { |
|
|
} |
|
|
} |
|
|
> |
|
|
> |
|
|
<Button |
|
|
<Button |
|
|
onClick={async () => { |
|
|
loading={loading} |
|
|
await handleRemove(selectedRowsState); |
|
|
onClick={() => { |
|
|
setSelectedRows([]); |
|
|
handleRemove(selectedRowsState); |
|
|
actionRef.current?.reloadAndRest?.(); |
|
|
|
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
<FormattedMessage |
|
|
<FormattedMessage |
|
|
@ -311,61 +258,6 @@ const TableList: React.FC = () => { |
|
|
</Button> |
|
|
</Button> |
|
|
</FooterToolbar> |
|
|
</FooterToolbar> |
|
|
)} |
|
|
)} |
|
|
<ModalForm |
|
|
|
|
|
title={intl.formatMessage({ |
|
|
|
|
|
id: 'pages.searchTable.createForm.newRule', |
|
|
|
|
|
defaultMessage: 'New rule', |
|
|
|
|
|
})} |
|
|
|
|
|
width="400px" |
|
|
|
|
|
open={createModalOpen} |
|
|
|
|
|
onOpenChange={handleModalOpen} |
|
|
|
|
|
onFinish={async (value) => { |
|
|
|
|
|
const success = await handleAdd(value as API.RuleListItem); |
|
|
|
|
|
if (success) { |
|
|
|
|
|
handleModalOpen(false); |
|
|
|
|
|
if (actionRef.current) { |
|
|
|
|
|
actionRef.current.reload(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<ProFormText |
|
|
|
|
|
rules={[ |
|
|
|
|
|
{ |
|
|
|
|
|
required: true, |
|
|
|
|
|
message: ( |
|
|
|
|
|
<FormattedMessage |
|
|
|
|
|
id="pages.searchTable.ruleName" |
|
|
|
|
|
defaultMessage="Rule name is required" |
|
|
|
|
|
/> |
|
|
|
|
|
), |
|
|
|
|
|
}, |
|
|
|
|
|
]} |
|
|
|
|
|
width="md" |
|
|
|
|
|
name="name" |
|
|
|
|
|
/> |
|
|
|
|
|
<ProFormTextArea width="md" name="desc" /> |
|
|
|
|
|
</ModalForm> |
|
|
|
|
|
<UpdateForm |
|
|
|
|
|
onSubmit={async (value) => { |
|
|
|
|
|
const success = await handleUpdate(value); |
|
|
|
|
|
if (success) { |
|
|
|
|
|
handleUpdateModalOpen(false); |
|
|
|
|
|
setCurrentRow(undefined); |
|
|
|
|
|
if (actionRef.current) { |
|
|
|
|
|
actionRef.current.reload(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}} |
|
|
|
|
|
onCancel={() => { |
|
|
|
|
|
handleUpdateModalOpen(false); |
|
|
|
|
|
if (!showDetail) { |
|
|
|
|
|
setCurrentRow(undefined); |
|
|
|
|
|
} |
|
|
|
|
|
}} |
|
|
|
|
|
updateModalOpen={updateModalOpen} |
|
|
|
|
|
values={currentRow || {}} |
|
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
|
|
<Drawer |
|
|
<Drawer |
|
|
width={600} |
|
|
width={600} |
|
|
|