|
1 | | -import { FC } from 'react'; |
| 1 | +import { FC, useRef } from 'react'; |
| 2 | +import { Button, Tag } from 'antd'; |
| 3 | + |
| 4 | +import { getUserList } from '@/apis/SystemManagementApi'; |
| 5 | +import { User, UserRequest } from '@/apis/SystemManagementApi/types'; |
| 6 | +import { WizardTable } from '@/compoments'; |
| 7 | +import { UseModalRefType } from '@/compoments/WizardModal/useModal'; |
| 8 | +import { CreateTableProps } from '@/compoments/WizardTable/types'; |
| 9 | +import { PlusOutlined } from '@ant-design/icons'; |
| 10 | +import { CreateUserModal } from './CreateUserModal'; |
2 | 11 |
|
3 | 12 | const SystemManagement: FC = () => { |
4 | | - return '系统管理'; |
| 13 | + const [page] = WizardTable.usePage(); |
| 14 | + const CreateUserModalRef = useRef<UseModalRefType>(null); |
| 15 | + |
| 16 | + const UserColumns: CreateTableProps<User>['columns'] = [ |
| 17 | + { |
| 18 | + title: '用户名', |
| 19 | + dataIndex: 'username', |
| 20 | + }, |
| 21 | + { |
| 22 | + title: '邮箱', |
| 23 | + dataIndex: 'email', |
| 24 | + width: 320, |
| 25 | + }, |
| 26 | + { |
| 27 | + title: 'Roles', |
| 28 | + dataIndex: 'role', |
| 29 | + width: 160, |
| 30 | + render: (val) => |
| 31 | + val && Array.isArray(val) ? ( |
| 32 | + <div className="flex items-center justify-center gap-2"> |
| 33 | + {val.map((it) => ( |
| 34 | + <Tag key={it} color="blue"> |
| 35 | + {it} |
| 36 | + </Tag> |
| 37 | + ))} |
| 38 | + </div> |
| 39 | + ) : ( |
| 40 | + '-' |
| 41 | + ), |
| 42 | + }, |
| 43 | + { |
| 44 | + title: '操作', |
| 45 | + dataIndex: 'report_id', |
| 46 | + fixed: 'right', |
| 47 | + width: 160, |
| 48 | + render: (_, record) => <div>这是操作项 {record?.email}</div>, |
| 49 | + }, |
| 50 | + ]; |
| 51 | + |
| 52 | + const handCreateUser = async () => { |
| 53 | + console.log(222); |
| 54 | + CreateUserModalRef.current?.open(); |
| 55 | + }; |
| 56 | + |
| 57 | + return ( |
| 58 | + <> |
| 59 | + <WizardTable |
| 60 | + page={page} |
| 61 | + rowKey="username" |
| 62 | + columns={UserColumns} |
| 63 | + tableHeader={{ |
| 64 | + title: '用户管理列表', |
| 65 | + options: { |
| 66 | + optionsSearch: { |
| 67 | + key: 'name', |
| 68 | + placeholder: '请输入用户名搜索', |
| 69 | + }, |
| 70 | + trigger: ( |
| 71 | + <div className="flex gap-2"> |
| 72 | + <Button onClick={async () => {}}> |
| 73 | + <PlusOutlined /> 批量创建 |
| 74 | + </Button> |
| 75 | + |
| 76 | + <Button |
| 77 | + type="primary" |
| 78 | + onClick={async () => handCreateUser()} |
| 79 | + > |
| 80 | + <PlusOutlined /> 创建用户 |
| 81 | + </Button> |
| 82 | + </div> |
| 83 | + ), |
| 84 | + }, |
| 85 | + }} |
| 86 | + request={async (params, filter) => { |
| 87 | + const request = { |
| 88 | + ...params, |
| 89 | + ...filter, |
| 90 | + } as UserRequest; |
| 91 | + const result = await getUserList({ ...request }); |
| 92 | + const { data } = result; |
| 93 | + return { |
| 94 | + list: data?.list ?? [], |
| 95 | + pagemeta: data?.pagemeta, |
| 96 | + }; |
| 97 | + }} |
| 98 | + /> |
| 99 | + <CreateUserModal |
| 100 | + ref={CreateUserModalRef} |
| 101 | + title="创建用户" |
| 102 | + refresh={page.refresh} |
| 103 | + /> |
| 104 | + </> |
| 105 | + ); |
5 | 106 | }; |
6 | 107 |
|
7 | 108 | export { SystemManagement }; |
0 commit comments