cfel-base-components 2.5.11 → 2.5.12

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,271 +1,132 @@
1
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 //复制
2
+ import {
3
+ Button, Modal, Form, Input,
4
+ } from 'antd';
5
+ export default function index({
6
+ ModalOpen, //弹框状态
7
+ editOpenStatus, //关闭弹框
8
+ editingData, //编辑数据
9
+ actionFunc, //新增事件
11
10
  }: 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])
11
+ const [form] = Form.useForm();
68
12
 
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
91
13
 
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
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])
29
+
30
+
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
168
73
  }
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))
74
+
75
+ const closeModel = () => {
76
+ form.resetFields()
77
+ editOpenStatus(false)
189
78
  }
190
- return result
191
- }
192
79
 
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
- )
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
+ )
271
132
  }
@@ -1,34 +1,18 @@
1
1
  import request from "../../../apiRequest/config"
2
2
 
3
-
4
3
  //分页查询账号
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
-
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
+ }