cfel-base-components 2.5.12 → 2.5.14

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.
@@ -0,0 +1,240 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { Button, Modal, Form, Input, Radio, Space, message, Alert } 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
+ {stepNext && (
218
+ <Alert
219
+ description='新的重置密码仅可本弹窗时复制,关闭后不可再复制,请及时保存'
220
+ type='info'
221
+ showIcon
222
+ style={{ marginBottom: '20px' }}
223
+ />
224
+ )}
225
+ <Form
226
+ form={form}
227
+ layout={'vertical'}
228
+ initialValues={{
229
+ remember: true,
230
+ passwordType: 'server'
231
+ }}
232
+ autoComplete='off'
233
+ >
234
+ {(stepNext ? nextFormDom : formDom).map((item: any, index: number) => {
235
+ return <div key={index}>{showCom(item)}</div>
236
+ })}
237
+ </Form>
238
+ </Modal>
239
+ )
240
+ }
@@ -1,18 +1,38 @@
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
+ //更新账号
35
+ export const updateAccount = (data?: any) => {
36
+ return request.post('/sdk/permission/rbac/console/account/updateAccount.json', { ...data })
37
+ }
38
+
@@ -1,31 +1,48 @@
1
- import React, { useEffect, useRef, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react'
2
+
2
3
  import PageContainer from '../../base-component/PageContainer';
3
4
  import QueryFilter from '../../base-component/QueryFilter';
4
5
  import ProTable from '../../base-component/ProTable';
5
6
  import Pagination from '../../base-component/Pagination';
6
- import { ProFormText, } from '@ant-design/pro-components';
7
- import { Space, Button, message,Modal } from 'antd';
8
- import { get } from 'lodash';
9
- import { timeFormatter } from '../../../utils';
10
7
  import useTableHooks from "../../../hooks/useTableHooks"
8
+ import { timeFormatter, getUrlParams } from '../../../utils';
9
+
10
+ import { ProFormText } from '@ant-design/pro-components'
11
+ import { Space, Button, message, Modal } from 'antd'
12
+ import { get } from 'lodash'
13
+
14
+ import { FormOutlined } from '@ant-design/icons'
11
15
  import {
12
- accountPage, accountCreateAccount,
13
- accountUpdateAccount, accountDeleteAccount
14
- } from "./api"
16
+ accountPage,
17
+ accountCreateAccount,
18
+ accountUpdateAccount,
19
+ accountDeleteAccount,
20
+ accountGetAccount,
21
+ accountGetAccountPassword,
22
+ accountResetPw,
23
+ updateAccount
24
+ } from './api'
15
25
  import AddModal from './AddModal'
16
- import "./index.scss"
26
+ import ResetModal from './ResetModal'
27
+ import EditNameModal from './EditNameModal'
28
+
29
+ import './index.scss'
17
30
 
18
31
  export interface AccountProps {
19
- historyAction: any;
32
+ historyAction: any
20
33
  }
21
34
 
