blob: fdcfb8514a59e56be96e3cdecad3acd008c7953e [file] [log] [blame]
86133aaa3f5d2025-04-20 21:33:29 +08001import React, { useEffect, useRef, useState } from 'react';
2import { Modal } from 'antd';
3import { FormattedMessage, useIntl } from '@umijs/max';
4import { ActionType, ParamsType, ProColumns, ProTable, RequestData } from '@ant-design/pro-components';
5import { getDictValueEnum } from '@/services/system/dict';
6import DictTag from '@/components/DictTag';
7
8
9/* *
10 *
11 * @author whiteshader@163.com
12 * @datetime 2023/02/10
13 *
14 * */
15
16export type DataScopeFormProps = {
17 onCancel: () => void;
18 onSubmit: (values: React.Key[]) => void;
19 open: boolean;
20 params: ParamsType;
21 request?: (params: Record<string, any>) => Promise<Partial<RequestData<API.System.User>>>;
22};
23
24const UserSelectorModal: React.FC<DataScopeFormProps> = (props) => {
25
26 const actionRef = useRef<ActionType>();
27 const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
28 const [statusOptions, setStatusOptions] = useState<any>([]);
29
30 useEffect(() => {
31 getDictValueEnum('sys_normal_disable').then((data) => {
32 setStatusOptions(data);
33 });
34 }, [props]);
35
36 const intl = useIntl();
37 const handleOk = () => {
38 props.onSubmit(selectedRowKeys);
39 };
40 const handleCancel = () => {
41 props.onCancel();
42 };
43
44 const columns: ProColumns<API.System.User>[] = [
45 {
46 title: <FormattedMessage id="system.user.user_id" defaultMessage="用户编号" />,
47 dataIndex: 'userId',
48 valueType: 'text',
49 hideInSearch: true,
50 },
51 {
52 title: <FormattedMessage id="system.user.user_name" defaultMessage="用户账号" />,
53 dataIndex: 'userName',
54 valueType: 'text',
55 },
56 {
57 title: <FormattedMessage id="system.user.nick_name" defaultMessage="用户昵称" />,
58 dataIndex: 'nickName',
59 valueType: 'text',
60 hideInSearch: true,
61 },
62 {
63 title: <FormattedMessage id="system.user.phonenumber" defaultMessage="手机号码" />,
64 dataIndex: 'phonenumber',
65 valueType: 'text',
66 },
67 {
68 title: <FormattedMessage id="system.user.status" defaultMessage="帐号状态" />,
69 dataIndex: 'status',
70 valueType: 'select',
71 hideInSearch: true,
72 valueEnum: statusOptions,
73 render: (_, record) => {
74 return (<DictTag enums={statusOptions} value={record.status} />);
75 },
76 },
77 {
78 title: <FormattedMessage id="system.user.create_time" defaultMessage="创建时间" />,
79 dataIndex: 'createTime',
80 valueType: 'dateRange',
81 hideInSearch: true,
82 render: (_, record) => {
83 return (<span>{record.createTime.toString()} </span>);
84 },
85 }
86 ];
87
88 return (
89 <Modal
90 width={800}
91 title={intl.formatMessage({
92 id: 'system.role.auth.user',
93 defaultMessage: '选择用户',
94 })}
95 open={props.open}
96 destroyOnClose
97 onOk={handleOk}
98 onCancel={handleCancel}
99 >
100 <ProTable<API.System.User>
101 headerTitle={intl.formatMessage({
102 id: 'pages.searchTable.title',
103 defaultMessage: '信息',
104 })}
105 actionRef={actionRef}
106 rowKey="userId"
107 key="userList"
108 search={{
109 labelWidth: 120,
110 }}
111 toolbar={{}}
112 params={props.params}
113 request={props.request}
114 columns={columns}
115 rowSelection={{
116 onChange: (selectedRowKeys: React.Key[]) => {
117 setSelectedRowKeys(selectedRowKeys);
118 },
119 }}
120 />
121 </Modal>
122 );
123};
124
125export default UserSelectorModal;