|
@@ -1,130 +0,0 @@
|
1
|
|
-import React from "react";
|
2
|
|
-import { Modal, Form, Input, Button, Select } from "antd";
|
3
|
|
-import useBool from "@/utils/hooks/useBool";
|
4
|
|
-import { getSysLogin, postSysLogin } from "@/services/syslogin";
|
5
|
|
-import { postSysUser, getSysUserById } from "@/services/sysuser";
|
6
|
|
-import md5 from "md5";
|
7
|
|
-
|
8
|
|
-const { Option } = Select;
|
9
|
|
-
|
10
|
|
-const formItemLayout = {
|
11
|
|
- labelCol: {
|
12
|
|
- xs: { span: 24 },
|
13
|
|
- sm: { span: 8 },
|
14
|
|
- },
|
15
|
|
- wrapperCol: {
|
16
|
|
- xs: { span: 24 },
|
17
|
|
- sm: { span: 16 },
|
18
|
|
- },
|
19
|
|
-};
|
20
|
|
-const tailFormItemLayout = {
|
21
|
|
- wrapperCol: {
|
22
|
|
- xs: {
|
23
|
|
- span: 24,
|
24
|
|
- offset: 0,
|
25
|
|
- },
|
26
|
|
- sm: {
|
27
|
|
- span: 16,
|
28
|
|
- offset: 8,
|
29
|
|
- },
|
30
|
|
- },
|
31
|
|
-};
|
32
|
|
-
|
33
|
|
-const defaultPass = "123456";
|
34
|
|
-
|
35
|
|
-export default (props) => {
|
36
|
|
- const { user, onSuccess, onCancel, roleList = [], ...leftProps } = props;
|
37
|
|
-
|
38
|
|
- const [loading, startLoading, cancelLoading] = useBool();
|
39
|
|
- const [form] = Form.useForm();
|
40
|
|
-
|
41
|
|
- const onFinish = (values) => {
|
42
|
|
- const password = md5(defaultPass);
|
43
|
|
- const rolesList = (values.rolesList || []).map((x) => ({ roleId: x }));
|
44
|
|
- const data = {
|
45
|
|
- ...user,
|
46
|
|
- ...values,
|
47
|
|
- password,
|
48
|
|
-
|
49
|
|
- rolesList,
|
50
|
|
- userId: user.userId,
|
51
|
|
- };
|
52
|
|
-
|
53
|
|
- startLoading();
|
54
|
|
- postSysUser(data)
|
55
|
|
- .then((res) => {
|
56
|
|
- onSuccess();
|
57
|
|
- cancelLoading();
|
58
|
|
- })
|
59
|
|
- .catch(() => {
|
60
|
|
- cancelLoading();
|
61
|
|
- });
|
62
|
|
- };
|
63
|
|
-
|
64
|
|
- React.useEffect(() => {
|
65
|
|
- if (user?.userId) {
|
66
|
|
- form.setFieldsValue({
|
67
|
|
- account: user.account || undefined,
|
68
|
|
- rolesList: user.rolesList.map((x) => x.roleId),
|
69
|
|
- });
|
70
|
|
- }
|
71
|
|
- }, [user, form]);
|
72
|
|
-
|
73
|
|
- return (
|
74
|
|
- <Modal
|
75
|
|
- title="账号维护"
|
76
|
|
- footer={null}
|
77
|
|
- width={600}
|
78
|
|
- onCancel={onCancel}
|
79
|
|
- {...leftProps}
|
80
|
|
- >
|
81
|
|
- <Form
|
82
|
|
- {...formItemLayout}
|
83
|
|
- form={form}
|
84
|
|
- scrollToFirstError
|
85
|
|
- style={{ width: "480px" }}
|
86
|
|
- onFinish={onFinish}
|
87
|
|
- >
|
88
|
|
- <Form.Item
|
89
|
|
- name="account"
|
90
|
|
- label="账号"
|
91
|
|
- rules={[
|
92
|
|
- {
|
93
|
|
- required: true,
|
94
|
|
- message: "请填写姓名",
|
95
|
|
- },
|
96
|
|
- ]}
|
97
|
|
- >
|
98
|
|
- <Input />
|
99
|
|
- </Form.Item>
|
100
|
|
- <Form.Item name="rolesList" label="角色">
|
101
|
|
- <Select
|
102
|
|
- mode="multiple"
|
103
|
|
- allowClear
|
104
|
|
- style={{ width: "100%" }}
|
105
|
|
- placeholder="请选择角色"
|
106
|
|
- >
|
107
|
|
- {roleList.map((role) => (
|
108
|
|
- <Option key={role.roleId}>{role.name}</Option>
|
109
|
|
- ))}
|
110
|
|
- </Select>
|
111
|
|
- </Form.Item>
|
112
|
|
- <Form.Item
|
113
|
|
- // name="password"
|
114
|
|
- label="密码"
|
115
|
|
- // help={`默认密码 ${defaultPass}`}
|
116
|
|
- >
|
117
|
|
- <div>{`默认密码 ${defaultPass}`}</div>
|
118
|
|
- </Form.Item>
|
119
|
|
- <Form.Item {...tailFormItemLayout}>
|
120
|
|
- <Button loading={loading} type="primary" htmlType="submit">
|
121
|
|
- 保存
|
122
|
|
- </Button>
|
123
|
|
- <Button style={{ marginLeft: "2em" }} onClick={onCancel}>
|
124
|
|
- 取消
|
125
|
|
- </Button>
|
126
|
|
- </Form.Item>
|
127
|
|
- </Form>
|
128
|
|
- </Modal>
|
129
|
|
- );
|
130
|
|
-};
|