145 lines
3.4 KiB
TypeScript
145 lines
3.4 KiB
TypeScript
import { PlusOutlined } from '@ant-design/icons';
|
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
|
import { history } from '@umijs/max';
|
|
import { Popconfirm } from 'antd';
|
|
import React, { useCallback, useRef, useState } from 'react';
|
|
import ConfigurableDrawerForm, {
|
|
type ConfigurableDrawerFormRef,
|
|
} from '@/components/DrawerForm';
|
|
import EnhancedProTable from '@/components/EnhancedProTable';
|
|
import type { ToolbarAction } from '@/components/EnhancedProTable/types';
|
|
import { formStatusType } from '@/constants';
|
|
import {
|
|
createDictType,
|
|
type DictTypeVO,
|
|
deleteDictType,
|
|
getDictTypePage,
|
|
updateDictType,
|
|
} from '@/services/system/dict/dict.type';
|
|
import { baseDictTypeColumns, formColumns } from './config';
|
|
|
|
const SyStemDict = () => {
|
|
const configurableDrawerRef = useRef<ConfigurableDrawerFormRef>(null);
|
|
const tableRef = useRef<ActionType>(null);
|
|
|
|
const [type, setType] = useState<'create' | 'update'>('create');
|
|
const [id, setId] = useState<number>(0);
|
|
|
|
//获取路由数据
|
|
|
|
const handleEdit = (record: DictTypeVO) => {
|
|
setType('update');
|
|
setId(record.id);
|
|
|
|
configurableDrawerRef.current?.open(record);
|
|
};
|
|
|
|
const onFetch = async (params: { pageSize?: number; current?: number }) => {
|
|
const data = await getDictTypePage({
|
|
...params,
|
|
pageNo: params.current,
|
|
pageSize: params.pageSize,
|
|
});
|
|
return {
|
|
data: data.list,
|
|
success: true,
|
|
total: data.total,
|
|
};
|
|
};
|
|
|
|
const handleAdd = () => {
|
|
setType('create');
|
|
configurableDrawerRef.current?.open({});
|
|
};
|
|
|
|
const handleSubmit = useCallback(
|
|
async (values: DictTypeVO) => {
|
|
if (type === 'create') {
|
|
await createDictType(values);
|
|
} else {
|
|
await updateDictType({
|
|
...values,
|
|
id,
|
|
});
|
|
}
|
|
tableRef.current?.reload();
|
|
return true;
|
|
},
|
|
[type, id],
|
|
);
|
|
|
|
const toolbarActions: ToolbarAction[] = [
|
|
{
|
|
key: 'add',
|
|
label: '新建',
|
|
type: 'primary',
|
|
icon: <PlusOutlined />,
|
|
onClick: handleAdd,
|
|
},
|
|
];
|
|
|
|
const actionColumns: ProColumns<DictTypeVO> = {
|
|
title: '操作',
|
|
dataIndex: 'option',
|
|
valueType: 'option',
|
|
fixed: 'right',
|
|
width: 120,
|
|
render: (
|
|
_text: React.ReactNode,
|
|
record: DictTypeVO,
|
|
_: any,
|
|
action: any,
|
|
) => [
|
|
<a key="editable" onClick={() => handleEdit(record)}>
|
|
编辑
|
|
</a>,
|
|
<Popconfirm
|
|
title="是否删除?"
|
|
key="delete"
|
|
onConfirm={async () => {
|
|
await deleteDictType(record.id);
|
|
action?.reload();
|
|
}}
|
|
okText="是"
|
|
cancelText="否"
|
|
>
|
|
<a>删除</a>
|
|
</Popconfirm>,
|
|
<a
|
|
key="data"
|
|
onClick={() =>
|
|
history.push({
|
|
pathname: '/system/dict/data/' + record.type,
|
|
})
|
|
}
|
|
>
|
|
数据
|
|
</a>,
|
|
],
|
|
};
|
|
|
|
const columns = [...baseDictTypeColumns, actionColumns];
|
|
return (
|
|
<>
|
|
<EnhancedProTable<DictTypeVO>
|
|
ref={tableRef}
|
|
columns={columns}
|
|
request={onFetch}
|
|
toolbarActions={toolbarActions}
|
|
headerTitle="租户列表"
|
|
showIndex={false}
|
|
showSelection={false}
|
|
/>
|
|
|
|
<ConfigurableDrawerForm
|
|
ref={configurableDrawerRef}
|
|
title={formStatusType[type]}
|
|
columns={formColumns(type)}
|
|
onSubmit={handleSubmit}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default SyStemDict;
|