cfel-base-components 2.0.11 → 2.0.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.
- package/demo/src/index.jsx +3 -3
- package/package.json +1 -1
- package/src/components/universal-pages/cpcRole/AddModal/index.tsx +116 -0
- package/src/components/universal-pages/cpcRole/api.ts +16 -0
- package/src/components/universal-pages/cpcRole/index.scss +0 -0
- package/src/components/universal-pages/cpcRole/index.tsx +204 -0
- package/src/components/universal-pages/cpcRoleInfo/EditAccountDrawer/index.tsx +111 -0
- package/src/components/universal-pages/cpcRoleInfo/api.ts +22 -0
- package/src/components/universal-pages/cpcRoleInfo/index.scss +3 -0
- package/src/components/universal-pages/cpcRoleInfo/index.tsx +246 -0
- package/src/index.tsx +6 -2
package/demo/src/index.jsx
CHANGED
|
@@ -6,9 +6,9 @@ import { SwapOutlined, } from '@ant-design/icons';
|
|
|
6
6
|
import './index.scss';
|
|
7
7
|
import PageContainer from '../../src/components/base-component/PageContainer';
|
|
8
8
|
import Layout from '../../src/components/layout';
|
|
9
|
-
import Account from '../../src/components/universal-pages/account';
|
|
9
|
+
// import Account from '../../src/components/universal-pages/account';
|
|
10
10
|
// import AccountInfo from '../../src/components/universal-pages/accountInfo';
|
|
11
|
-
|
|
11
|
+
import CpcRole from '../../src/components/universal-pages/cpcRole';
|
|
12
12
|
// import RoleInfo from '../../src/components/universal-pages/roleInfo';
|
|
13
13
|
|
|
14
14
|
const App = () => {
|
|
@@ -47,7 +47,7 @@ const App = () => {
|
|
|
47
47
|
logoutUrl={(window)?.g_config?.logoutUrl}
|
|
48
48
|
switchTenantUrl={(window)?.g_config?.switchTenantUrl}
|
|
49
49
|
>
|
|
50
|
-
<
|
|
50
|
+
<CpcRole></CpcRole>
|
|
51
51
|
</Layout>
|
|
52
52
|
</PageContainer>
|
|
53
53
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
|
|
13
|
+
const { TextArea } = Input;
|
|
14
|
+
|
|
15
|
+
const formDom = [
|
|
16
|
+
{ title: "角色名称", key: 'roleName', type: 'string', required: true },
|
|
17
|
+
{ title: "描述", key: 'description', type: 'descriptionstring', 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 'descriptionstring':
|
|
44
|
+
dom = (<Form.Item
|
|
45
|
+
label={title}
|
|
46
|
+
name={key}
|
|
47
|
+
rules={[{ required: required, message: '请输入' }]}
|
|
48
|
+
>
|
|
49
|
+
<TextArea rows={3} placeholder="请输入"/>
|
|
50
|
+
</Form.Item>)
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
default:
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
return dom
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const closeModel = () => {
|
|
60
|
+
form.resetFields()
|
|
61
|
+
editOpenStatus(false)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const modelSubmit = () => {
|
|
65
|
+
form.validateFields().then((value) => {
|
|
66
|
+
console.log(value, "value")
|
|
67
|
+
if (editingData) {
|
|
68
|
+
value.roleCode = editingData.roleCode
|
|
69
|
+
}
|
|
70
|
+
actionFunc(value, editingData ? "edit" : "add").then(() => {
|
|
71
|
+
form.resetFields()
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
return (
|
|
76
|
+
<Modal title={editingData ? "编辑角色" : "新增角色"}
|
|
77
|
+
destroyOnClose={true}
|
|
78
|
+
open={ModalOpen}
|
|
79
|
+
onCancel={() => {
|
|
80
|
+
closeModel()
|
|
81
|
+
}}
|
|
82
|
+
footer={[
|
|
83
|
+
<Button
|
|
84
|
+
key="refresh"
|
|
85
|
+
onClick={() => {
|
|
86
|
+
closeModel()
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
取消
|
|
90
|
+
</Button>,
|
|
91
|
+
<Button
|
|
92
|
+
key="submit"
|
|
93
|
+
type="primary"
|
|
94
|
+
onClick={() => {
|
|
95
|
+
modelSubmit()
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
确定
|
|
99
|
+
</Button>,
|
|
100
|
+
]}
|
|
101
|
+
>
|
|
102
|
+
<Form
|
|
103
|
+
form={form}
|
|
104
|
+
layout={'vertical'}
|
|
105
|
+
initialValues={{ remember: true }}
|
|
106
|
+
autoComplete="off"
|
|
107
|
+
>
|
|
108
|
+
{
|
|
109
|
+
formDom.map((item: any, index: number) => {
|
|
110
|
+
return <div key={index}>{showCom(item)}</div>
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
</Form>
|
|
114
|
+
</Modal>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import request from "../../../apiRequest/config"
|
|
2
|
+
|
|
3
|
+
export const pageRequest = (data?: any) => {
|
|
4
|
+
return request.post("/api/permission/role/page.json", { ...data })
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const create = (data?: any) => {
|
|
8
|
+
return request.post("/api/permission/role/create.json", { ...data })
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const remove = (data?: any) => {
|
|
12
|
+
return request.post("/api/permission/role/remove.json", { ...data })
|
|
13
|
+
}
|
|
14
|
+
export const update = (data?: any) => {
|
|
15
|
+
return request.post("/api/permission/role/update.json", { ...data })
|
|
16
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import useTableHooks from "../../../hooks/useTableHooks"
|
|
3
|
+
|
|
4
|
+
import PageContainer from '../../base-component/PageContainer';
|
|
5
|
+
import QueryFilter from '../../base-component/QueryFilter';
|
|
6
|
+
import ProTable from '../../base-component/ProTable';
|
|
7
|
+
import Pagination from '../../base-component/Pagination';
|
|
8
|
+
import { get } from 'lodash';
|
|
9
|
+
import { Space, Button,message,Modal } from 'antd';
|
|
10
|
+
import { pageRequest,
|
|
11
|
+
create,
|
|
12
|
+
remove,
|
|
13
|
+
update
|
|
14
|
+
} from "./api"
|
|
15
|
+
|
|
16
|
+
import { ProFormText, } from '@ant-design/pro-components';
|
|
17
|
+
import { timeFormatter } from '../../../utils';
|
|
18
|
+
import AddModal from './AddModal'
|
|
19
|
+
import "./index.scss"
|
|
20
|
+
export interface RoleProps {
|
|
21
|
+
historyAction: any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function Role({
|
|
25
|
+
historyAction
|
|
26
|
+
}: RoleProps) {
|
|
27
|
+
const searchFormRef: any = useRef()
|
|
28
|
+
|
|
29
|
+
const [ModalOpen, setModalOpen] = useState(false)
|
|
30
|
+
const [editingData, setEditingData] = useState(null);//编辑数据
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
init()
|
|
33
|
+
execute()
|
|
34
|
+
}, [])
|
|
35
|
+
|
|
36
|
+
const init = () => {
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const columns: any = [
|
|
40
|
+
{
|
|
41
|
+
title: '角色名称',
|
|
42
|
+
dataIndex: 'roleName',
|
|
43
|
+
key: 'roleName',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
title: '角色编码',
|
|
47
|
+
dataIndex: 'roleCode',
|
|
48
|
+
key: 'roleCode',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
title: '角色描述',
|
|
52
|
+
dataIndex: 'description',
|
|
53
|
+
key: 'description',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
title: '创建时间',
|
|
57
|
+
dataIndex: 'gmtCreate',
|
|
58
|
+
key: 'gmtCreate',
|
|
59
|
+
render: (cell: any) => {
|
|
60
|
+
return timeFormatter(cell)
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
title: '更新时间',
|
|
65
|
+
dataIndex: 'gmtModified',
|
|
66
|
+
key: 'gmtModified',
|
|
67
|
+
render: (cell: any) => {
|
|
68
|
+
return timeFormatter(cell)
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
title: '操作',
|
|
73
|
+
width: 180,
|
|
74
|
+
fixed: "right",
|
|
75
|
+
render: (rowdata: any,) => <Space>
|
|
76
|
+
{
|
|
77
|
+
rowdata.source !== "system" &&
|
|
78
|
+
<a onClick={() => {
|
|
79
|
+
setEditingData(rowdata)
|
|
80
|
+
setModalOpen(true)
|
|
81
|
+
}}>编辑</a>
|
|
82
|
+
}
|
|
83
|
+
<a onClick={() => {
|
|
84
|
+
historyAction?.push({
|
|
85
|
+
pathname: `/role-info`,
|
|
86
|
+
search: `?roleCode=${rowdata.roleCode}`,
|
|
87
|
+
});
|
|
88
|
+
}}>赋予账号</a>
|
|
89
|
+
{
|
|
90
|
+
rowdata.source !== "system" &&
|
|
91
|
+
<a onClick={() => {
|
|
92
|
+
Modal.confirm({
|
|
93
|
+
title: "确认删除吗?",
|
|
94
|
+
content: '',
|
|
95
|
+
onOk: () => {
|
|
96
|
+
DeleteFunc(rowdata?.roleCode)
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
}} >删除</a>
|
|
100
|
+
}
|
|
101
|
+
</Space>
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
const handleOnReset: any = async (values: any) => {
|
|
106
|
+
searchFormRef.current = { ...values }
|
|
107
|
+
execute({
|
|
108
|
+
innerPageNo: 1,
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const handleOnFinish: any = async (values: any) => {
|
|
113
|
+
searchFormRef.current = { ...values }
|
|
114
|
+
execute()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const readDataList = ({
|
|
118
|
+
innerPageNo,
|
|
119
|
+
innerPageSize,
|
|
120
|
+
}: any) => {
|
|
121
|
+
return pageRequest({
|
|
122
|
+
currentPage: innerPageNo,
|
|
123
|
+
pageSize: innerPageSize,
|
|
124
|
+
...searchFormRef.current
|
|
125
|
+
}).then((res: any) => {
|
|
126
|
+
let records = get(res, "records", [])
|
|
127
|
+
let total = get(res, "total", 0)
|
|
128
|
+
return {
|
|
129
|
+
dataList: records,
|
|
130
|
+
totalCount: total
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const { execute, dataList, isLoading, pagination } = useTableHooks({
|
|
136
|
+
asyncFunction: readDataList
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const handleRoload = () => {
|
|
140
|
+
execute()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const setModalOpenFunc = (type: boolean) => {
|
|
144
|
+
setModalOpen(type)
|
|
145
|
+
setEditingData(null)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const actionFunc = (data: any, type: string) => {
|
|
149
|
+
return (type == 'add' ? create : update)({ ...data }).then((res) => {
|
|
150
|
+
message.success(`${type == 'add' ? '新增' : '更新'}成功`)
|
|
151
|
+
setModalOpen(false)
|
|
152
|
+
setEditingData(null)
|
|
153
|
+
execute()
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
const DeleteFunc = (roleCode:any)=>{
|
|
157
|
+
remove({
|
|
158
|
+
roleCode,
|
|
159
|
+
}).then((res: any) => {
|
|
160
|
+
message.success('删除成功')
|
|
161
|
+
execute()
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
return (
|
|
165
|
+
<PageContainer >
|
|
166
|
+
<QueryFilter
|
|
167
|
+
onReset={handleOnReset}
|
|
168
|
+
onFinish={handleOnFinish}
|
|
169
|
+
>
|
|
170
|
+
<ProFormText name="roleName" label="角色名称" />
|
|
171
|
+
</QueryFilter>
|
|
172
|
+
|
|
173
|
+
<ProTable
|
|
174
|
+
toolBarRender={() => {
|
|
175
|
+
return [
|
|
176
|
+
<Button
|
|
177
|
+
type="primary"
|
|
178
|
+
onClick={() => {
|
|
179
|
+
setModalOpen(true)
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
新增账号
|
|
183
|
+
</Button>,
|
|
184
|
+
];
|
|
185
|
+
}}
|
|
186
|
+
headerTitle={"角色列表"}
|
|
187
|
+
dataSource={dataList}
|
|
188
|
+
loading={isLoading}
|
|
189
|
+
columns={columns}
|
|
190
|
+
rowKey="id"
|
|
191
|
+
options={{
|
|
192
|
+
reload: handleRoload
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
<Pagination {...pagination} />
|
|
196
|
+
<AddModal
|
|
197
|
+
ModalOpen={ModalOpen}
|
|
198
|
+
editOpenStatus={setModalOpenFunc} //修改状态事件
|
|
199
|
+
editingData={editingData} //当前数据
|
|
200
|
+
actionFunc={actionFunc}//事件
|
|
201
|
+
/>
|
|
202
|
+
</PageContainer >
|
|
203
|
+
)
|
|
204
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Button, Drawer, Select, Modal, Form, Spin, Space } from 'antd';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
interface propsType {
|
|
6
|
+
open: boolean;
|
|
7
|
+
editOpenStatus: Function;
|
|
8
|
+
roleBoundAccountsFunc: Function;
|
|
9
|
+
queryByKeywordFunc: Function;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function index({
|
|
13
|
+
open,
|
|
14
|
+
editOpenStatus,
|
|
15
|
+
roleBoundAccountsFunc,
|
|
16
|
+
queryByKeywordFunc
|
|
17
|
+
}: propsType) {
|
|
18
|
+
const [form] = Form.useForm();
|
|
19
|
+
const [selectOptions, useSelectOptions] = useState([])
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
form.resetFields()
|
|
23
|
+
if(open)queryByKeywordSearch('')
|
|
24
|
+
}, [open])
|
|
25
|
+
|
|
26
|
+
const editModelOpen = (type: boolean) => {
|
|
27
|
+
editOpenStatus(type);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const onCloseDrawer = () => {
|
|
31
|
+
editModelOpen(false)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function useDebounce(fn: any, delay: any, dep = []) {
|
|
35
|
+
const { current }: any = useRef({ fn, timer: null });
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
current.fn = fn;
|
|
38
|
+
}, [fn]);
|
|
39
|
+
return useCallback(function f(...args: any) {
|
|
40
|
+
if (current.timer) {
|
|
41
|
+
clearTimeout(current.timer);
|
|
42
|
+
}
|
|
43
|
+
current.timer = setTimeout(() => {
|
|
44
|
+
current.fn(...args);
|
|
45
|
+
}, delay);
|
|
46
|
+
}, dep)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const queryByKeywordSearch = useDebounce((keyword: any) => {
|
|
50
|
+
queryByKeywordFunc({
|
|
51
|
+
keyword
|
|
52
|
+
}).then((res: any) => {
|
|
53
|
+
useSelectOptions(res)
|
|
54
|
+
}).catch((err) => {
|
|
55
|
+
})
|
|
56
|
+
}, 500)
|
|
57
|
+
|
|
58
|
+
const onFinishForm = () => {
|
|
59
|
+
form.validateFields()
|
|
60
|
+
.then((values) => {
|
|
61
|
+
roleBoundAccountsFunc(values)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Drawer
|
|
67
|
+
title="绑定的角色"
|
|
68
|
+
closable={false}
|
|
69
|
+
open={open}
|
|
70
|
+
destroyOnClose={true}
|
|
71
|
+
onClose={() => { onCloseDrawer() }}
|
|
72
|
+
footer={<Space>
|
|
73
|
+
<Button
|
|
74
|
+
key="submit"
|
|
75
|
+
type="primary"
|
|
76
|
+
onClick={() => {
|
|
77
|
+
onFinishForm()
|
|
78
|
+
}}
|
|
79
|
+
>保存</Button>
|
|
80
|
+
<Button
|
|
81
|
+
key="refresh"
|
|
82
|
+
onClick={() => { onCloseDrawer() }}
|
|
83
|
+
>取消</Button>
|
|
84
|
+
</Space>}
|
|
85
|
+
>
|
|
86
|
+
<Form
|
|
87
|
+
form={form}
|
|
88
|
+
layout={'vertical'}
|
|
89
|
+
initialValues={{ remember: true }}
|
|
90
|
+
autoComplete="off"
|
|
91
|
+
>
|
|
92
|
+
<Form.Item name="accountIds" label="添加账号"
|
|
93
|
+
rules={[{ required: true, message: '请选中账号!' }]}>
|
|
94
|
+
<Select
|
|
95
|
+
mode="multiple"
|
|
96
|
+
allowClear
|
|
97
|
+
placeholder="根据名称或账号搜索"
|
|
98
|
+
options={(selectOptions || []).map((d: any) => ({
|
|
99
|
+
value: d.id,
|
|
100
|
+
label: d.name,
|
|
101
|
+
}))}
|
|
102
|
+
onSearch={((e) => {
|
|
103
|
+
queryByKeywordSearch(e)
|
|
104
|
+
})}
|
|
105
|
+
filterOption={false}
|
|
106
|
+
/>
|
|
107
|
+
</Form.Item>
|
|
108
|
+
</Form>
|
|
109
|
+
</Drawer>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import request from "../../../apiRequest/config"
|
|
2
|
+
|
|
3
|
+
//根据角色分页查询绑定的账号
|
|
4
|
+
export const pageBoundAccounts= (data?: any) => {
|
|
5
|
+
return request.post("/api/permission/accountRole/pageBoundAccounts.json", { ...data })
|
|
6
|
+
}
|
|
7
|
+
//按关键词查询账号信息
|
|
8
|
+
export const queryByKeyword= (data?: any) => {
|
|
9
|
+
return request.post("/api/permission/account/queryByKeyword.json", { ...data })
|
|
10
|
+
}
|
|
11
|
+
//角色下绑定账号
|
|
12
|
+
export const roleBoundAccounts= (data?: any) => {
|
|
13
|
+
return request.post("/api/permission/accountRole/roleBoundAccounts.json", { ...data })
|
|
14
|
+
}
|
|
15
|
+
//角色下解绑账号
|
|
16
|
+
export const roleUnboundAccounts= (data?: any) => {
|
|
17
|
+
return request.post("/api/permission/accountRole/roleUnboundAccounts.json", { ...data })
|
|
18
|
+
}
|
|
19
|
+
//根据编码查询角色
|
|
20
|
+
export const getRole= (data?: any) => {
|
|
21
|
+
return request.post("/api/permission/role/getRole.json", { ...data })
|
|
22
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import useTableHooks from "../../../hooks/useTableHooks"
|
|
3
|
+
|
|
4
|
+
import PageContainer from '../../base-component/PageContainer';
|
|
5
|
+
import QueryFilter from '../../base-component/QueryFilter';
|
|
6
|
+
import ProTable from '../../base-component/ProTable';
|
|
7
|
+
import Pagination from '../../base-component/Pagination';
|
|
8
|
+
import { get } from 'lodash';
|
|
9
|
+
import { ProFormText, } from '@ant-design/pro-components';
|
|
10
|
+
import { Button, Divider, Modal, Descriptions, Space, message } from 'antd';
|
|
11
|
+
import EditAccountDrawer from './EditAccountDrawer/index'
|
|
12
|
+
import { timeFormatter, getUrlParams } from '../../../utils';
|
|
13
|
+
import {
|
|
14
|
+
pageBoundAccounts,
|
|
15
|
+
roleBoundAccounts,
|
|
16
|
+
roleUnboundAccounts,
|
|
17
|
+
getRole,
|
|
18
|
+
queryByKeyword
|
|
19
|
+
} from './api'
|
|
20
|
+
import "./index.scss"
|
|
21
|
+
|
|
22
|
+
export default function RoleInfo() {
|
|
23
|
+
const searchFormRef: any = useRef()
|
|
24
|
+
const [roleCode, setRoleCode] = useState('')
|
|
25
|
+
const [roleInfo, setRoleInfo]: any = useState({})
|
|
26
|
+
const [editAccountOpen, setEditAccountOpen] = useState(false);
|
|
27
|
+
|
|
28
|
+
const columns: any = [
|
|
29
|
+
{
|
|
30
|
+
title: '名称',
|
|
31
|
+
dataIndex: 'name',
|
|
32
|
+
key: 'name',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
title: '账号',
|
|
36
|
+
dataIndex: 'account',
|
|
37
|
+
key: 'account',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
title: '工号',
|
|
41
|
+
dataIndex: 'jobNumber',
|
|
42
|
+
key: 'jobNumber',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
title: '手机号',
|
|
46
|
+
dataIndex: 'mobile',
|
|
47
|
+
key: 'mobile',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
title: '邮箱',
|
|
51
|
+
dataIndex: 'email',
|
|
52
|
+
key: 'email',
|
|
53
|
+
copyable: true,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
title: '是否企业管理员',
|
|
57
|
+
dataIndex: 'isAdmin',
|
|
58
|
+
key: 'isAdmin',
|
|
59
|
+
render: (cell: any) => {
|
|
60
|
+
if (cell) {
|
|
61
|
+
return '是'
|
|
62
|
+
} else {
|
|
63
|
+
return '否'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
title: '创建时间',
|
|
69
|
+
dataIndex: 'gmtCreate',
|
|
70
|
+
key: 'gmtCreate',
|
|
71
|
+
render: (cell: any) => {
|
|
72
|
+
return timeFormatter(cell)
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
title: '修改时间',
|
|
77
|
+
dataIndex: 'gmtModified',
|
|
78
|
+
key: 'gmtModified',
|
|
79
|
+
render: (cell: any) => {
|
|
80
|
+
return timeFormatter(cell)
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
title: '操作',
|
|
85
|
+
width: 80,
|
|
86
|
+
fixed: "right",
|
|
87
|
+
render: (rowdata: any,) => <Space>
|
|
88
|
+
<a onClick={() => {
|
|
89
|
+
Modal.confirm({
|
|
90
|
+
title: "确认解绑吗?",
|
|
91
|
+
content: '',
|
|
92
|
+
onOk: () => {
|
|
93
|
+
roleUnboundAccountsFunc(rowdata.id)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
}}>解绑</a>
|
|
98
|
+
</Space>
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
initGetData('init', true)
|
|
104
|
+
}, [])
|
|
105
|
+
|
|
106
|
+
//初始化请求数据
|
|
107
|
+
const initGetData = (type: string, msgType: any) => {
|
|
108
|
+
let roleCode = getUrlParams('roleCode')
|
|
109
|
+
setRoleCode(roleCode)
|
|
110
|
+
if (roleCode) {
|
|
111
|
+
getRoleFunc({ roleCode })
|
|
112
|
+
execute({ "roleCode": roleCode })
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const getRoleFunc = (data: any) => {
|
|
116
|
+
setRoleInfo({})
|
|
117
|
+
getRole({
|
|
118
|
+
...data,
|
|
119
|
+
}).then((res: any) => {
|
|
120
|
+
setRoleInfo(res || {})
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
const roleUnboundAccountsFunc = (account: any) => {
|
|
124
|
+
roleUnboundAccounts({
|
|
125
|
+
"accountIds": [account],
|
|
126
|
+
"roleCode": roleCode
|
|
127
|
+
}).then((res: any) => {
|
|
128
|
+
message.success('解绑成功')
|
|
129
|
+
execute({ "roleCode": roleCode })
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const readDataList = ({
|
|
134
|
+
innerPageNo,
|
|
135
|
+
innerPageSize,
|
|
136
|
+
...otherOptions
|
|
137
|
+
}: any) => {
|
|
138
|
+
return pageBoundAccounts({
|
|
139
|
+
currentPage: innerPageNo,
|
|
140
|
+
pageSize: innerPageSize,
|
|
141
|
+
...searchFormRef.current,
|
|
142
|
+
...otherOptions
|
|
143
|
+
}).then((res: any) => {
|
|
144
|
+
let records = get(res, "records", [])
|
|
145
|
+
let total = get(res, "total", 0)
|
|
146
|
+
return {
|
|
147
|
+
dataList: records,
|
|
148
|
+
totalCount: total
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
const { execute, dataList, isLoading, pagination } = useTableHooks({
|
|
153
|
+
asyncFunction: readDataList
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
const handleRoload = () => {
|
|
157
|
+
execute({ "roleCode": roleCode })
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const getQueryBoundRolesFunc = async () => {
|
|
161
|
+
setEditAccountOpen(true)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const roleBoundAccountsFunc = ({ accountIds }: any) => {
|
|
165
|
+
return roleBoundAccounts({
|
|
166
|
+
"accountIds": accountIds,
|
|
167
|
+
"roleCode": roleCode
|
|
168
|
+
}).then((res: any) => {
|
|
169
|
+
message.success(`添加账号成功`)
|
|
170
|
+
execute({ "roleCode": roleCode })
|
|
171
|
+
setEditAccountOpen(false)
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
//搜索关键字
|
|
175
|
+
const queryByKeywordFunc = ({ keyword }: any) => {
|
|
176
|
+
return queryByKeyword({
|
|
177
|
+
keyword
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const handleOnReset: any = async (values: any) => {
|
|
182
|
+
searchFormRef.current = { ...values }
|
|
183
|
+
execute({
|
|
184
|
+
innerPageNo: 1,
|
|
185
|
+
"roleCode": roleCode
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const handleOnFinish: any = async (values: any) => {
|
|
190
|
+
searchFormRef.current = { ...values }
|
|
191
|
+
execute({ "roleCode": roleCode })
|
|
192
|
+
}
|
|
193
|
+
return (
|
|
194
|
+
<PageContainer>
|
|
195
|
+
<Divider orientation="left">{roleInfo?.roleName || "-"}</Divider>
|
|
196
|
+
<Descriptions className="basicInfoWrap">
|
|
197
|
+
<Descriptions.Item label="角色名称">{roleInfo?.roleName || ''}</Descriptions.Item>
|
|
198
|
+
<Descriptions.Item label="角色编码">{roleInfo?.roleCode || ''}</Descriptions.Item>
|
|
199
|
+
<Descriptions.Item label="角色描述">{roleInfo?.description || ''}</Descriptions.Item>
|
|
200
|
+
<Descriptions.Item label="创建时间">{timeFormatter(roleInfo?.gmtCreate) || ''}</Descriptions.Item>
|
|
201
|
+
<Descriptions.Item label="更新时间">{timeFormatter(roleInfo?.gmtModified) || ''}</Descriptions.Item>
|
|
202
|
+
</Descriptions>
|
|
203
|
+
|
|
204
|
+
<QueryFilter
|
|
205
|
+
onReset={handleOnReset}
|
|
206
|
+
onFinish={handleOnFinish}
|
|
207
|
+
>
|
|
208
|
+
<ProFormText name="keyword" label="关键词" />
|
|
209
|
+
</QueryFilter>
|
|
210
|
+
|
|
211
|
+
<ProTable
|
|
212
|
+
headerTitle={"角色下绑定的账号"}
|
|
213
|
+
dataSource={dataList}
|
|
214
|
+
loading={isLoading}
|
|
215
|
+
columns={columns}
|
|
216
|
+
rowKey="id"
|
|
217
|
+
options={{
|
|
218
|
+
reload: handleRoload
|
|
219
|
+
}}
|
|
220
|
+
toolBarRender={() => {
|
|
221
|
+
return [
|
|
222
|
+
<Button type="primary" onClick={(() => {
|
|
223
|
+
getQueryBoundRolesFunc()
|
|
224
|
+
})}>添加账号</Button>
|
|
225
|
+
];
|
|
226
|
+
}}
|
|
227
|
+
/>
|
|
228
|
+
|
|
229
|
+
<Pagination {...pagination}
|
|
230
|
+
onChange={(innerPageNo: number, innerPageSize: number) => {
|
|
231
|
+
execute({
|
|
232
|
+
innerPageNo,
|
|
233
|
+
innerPageSize,
|
|
234
|
+
"roleCode": roleCode
|
|
235
|
+
})
|
|
236
|
+
}}/>
|
|
237
|
+
<EditAccountDrawer
|
|
238
|
+
open={editAccountOpen} // 状态
|
|
239
|
+
editOpenStatus={setEditAccountOpen} //修改弹框显隐事件
|
|
240
|
+
roleBoundAccountsFunc={roleBoundAccountsFunc}
|
|
241
|
+
queryByKeywordFunc={queryByKeywordFunc} //搜索事件
|
|
242
|
+
></EditAccountDrawer>
|
|
243
|
+
|
|
244
|
+
</PageContainer>
|
|
245
|
+
)
|
|
246
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -12,7 +12,8 @@ import request from './apiRequest/config'
|
|
|
12
12
|
import iotRequest from './apiRequest/iotConfig'
|
|
13
13
|
import { hosts } from './apiRequest/hosts'
|
|
14
14
|
import CpcAccount from './components/universal-pages/cpcAccount' //cp列表c账号
|
|
15
|
-
|
|
15
|
+
import CpcRole from './components/universal-pages/cpcRole' //cpc 角色
|
|
16
|
+
import CpcRoleInfo from './components/universal-pages/cpcRoleInfo' //cpc角色详情
|
|
16
17
|
import { getUrlParams, downloadFile, timeFormatter } from './utils/index'
|
|
17
18
|
export {
|
|
18
19
|
LiosLayout,
|
|
@@ -34,5 +35,8 @@ export {
|
|
|
34
35
|
hosts,
|
|
35
36
|
getUrlParams,
|
|
36
37
|
downloadFile,
|
|
37
|
-
timeFormatter
|
|
38
|
+
timeFormatter,
|
|
39
|
+
|
|
40
|
+
CpcRole,
|
|
41
|
+
CpcRoleInfo
|
|
38
42
|
}
|