22
- export default function Account({
23
- historyAction
24
- }: AccountProps) {
35
+ export default function Account({ historyAction }: AccountProps) {
25
36
  const searchFormRef: any = useRef()
26
37
 
27
38
  const [ModalOpen, setModalOpen] = useState(false)
28
- const [editingData, setEditingData] = useState(null);//编辑数据
39
+ const [editingData, setEditingData]: any = useState(null) //编辑数据
40
+
41
+ const [resetModalOpen, setResetModalOpen] = useState(false)
42
+ const [resetEditingData, setResetEditingData]: any = useState(null) //编辑数据
43
+
44
+ const [editNameModalOpen, setEditNameModalOpen] = useState(false)
45
+ const [editNameData, setEditNameData]: any = useState(null) //编辑数据
29
46
 
30
47
  useEffect(() => {
31
48
  execute()
@@ -38,41 +55,22 @@ export default function Account({
38
55
  key: 'name',
39
56
  render: (text: any, data: any) => {
40
57
  return (
41
- <span
42
- style={{ cursor: "pointer", color: "#1677ff" }}
43
- onClick={() => {
44
- historyAction?.push({
45
- pathname: `/account-info`,
46
- search: `?id=${data.id}`,
47
- });
48
- }}
49
- >
50
- {data?.name}
51
- </span>
52
- );
53
- },
58
+ <Space>
59
+ <span>{data?.name}</span>
60
+ <FormOutlined
61
+ style={{ cursor: 'pointer', color: '#1677ff' }}
62
+ onClick={() => openEditName(data)}
63
+ />
64
+ </Space>
65
+ )
66
+ }
54
67
  },
55
68
  {
56
69
  title: '账号',
57
70
  dataIndex: 'account',
58
- key: 'account',
59
- },
60
- {
61
- title: '工号',
62
- dataIndex: 'jobNumber',
63
- key: 'jobNumber',
64
- },
65
- {
66
- title: '手机号',
67
- dataIndex: 'mobile',
68
- key: 'mobile',
69
- },
70
- {
71
- title: '邮箱',
72
- dataIndex: 'email',
73
- key: 'email',
74
- ellipsis: true,
71
+ key: 'account'
75
72
  },
73
+
76
74
  {
77
75
  title: '是否主账号',
78
76
  dataIndex: 'isAdmin',
@@ -107,39 +105,48 @@ export default function Account({
107
105
  fixed: 'right',
108
106
  width: 150,
109
107
  render: (rowdata: any) => (
110
-
111
108
  <Space>
112
- <a onClick={() => {
113
- setEditingData(rowdata)
114
- setModalOpen(true)
115
- }} >编辑</a>
109
+ <a
110
+ onClick={() => {
111
+ setResetEditingData(rowdata)
112
+ setResetModalOpen(true)
113
+ }}
114
+ >
115
+ 重置密码
116
+ </a>
116
117
  <a
117
118
  onClick={() => {
118
119
  historyAction?.push({
119
120
  pathname: `/account-info`,
120
- search: `?id=${rowdata.id}`,
121
- });
121
+ search: `?id=${rowdata.id}`
122
+ })
122
123
  }}
123
124
  >
124
125
  配置
125
126
  </a>
126
- <a onClick={() => {
127
- Modal.confirm({
128
- title: `确认删除${rowdata?.name}吗?`,
129
- onOk: () => {
130
- DeleteFunc(rowdata?.id)
131
- }
132
- })
133
- }} >删除</a>
127
+ {rowdata.isAdmin ? null : (
128
+ <a
129
+ onClick={() => {
130
+ Modal.confirm({
131
+ title: `确认删除${rowdata?.name}吗?`,
132
+ onOk: () => {
133
+ DeleteFunc(rowdata?.id)
134
+ }
135
+ })
136
+ }}
137
+ >
138
+ 删除
139
+ </a>
140
+ )}
134
141
  </Space>
135
- ),
136
- },
137
- ];
142
+ )
143
+ }
144
+ ]
138
145
 
139
146
  const handleOnReset: any = async (values: any) => {
140
147
  searchFormRef.current = { ...values }
141
148
  execute({
142
- innerPageNo: 1,
149
+ innerPageNo: 1
143
150
  })
144
151
  }
145
152
 
