cfel-base-components 2.5.10 → 2.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,132 +1,271 @@
1
1
  import React, { useEffect, useState } from 'react'
2
- import {
3
- Button, Modal, Form, Input,
4
- } from 'antd';
5
- export default function index({
6
- ModalOpen, //弹框状态
7
- editOpenStatus, //关闭弹框
8
- editingData, //编辑数据
9
- actionFunc, //新增事件
10
- }: any) {
11
- const [form] = Form.useForm();
12
-
2
+ import { Button, Modal, Form, Input, Radio, Space, message } from 'antd'
3
+ let timeChange: any
13
4
 
14
- const formDom = [
15
- { title: "名称", key: 'name', type: 'string', required: true },
16
- { title: "手机号", key: 'mobile', type: 'mobileint', required: true },
17
- { title: "邮箱", key: 'email', type: 'emailstring', required: false },
18
- ]
19
- useEffect(() => {
20
- if (!ModalOpen) return
21
-
22
- if (editingData) {
23
- console.log(editingData, "editingData")
24
- form.setFieldsValue({
25
- ...editingData
26
- })
27
- }
28
- }, [ModalOpen])
5
+ export default function Index({
6
+ ModalOpen, //弹框状态
7
+ editOpenStatus, //关闭弹框
8
+ editingData, //编辑数据
9
+ actionFunc, //新增事件
10
+ accountGetAccountPasswordFunc //复制
11
+ }: any) {
12
+ const [form] = Form.useForm()
13
+ const [passwordType, setPasswordType] = useState('server')
14
+ const [loading, setLoading] = useState(false)
15
+ const [disabledType, setDisabledType] = useState(true)
16
+ const [secondNum, setSecondNum]: any = useState(null) //秒数
17
+ const [showText, setShowText] = useState('')
18
+ const formDom = [
19
+ { title: '名称', key: 'name', type: 'string', required: true },
20
+ { title: '账号', key: 'account', type: 'account', required: true },
21
+ { title: '密码', key: 'passwordType', type: 'psw', required: true },
22
+ { title: ' ', key: 'password', type: 'pswDiy', required: true },
23
+ { title: '手机号', key: 'mobile', type: 'mobileint', required: false },
24
+ { title: '邮箱', key: 'email', type: 'emailstring', required: false }
25
+ ]
26
+ const editFormDom = [
27
+ { title: '名称', key: 'name', type: 'rString', required: false },
28
+ { title: '账号', key: 'account', type: 'rString', required: false },
29
+ { title: '密码', key: 'passwordType', type: 'rPswString', required: false },
30
+ { title: '手机号', key: 'mobile', type: 'rString', required: false },
31
+ { title: '邮箱', key: 'email', type: 'rString', required: false }
32
+ ]
33
+ useEffect(() => {
34
+ clearInterval(timeChange)
35
+ return () => {
36
+ clearInterval(timeChange)
37
+ }
38
+ }, [])
39
+ useEffect(() => {
40
+ if (!editingData) return
41
+ init()
42
+ }, [editingData])
43
+ const init = () => {
44
+ setLoading(false)
45
+ setDisabledType(true)
46
+ setShowText('关闭(4s)')
47
+ timeChange = setInterval(
48
+ () =>
49
+ setSecondNum((t: any) => {
50
+ let num = t
51
+ console.log(t, 't')
52
+ return --num
53
+ }),
54
+ 1000
55
+ )
56
+ }
57
+ useEffect(() => {
58
+ console.log(secondNum, 'secondNum')
59
+ if (secondNum > 0 && secondNum <= 3) {
60
+ setShowText(`关闭(${secondNum}s)`)
61
+ } else {
62
+ clearInterval(timeChange)
63
+ setSecondNum(4)
64
+ setDisabledType(false)
65
+ setShowText('关闭')
66
+ }
67
+ }, [secondNum])
29
68
 
69
+ const showCom = ({ title, key, type, required }: any) => {
70
+ let dom: any = null
71
+ switch (type) {
72
+ case 'rString':
73
+ dom = <Form.Item label={title}>{editingData[key]}</Form.Item>
74
+ break
75
+ case 'rPswString':
76
+ dom = (
77
+ <Form.Item label={title}>
78
+ <span>
79
+ ********** <a onClick={() => copy()}>复制</a>
80
+ </span>
81
+ </Form.Item>
82
+ )
83
+ break
84
+ case 'string':
85
+ dom = (
86
+ <Form.Item label={title} name={key} rules={[{ required: required, message: '请输入' }]}>
87
+ <Input placeholder='请输入' />
88
+ </Form.Item>
89
+ )
90
+ break
30
91
 
31
- const showCom = ({ title, key, type, required }: any) => {
32
- let dom: any = null
33
- switch (type) {
34
- case 'string':
35
- dom = (<Form.Item
36
- label={title}
37
- name={key}
38
- rules={[{ required: required, message: '请输入' }]}
39
- >
40
- <Input placeholder="请输入" />
41
- </Form.Item>)
42
- break;
43
- case 'emailstring':
44
- dom = (<Form.Item
45
- label={title}
46
- name={key}
47
- rules={[
48
- { required: required, message: '请输入' },
49
- { pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, message: '请输入正确的邮箱' }
50
- ]}
51
- >
52
- <Input placeholder="请输入" />
53
- </Form.Item>)
54
- break;
55
- case 'mobileint':
56
- dom = (<Form.Item
57
- label={title}
58
- name={key}
59
- rules={
60
- editingData ? [{ required: required, message: '请输入' }] : [
61
- { required: required, message: '请输入' },
62
- { pattern: /1[0-9]{10}$/, message: '请输入正确的电话号码' }
63
- ]}
64
- >
65
- <Input placeholder="请输入"
66
- disabled={editingData ? true : false} />
67
- </Form.Item>)
68
- break;
69
- default:
70
- break;
71
- }
72
- return dom
92
+ case 'account':
93
+ dom = (
94
+ <Form.Item label={title} name={key} rules={[{ required: required, message: '请输入' }]}>
95
+ <Input placeholder='请输入' addonAfter={`@${(window as any).g_config?.tenant?.id}.oncfel.com`} />
96
+ </Form.Item>
97
+ )
98
+ break
99
+ case 'psw':
100
+ dom = (
101
+ <Form.Item label={title} name={key} rules={[{ required: required, message: '请输入' }]}>
102
+ <Radio.Group>
103
+ <Space
104
+ direction='vertical'
105
+ onChange={(e: any) => {
106
+ setPasswordType(e.target.value)
107
+ }}
108
+ >
109
+ <Radio value='server'>生成随机密码(安全性高)</Radio>
110
+ <Radio value='diy'>自定义密码</Radio>
111
+ </Space>
112
+ </Radio.Group>
113
+ </Form.Item>
114
+ )
115
+ break
116
+ case 'pswDiy':
117
+ dom = passwordType === 'diy' && (
118
+ <Form.Item
119
+ label={null}
120
+ name={key}
121
+ rules={[
122
+ { required: required, message: '请输入' },
123
+ {
124
+ pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_+{}|]{8,32}$/,
125
+ message: '请输入正确的密码'
126
+ }
127
+ ]}
128
+ extra='密码要求至少包含英文字母和数字,字符数8-32位'
129
+ >
130
+ <Input placeholder='请输入' />
131
+ </Form.Item>
132
+ )
133
+ break
134
+ case 'emailstring':
135
+ dom = (
136
+ <Form.Item
137
+ label={title}
138
+ name={key}
139
+ rules={[
140
+ { required: required, message: '请输入' },
141
+ {
142
+ pattern:
143
+ /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
144
+ message: '请输入正确的邮箱'
145
+ }
146
+ ]}
147
+ >
148
+ <Input placeholder='请输入' />
149
+ </Form.Item>
150
+ )
151
+ break
152
+ case 'mobileint':
153
+ dom = (
154
+ <Form.Item
155
+ label={title}
156
+ name={key}
157
+ rules={[
158
+ { required: required, message: '请输入' },
159
+ { pattern: /1[0-9]{10}$/, message: '请输入正确的电话号码' }
160
+ ]}
161
+ >
162
+ <Input placeholder='请输入' />
163
+ </Form.Item>
164
+ )
165
+ break
166
+ default:
167
+ break
73
168
  }
74
-
75
- const closeModel = () => {
76
- form.resetFields()
77
- editOpenStatus(false)
169
+ return dom
170
+ }
171
+ const copy = () => {
172
+ accountGetAccountPasswordFunc({
173
+ id: editingData?.id
174
+ }).then((res: any) => {
175
+ message.success('复制成功')
176
+ navigator.clipboard.writeText(res)
177
+ })
178
+ }
179
+ const closeModel = () => {
180
+ form.resetFields()
181
+ editOpenStatus(false)
182
+ }
183
+ const generateRandomString = (minLength = 8, maxLength = 32) => {
184
+ const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength
185
+ const possibleChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
186
+ let result = ''
187
+ for (let i = 0; i < length; i++) {
188
+ result += possibleChars.charAt(Math.floor(Math.random() * possibleChars.length))
78
189
  }
190
+ return result
191
+ }
79
192
 
80
- const modelSubmit = () => {
81
- form.validateFields().then((value) => {
82
- console.log(value, "value")
83
- if (editingData) {
84
- value.id = editingData.id
85
- }
86
- actionFunc(value, editingData ? "edit" : "add").then(() => {
87
- form.resetFields()
88
- })
89
- })
90
- }
91
- return (
92
- <Modal title={editingData ? "编辑账号" : "新增账号"}
93
- destroyOnClose={true}
94
- open={ModalOpen}
95
- onCancel={() => {
96
- closeModel()
97
- }}
98
- footer={[
99
- <Button
100
- key="refresh"
101
- onClick={() => {
102
- closeModel()
103
- }}
104
- >
105
- 取消
106
- </Button>,
107
- <Button
108
- key="submit"
109
- type="primary"
110
- onClick={() => {
111
- modelSubmit()
112
- }}
113
- >
114
- 确定
115
- </Button>,
116
- ]}
117
- >
118
- <Form
119
- form={form}
120
- layout={'vertical'}
121
- initialValues={{ remember: true }}
122
- autoComplete="off"
123
- >
124
- {
125
- formDom.map((item: any, index: number) => {
126
- return <div key={index}>{showCom(item)}</div>
127
- })
128
- }
129
- </Form>
130
- </Modal>
131
- )
193
+ const modelSubmit = () => {
194
+ form.validateFields().then(value => {
195
+ setLoading(true)
196
+ value.account = `${value.account}@${(window as any).g_config?.tenant?.id}.oncfel.com`
197
+ if (value.passwordType === 'server') {
198
+ value.password = generateRandomString()
199
+ }
200
+ delete value.passwordType
201
+ actionFunc(value, 'add').then(() => setLoading(false))
202
+ })
203
+ }
204
+ return (
205
+ <Modal
206
+ title={editingData ? '查看' : '新增账号'}
207
+ destroyOnClose={true}
208
+ open={ModalOpen}
209
+ closable={false}
210
+ footer={
211
+ editingData
212
+ ? [
213
+ <Button
214
+ disabled={disabledType}
215
+ key='refresh'
216
+ type='primary'
217
+ onClick={() => {
218
+ closeModel()
219
+ }}
220
+ >
221
+ {showText}
222
+ </Button>
223
+ ]
224
+ : [
225
+ <Button
226
+ key='refresh'
227
+ onClick={() => {
228
+ closeModel()
229
+ }}
230
+ >
231
+ 取消
232
+ </Button>,
233
+ <Button
234
+ key='submit'
235
+ type='primary'
236
+ loading={loading}
237
+ onClick={() => {
238
+ modelSubmit()
239
+ }}
240
+ >
241
+ 确定
242
+ </Button>
243
+ ]
244
+ }
245
+ >
246
+ <Form
247
+ form={form}
248
+ layout={editingData ? 'horizontal' : 'vertical'}
249
+ initialValues={{
250
+ remember: true,
251
+ passwordType: 'server'
252
+ }}
253
+ autoComplete='off'
254
+ >
255
+ {editingData ? (
256
+ <>
257
+ {editFormDom.map((item: any, index: number) => {
258
+ return <div key={index}>{showCom(item)}</div>
259
+ })}
260
+ </>
261
+ ) : (
262
+ <>
263
+ {formDom.map((item: any, index: number) => {
264
+ return <div key={index}>{showCom(item)}</div>
265
+ })}
266
+ </>
267
+ )}
268
+ </Form>
269
+ </Modal>
270
+ )
132
271
  }
@@ -0,0 +1,232 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { Button, Modal, Form, Input, Radio, Space, message } from 'antd'
3
+ let timeChange: any
4
+
5
+ export default function Index({
6
+ ModalOpen, //弹框状态
7
+ editOpenStatus, //关闭弹框
8
+ editingData, //编辑数据
9
+ actionFunc, //新增事件
10
+ accountGetAccountPasswordFunc
11
+ }: any) {
12
+ const [form] = Form.useForm()
13
+ const [passwordType, setPasswordType] = useState('server')
14
+ const [loading, setLoading] = useState(false)
15
+ const [disabledType, setDisabledType] = useState(true)
16
+ const [secondNum, setSecondNum]: any = useState(null) //秒数
17
+ const [showText, setShowText] = useState('')
18
+ const [stepNext, setStepNext] = useState(false)
19
+ const formDom = [
20
+ { title: '账号', key: 'account', type: 'account', required: true },
21
+ { title: '密码', key: 'passwordType', type: 'psw', required: true },
22
+ { title: ' ', key: 'password', type: 'pswDiy', required: true }
23
+ ]
24
+ const nextFormDom = [
25
+ { title: '账号', key: 'account', type: 'rString', required: false },
26
+ { title: '密码', key: 'passwordType', type: 'rPwString', required: false }
27
+ ]
28
+ useEffect(() => {
29
+ return () => {
30
+ clearInterval(timeChange)
31
+ }
32
+ }, [])
33
+
34
+ const init = () => {
35
+ setLoading(false)
36
+ setDisabledType(true)
37
+ setShowText('关闭(4s)')
38
+ timeChange = setInterval(
39
+ () =>
40
+ setSecondNum((t: any) => {
41
+ let num = t
42
+ console.log(t, 't')
43
+ return --num
44
+ }),
45
+ 1000
46
+ )
47
+ }
48
+ useEffect(() => {
49
+ console.log(secondNum, 'secondNum')
50
+ if (secondNum > 0 && secondNum <= 3) {
51
+ setShowText(`关闭(${secondNum}s)`)
52
+ } else {
53
+ clearInterval(timeChange)
54
+ setSecondNum(4)
55
+ setDisabledType(false)
56
+ setShowText('关闭')
57
+ }
58
+ }, [secondNum])
59
+
60
+ useEffect(() => {
61
+ if (!ModalOpen) return
62
+ if (editingData) {
63
+ console.log(editingData, 'editingData')
64
+ clearInterval(timeChange)
65
+ form.setFieldsValue({
66
+ ...editingData
67
+ })
68
+ }
69
+ }, [ModalOpen])
70
+
71
+ const showCom = ({ title, key, type, required }: any) => {
72
+ let dom: any = null
73
+ switch (type) {
74
+ case 'rString':
75
+ dom = (
76
+ <Form.Item label={title} name={key} rules={[{ required: required, message: '请输入' }]}>
77
+ <span>{editingData?.[key]}</span>
78
+ </Form.Item>
79
+ )
80
+ break
81
+ case 'rPwString':
82
+ dom = (
83
+ <Form.Item label={title} name={key} rules={[{ required: required, message: '请输入' }]}>
84
+ <span>
85
+ ******* <a onClick={() => copy()}>复制</a>
86
+ </span>
87
+ </Form.Item>
88
+ )
89
+ break
90
+ case 'account':
91
+ dom = (
92
+ <Form.Item label={title} name={key} rules={[{ required: required, message: '请输入' }]}>
93
+ <Input placeholder='请输入' disabled />
94
+ </Form.Item>
95
+ )
96
+ break
97
+ case 'psw':
98
+ dom = (
99
+ <Form.Item label={title} name={key} rules={[{ required: required, message: '请输入' }]}>
100
+ <Radio.Group>
101
+ <Space
102
+ direction='vertical'
103
+ onChange={(e: any) => {
104
+ setPasswordType(e.target.value)
105
+ }}
106
+ >
107
+ <Radio value='server'>生成随机密码(安全性高)</Radio>
108
+ <Radio value='diy'>自定义密码</Radio>
109
+ </Space>
110
+ </Radio.Group>
111
+ </Form.Item>
112
+ )
113
+ break
114
+ case 'pswDiy':
115
+ dom = passwordType === 'diy' && (
116
+ <Form.Item
117
+ label={null}
118
+ name={key}
119
+ rules={[
120
+ { required: required, message: '请输入' },
121
+ {
122
+ pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!@#$%^&*()_+{}|]{8,32}$/,
123
+ message: '请输入正确的密码'
124
+ }
125
+ ]}
126
+ extra='密码要求至少包含英文字母和数字,字符数8-32位'
127
+ >
128
+ <Input placeholder='请输入' />
129
+ </Form.Item>
130
+ )
131
+ break
132
+ default:
133
+ break
134
+ }
135
+ return dom
136
+ }
137
+ const copy = () => {
138
+ accountGetAccountPasswordFunc({
139
+ id: editingData?.id
140
+ }).then((res: any) => {
141
+ message.success('复制成功')
142
+ navigator.clipboard.writeText(res)
143
+ })
144
+ }
145
+ const closeModel = () => {
146
+ form.resetFields()
147
+ editOpenStatus(false)
148
+ setStepNext(false)
149
+ }
150
+ const generateRandomString = (minLength = 8, maxLength = 32) => {
151
+ const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength
152
+ const possibleChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
153
+ let result = ''
154
+ for (let i = 0; i < length; i++) {
155
+ result += possibleChars.charAt(Math.floor(Math.random() * possibleChars.length))
156
+ }
157
+ return result
158
+ }
159
+
160
+ const modelSubmit = () => {
161
+ form.validateFields().then(value => {
162
+ if (value.passwordType === 'server') {
163
+ value.password = generateRandomString()
164
+ }
165
+ actionFunc({
166
+ id: editingData?.id,
167
+ newPassword: value.password
168
+ }).then(() => {
169
+ // form.resetFields()
170
+ setStepNext(true)
171
+ init()
172
+ })
173
+ })
174
+ }
175
+ return (
176
+ <Modal
177
+ title={'重置密码'}
178
+ destroyOnClose={true}
179
+ open={ModalOpen}
180
+ closable={false}
181
+ footer={
182
+ stepNext
183
+ ? [
184
+ <Button
185
+ disabled={disabledType}
186
+ key='refresh'
187
+ type='primary'
188
+ onClick={() => {
189
+ closeModel()
190
+ }}
191
+ >
192
+ {showText}
193
+ </Button>
194
+ ]
195
+ : [
196
+ <Button
197
+ key='refresh'
198
+ onClick={() => {
199
+ closeModel()
200
+ }}
201
+ >
202
+ 取消
203
+ </Button>,
204
+ <Button
205
+ key='submit'
206
+ type='primary'
207
+ loading={loading}
208
+ onClick={() => {
209
+ modelSubmit()
210
+ }}
211
+ >
212
+ 确定
213
+ </Button>
214
+ ]
215
+ }
216
+ >
217
+ <Form
218
+ form={form}
219
+ layout={'vertical'}
220
+ initialValues={{
221
+ remember: true,
222
+ passwordType: 'server'
223
+ }}
224
+ autoComplete='off'
225
+ >
226
+ {(stepNext ? nextFormDom : formDom).map((item: any, index: number) => {
227
+ return <div key={index}>{showCom(item)}</div>
228
+ })}
229
+ </Form>
230
+ </Modal>
231
+ )
232
+ }
@@ -1,18 +1,34 @@
1
1
  import request from "../../../apiRequest/config"
2
2
 
3
+
3
4
  //分页查询账号
4
- export const accountPage= (data?: any) => {
5
- return request.post("/api/permission/account/page.json", { ...data })
6
- }
7
- //指定租户下创建账号
8
- export const accountCreateAccount = (data?: any) => {
9
- return request.post("/api/permission/account/createAccount.json", { ...data })
10
- }
11
- //指定租户下修改账号
12
- export const accountUpdateAccount = (data?: any) => {
13
- return request.post("/api/permission/account/updateAccount.json", { ...data })
14
- }
15
- //指定租户下删除账号
16
- export const accountDeleteAccount = (data?: any) => {
17
- return request.get("/api/permission/account/deleteAccount.json", { params:{...data} })
18
- }
5
+ export const accountPage = (data?: any) => {
6
+ return request.post('/sdk/permission/rbac/console/account/page.json', { ...data })
7
+ }
8
+ //指定租户下创建账号
9
+ export const accountCreateAccount = (data?: any) => {
10
+ return request.post('/sdk/permission/rbac/console/account/createAccount.json', { ...data })
11
+ }
12
+ //指定租户下修改账号
13
+ export const accountUpdateAccount = (data?: any) => {
14
+ return request.post('/api/permission/account/updateAccount.json', { ...data })
15
+ }
16
+ //指定租户下删除账号
17
+ export const accountDeleteAccount = (data?: any) => {
18
+ return request.get('/sdk/permission/rbac/console/account/deleteAccount.json', {
19
+ params: { ...data }
20
+ })
21
+ }
22
+ //按账号id查询账号信息
23
+ export const accountGetAccount = (data?: any) => {
24
+ return request.post('/sdk/permission/rbac/console/account/getAccount.json', { ...data })
25
+ }
26
+ //按账号id查询账号信息
27
+ export const accountGetAccountPassword = (data?: any) => {
28
+ return request.post('/sdk/permission/rbac/console/account/getAccountPassword.json', { ...data })
29
+ }
30
+ //按账号id查询账号信息
31
+ export const accountResetPw = (data?: any) => {
32
+ return request.post('/sdk/permission/rbac/console/account/resetPw.json', { ...data })
33
+ }
34
+