@@ -148,17 +155,14 @@ export default function Account({
148
155
  execute()
149
156
  }
150
157
 
151
- const readDataList = ({
152
- innerPageNo,
153
- innerPageSize,
154
- }: any) => {
158
+ const readDataList = ({ innerPageNo, innerPageSize }: any) => {
155
159
  return accountPage({
156
160
  currentPage: innerPageNo,
157
161
  pageSize: innerPageSize,
158
- ...searchFormRef.current,
162
+ ...searchFormRef.current
159
163
  }).then((res: any) => {
160
- let records = get(res, "records", [])
161
- let total = get(res, "total", 0)
164
+ let records = get(res, 'records', [])
165
+ let total = get(res, 'total', 0)
162
166
  return {
163
167
  ...res,
164
168
  dataList: records,
@@ -179,63 +183,111 @@ export default function Account({
179
183
  setEditingData(null)
180
184
  }
181
185
  const actionFunc = (data: any, type: string) => {
182
- return (type == 'add' ? accountCreateAccount : accountUpdateAccount)({ ...data }).then((res) => {
183
- message.success(`${type == 'add' ? '新增' : '更新'}成功`)
184
- setModalOpen(false)
185
- setEditingData(null)
186
+ return accountCreateAccount({ ...data }).then((res: any) => {
187
+ message.success(`新增成功`)
188
+ accountGetAccountFunc(res)
186
189
  execute()
187
190
  })
188
191
  }
189
- const DeleteFunc = (id:any)=>{
192
+ const accountGetAccountFunc = (id: any) => {
193
+ accountGetAccount({
194
+ id
195
+ }).then((res: any) => {
196
+ setEditingData(res)
197
+ })
198
+ }
199
+ const DeleteFunc = (id: any) => {
190
200
  accountDeleteAccount({
191
- id,
201
+ id
192
202
  }).then((res: any) => {
193
- message.success('删除成功')
194
- execute()
195
- })
196
- }
203
+ message.success('删除成功')
204
+ execute()
205
+ })
206
+ }
207
+ const accountGetAccountPasswordFunc = (data: any) => {
208
+ return accountGetAccountPassword(data)
209
+ }
210
+
211
+ const actionResetFunc = (data: any) => {
212
+ return accountResetPw({ ...data }).then((res: any) => {
213
+ message.success(`重置成功`)
214
+ })
215
+ }
216
+ const setResetModalOpenFunc = (type: boolean) => {
217
+ setResetModalOpen(type)
218
+ setResetEditingData(null)
219
+ }
220
+
221
+ const openEditName = (data: any) => {
222
+ setEditNameModalOpen(true)
223
+ setEditNameData(data)
224
+ }
225
+ const setEditModalOpenFunc = (type: boolean) => {
226
+ setEditNameModalOpen(type)
227
+ setEditNameData(null)
228
+ }
229
+ const actionEditFunc = (data: any) => {
230
+ return updateAccount({ ...data }).then((res: any) => {
231
+ message.success(`更新名称成功`)
232
+ setEditModalOpenFunc(false)
233
+ execute()
234
+ })
235
+ }
197
236
  return (
198
237
  <PageContainer>
199
- <QueryFilter
200
- onReset={handleOnReset}
201
- onFinish={handleOnFinish}
202
- >
203
- <ProFormText name="name" label="名称" />
204
- <ProFormText name="account" label="账号" />
238
+ <QueryFilter onReset={handleOnReset} onFinish={handleOnFinish}>
239
+ <ProFormText name='name' label='名称' />
240
+ <ProFormText name='account' label='账号' />
205
241
  </QueryFilter>
206
242
  <ProTable
207
- columnsState={{
208
- persistenceKey: 'base_cpcAccount',
209
- persistenceType: 'localStorage'
210
- }}
243
+ columnsState={{
244
+ persistenceKey: 'base_cpcAccount',
245
+ persistenceType: 'localStorage'
246
+ }}
211
247
  toolBarRender={() => {
212
248
  return [
213
249
  <Button
214
- type="primary"
250
+ key='add'
251
+ type='primary'
215
252
  onClick={() => {
216
253
  setModalOpen(true)
217
254
  }}
218
255
  >
219
256
  新增账号
220
- </Button>,
221
- ];
257
+ </Button>
258
+ ]
222
259
  }}
223
- headerTitle={"账号列表"}
260
+ headerTitle={'账号列表'}
224
261
  dataSource={dataList}
225
262
  loading={isLoading}
226
263
  columns={columns}
227
- rowKey="id"
264
+ rowKey='id'
228
265
  options={{
229
266
  reload: handleRoload
230
267
  }}
231
268
  />
269
+
270
+ <Pagination {...pagination} />
271
+ <ResetModal
272
+ ModalOpen={resetModalOpen} //弹框状态
273
+ editOpenStatus={setResetModalOpenFunc} //关闭弹框
274
+ editingData={resetEditingData} //编辑数据
275
+ actionFunc={actionResetFunc} //新增事件
276
+ accountGetAccountPasswordFunc={accountGetAccountPasswordFunc}
277
+ />
232
278
  <AddModal
233
279
  ModalOpen={ModalOpen}
234
280
  editOpenStatus={setModalOpenFunc} //修改状态事件
235
281
  editingData={editingData} //当前数据
236
- actionFunc={actionFunc}//事件
282
+ actionFunc={actionFunc} //事件
283
+ accountGetAccountPasswordFunc={accountGetAccountPasswordFunc}
284
+ />
285
+ <EditNameModal
286
+ ModalOpen={editNameModalOpen} //弹框状态
287
+ editOpenStatus={setEditModalOpenFunc} //关闭弹框
288
+ editingData={editNameData} //编辑数据
289
+ actionFunc={actionEditFunc} //新增事件
237
290
  />
238
- <Pagination {...pagination} />
239
291
  </PageContainer>
240
292
  )
241
293
  }
@@ -130,6 +130,7 @@ export default function AccountInfo({ isShowTab, getAuthTree, getAccountAuthTree
130
130
  fixed: 'right',
131
131
  render: (rowdata: any) => (
132
132
  <Space>
133
+ {accountInfo?.isAdmin && rowdata.roleCode === 'admin' ? null : (
133
134
  <a
134
135
  onClick={() => {
135
136
  Modal.confirm({
@@ -143,7 +144,8 @@ export default function AccountInfo({ isShowTab, getAuthTree, getAccountAuthTree
143
144
  >
144
145
  解绑
145
146
  </a>
146
- </Space>
147
+ )}
148
+ </Space>
147
149
  )
148
150
  }
149
151
  ]
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
2
2
  import {
3
3
  Button, Modal, Form, Input,
4
4
  } from 'antd';
5
- export default function index({
5
+ export default function Index({
6
6
  ModalOpen, //弹框状态
7
7
  editOpenStatus, //关闭弹框
8
8
  editingData, //编辑数据