cfel-base-components 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -1,2 +1,2 @@
1
1
  <!-- npm run dev
2
- npm pubilsh -->
2
+ npm publish -->
@@ -25,5 +25,5 @@ module.exports = {
25
25
  exclude: /node_modules/, // 只解析 src 目录下的文件
26
26
  },
27
27
  ]
28
- },
28
+ }
29
29
  };
@@ -12,6 +12,32 @@
12
12
  </head>
13
13
  <body>
14
14
  <div id="root"></div>
15
+ <script>
16
+ window.g_config = {
17
+ token: "111f1bf4-600b-4e47-815b-b739d5398c91",
18
+ tenant: {
19
+ id: 1674706582226763778,
20
+ corpId: "dingc9dbc42450ccf06e4ac5d6980864d335",
21
+ source: "\u9489\u9489",
22
+ name: "\u8FDC\u822A\u8DE8\u56FD\u63A7\u80A1\u96C6\u56E2",
23
+ shortName: "\u8FDC\u822A\u8DE8\u56FD\u63A7\u80A1\u96C6\u56E2",
24
+ logo: ""
25
+ },
26
+ user: {
27
+ id: 1676424765496406018,
28
+ userId: "01436565094521893533",
29
+ unionId: "xsU4QrgEfZxxj8YxEWAYJAiEiE",
30
+ name: "\u5434\u91D1\u521A",
31
+ avatar: "https:\/\/pic.imgdb.cn\/item\/64a520d21ddac507cc4653d3.jpg",
32
+ account: "15957797376",
33
+ roleInfo: []
34
+ },
35
+ logoutUrl: "\/sso\/logout?back=http%3A%2F%2Flios-iot-obee-daily.chengfengerlai.com%2Fdelivery",
36
+ switchTenantUrl: "https:\/\/cfel-sso-daily.chengfengerlai.com\/tenant\/switch?fakeAccountId=1676424765496406018\u0026redirect=http:\/\/lios-iot-obee-daily.chengfengerlai.com\/sso\/login?back=http%3A%2F%2Flios-iot-obee-daily.chengfengerlai.com%2Fdelivery",
37
+ productCode: "lios-iot-obee",
38
+ env: "daily"
39
+ };
40
+ </script>
15
41
  <script src="dev.js"></script>
16
42
  </body>
17
43
  </html>
@@ -14,8 +14,6 @@ const App = () => {
14
14
  return <PageContainer className={"aaa"}>
15
15
  123
16
16
  </PageContainer>
17
-
18
-
19
17
  }
20
18
  const container = document.getElementById('root');
21
19
  const root = createRoot(container);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cfel-base-components",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "cfel-base-components",
5
5
  "main": "/src/index.tsx",
6
6
  "types": "src/index.d.ts",
@@ -21,12 +21,15 @@
21
21
  "@babel/preset-env": "^7.22.5",
22
22
  "@babel/preset-react": "^7.22.5",
23
23
  "@babel/preset-typescript": "^7.22.5",
24
+ "@types/lodash": "^4.14.195",
24
25
  "@types/react": "^18.2.14",
25
26
  "@types/react-dom": "^18.2.6",
27
+ "axios": "^1.4.0",
26
28
  "babel-loader": "^8.2.5",
27
29
  "classnames": "^2.3.2",
28
30
  "css-loader": "^6.8.1",
29
31
  "less-loader": "^11.1.3",
32
+ "lodash": "^4.17.21",
30
33
  "mini-css-extract-plugin": "^2.7.6",
31
34
  "node-sass": "^9.0.0",
32
35
  "postcss": "^8.4.24",
@@ -46,5 +49,8 @@
46
49
  "@ant-design/icons": "^5.1.4",
47
50
  "@ant-design/pro-components": "^2.6.12",
48
51
  "antd": "^5.5.2"
52
+ },
53
+ "dependencies": {
54
+ "dayjs": "^1.11.9"
49
55
  }
50
56
  }
@@ -0,0 +1,71 @@
1
+ import axios, { AxiosRequestHeaders } from 'axios';
2
+ import { notification } from 'antd';
3
+
4
+
5
+ let UMI_APP_BASEURL:any = window.location.origin || process.env
6
+ const instance = axios.create({ baseURL: UMI_APP_BASEURL });
7
+
8
+ instance.interceptors.request.use(
9
+ (config: any) => {
10
+ config.headers = {
11
+ ...config.headers,
12
+ "cfel-token": (window as any)?.g_config?.token
13
+ } as AxiosRequestHeaders;
14
+
15
+ config.params = {
16
+ ...config.params,
17
+ productCode: (window as any)?.g_config?.productCode,
18
+ }
19
+
20
+ return config;
21
+ },
22
+ (error: any) => Promise.reject(error)
23
+ );
24
+
25
+ instance.interceptors.response.use(
26
+ //状态码为2xx的时候执行
27
+ (response: any) => {
28
+ const { data = {} } = response;
29
+ const { success, content, errorCode, errorMsg } = data;
30
+
31
+ if (!success) {
32
+ notification.error({
33
+ message: errorMsg
34
+ });
35
+ return Promise.reject(data);
36
+ }
37
+
38
+ return content;
39
+ },
40
+ //状态码不为2xx的时候执行
41
+ (error: any) => {
42
+ const { response = {} } = error;
43
+ const { status } = response;
44
+
45
+ enum CodeMessage {
46
+ '发出的请求有错误,服务器没有进行新建或修改数据的操作。' = 400,
47
+ '用户未登录。' = 401,
48
+ '用户得到授权,但是访问是被禁止的。' = 403,
49
+ '发出的请求针对的是不存在的记录,服务器没有进行操作。' = 404,
50
+ '请求的格式不可得。' = 406,
51
+ '请求的资源被永久删除,且不会再得到的。' = 410,
52
+ '当创建一个对象时,发生一个验证错误。' = 422,
53
+ '服务器发生错误,请检查服务器。' = 500,
54
+ '网关错误。' = 502,
55
+ '服务不可用,服务器暂时过载或维护。' = 503,
56
+ '网关超时。' = 504
57
+ }
58
+
59
+ notification.error({
60
+ message: response?.data?.message || CodeMessage[status]
61
+ });
62
+
63
+ if (status === 401) {
64
+
65
+ }
66
+
67
+ return Promise.reject(error);
68
+ }
69
+ );
70
+
71
+ export default instance;
@@ -0,0 +1,6 @@
1
+ export const hosts: any = {
2
+ iot: {
3
+ "daily": "https://lios-iot-daily.chengfengerlai.com",
4
+ "product": "https://lios-iot.chengfengerlai.com"
5
+ }
6
+ }
@@ -0,0 +1,71 @@
1
+ import axios, { AxiosRequestHeaders } from 'axios';
2
+ import { notification } from 'antd';
3
+ import { hosts } from './hosts'
4
+
5
+ const env = (window as any)?.g_config?.env
6
+ const instance = axios.create({ baseURL: hosts["iot"][env] });
7
+
8
+ instance.interceptors.request.use(
9
+ (config: any) => {
10
+ config.headers = {
11
+ ...config.headers,
12
+ "cfel-token": (window as any)?.g_config?.token
13
+ } as AxiosRequestHeaders;
14
+
15
+ config.params = {
16
+ ...config.params,
17
+ productCode: (window as any)?.g_config?.productCode,
18
+ }
19
+
20
+ return config;
21
+ },
22
+ (error: any) => Promise.reject(error)
23
+ );
24
+
25
+ instance.interceptors.response.use(
26
+ //状态码为2xx的时候执行
27
+ (response: any) => {
28
+ const { data = {} } = response;
29
+ const { success, content, errorCode, errorMsg } = data;
30
+
31
+ if (!success) {
32
+ notification.error({
33
+ message: errorMsg
34
+ });
35
+ return Promise.reject(data);
36
+ }
37
+
38
+ return content;
39
+ },
40
+ //状态码不为2xx的时候执行
41
+ (error: any) => {
42
+ const { response = {} } = error;
43
+ const { status } = response;
44
+
45
+ enum CodeMessage {
46
+ '发出的请求有错误,服务器没有进行新建或修改数据的操作。' = 400,
47
+ '用户未登录。' = 401,
48
+ '用户得到授权,但是访问是被禁止的。' = 403,
49
+ '发出的请求针对的是不存在的记录,服务器没有进行操作。' = 404,
50
+ '请求的格式不可得。' = 406,
51
+ '请求的资源被永久删除,且不会再得到的。' = 410,
52
+ '当创建一个对象时,发生一个验证错误。' = 422,
53
+ '服务器发生错误,请检查服务器。' = 500,
54
+ '网关错误。' = 502,
55
+ '服务不可用,服务器暂时过载或维护。' = 503,
56
+ '网关超时。' = 504
57
+ }
58
+
59
+ notification.error({
60
+ message: response?.data?.message || CodeMessage[status]
61
+ });
62
+
63
+ if (status === 401) {
64
+
65
+ }
66
+
67
+ return Promise.reject(error);
68
+ }
69
+ );
70
+
71
+ export default instance;
@@ -0,0 +1,11 @@
1
+ import request from "../../../apiRequest/config"
2
+
3
+ //分页查询账号
4
+ export const accountPage= (data?: any) => {
5
+ return request.post("/api/permission/account/page.json", { ...data })
6
+ }
7
+
8
+ export const updateDevice = (data?: any) => {
9
+ return request.post("/api/wifi/device/bound/space/update.json", { ...data })
10
+ }
11
+
@@ -3,31 +3,146 @@ import PageContainer from '../../base-component/PageContainer';
3
3
  import QueryFilter from '../../base-component/QueryFilter';
4
4
  import ProTable from '../../base-component/ProTable';
5
5
  import Pagination from '../../base-component/Pagination';
6
- import {
7
- ProFormText,
8
- } from '@ant-design/pro-components';
9
- import "./index.scss"
6
+ import { ProFormText, } from '@ant-design/pro-components';
7
+ import { Space, } from 'antd';
8
+ import { get } from 'lodash';
9
+ import { timeFormatter } from '../../../utils';
10
+ import useTableHooks from "../../../hooks/useTableHooks"
11
+ import { accountPage } from "./api"
10
12
 
13
+ import "./index.scss"
11
14
 
12
15
  export interface AccountProps {
13
- dataList: any;
14
- columns: any;
15
- isLoading: any;
16
- handleRoload: () => any;
17
- pagination: any;
18
- handleOnReset: (item: any) => any;
19
- handleOnFinish: (item: any) => any;
16
+ historyAction: any;
20
17
  }
21
18
 
22
19
  export default function Account({
23
- dataList,
24
- columns,
25
- isLoading,
26
- handleRoload,
27
- pagination,
28
- handleOnReset,
29
- handleOnFinish
20
+ historyAction
30
21
  }: AccountProps) {
22
+ const searchFormRef: any = useRef()
23
+
24
+ useEffect(() => {
25
+ execute()
26
+ }, [])
27
+
28
+ const columns: any = [
29
+ {
30
+ title: '名称',
31
+ dataIndex: 'name',
32
+ key: 'name',
33
+ render: (text: any) => {
34
+ return <span>{text}</span>
35
+ }
36
+ },
37
+ {
38
+ title: '账号',
39
+ dataIndex: 'account',
40
+ key: 'account',
41
+ },
42
+ {
43
+ title: '工号',
44
+ dataIndex: 'jobNumber',
45
+ key: 'jobNumber',
46
+ },
47
+ {
48
+ title: '手机号',
49
+ dataIndex: 'mobile',
50
+ key: 'mobile',
51
+ },
52
+ {
53
+ title: '邮箱',
54
+ dataIndex: 'email',
55
+ key: 'email',
56
+ ellipsis: true,
57
+ },
58
+ {
59
+ title: '是否企业管理员',
60
+ dataIndex: 'isAdmin',
61
+ key: 'isAdmin',
62
+ render: (text: any, rowData: any) => {
63
+ if (rowData.isAdmin) {
64
+ return '是'
65
+ } else {
66
+ return '否'
67
+ }
68
+ }
69
+ },
70
+
71
+ {
72
+ title: '创建时间',
73
+ dataIndex: 'gmtCreate',
74
+ key: 'gmtCreate',
75
+ render: (cell: any) => {
76
+ return timeFormatter(cell)
77
+ }
78
+ },
79
+ {
80
+ title: '修改时间',
81
+ dataIndex: 'gmtModified',
82
+ key: 'gmtModified',
83
+ render: (cell: any) => {
84
+ return timeFormatter(cell)
85
+ }
86
+ },
87
+ {
88
+ title: '操作',
89
+ fixed: 'right',
90
+ width: 80,
91
+ render: (rowdata: any) => (
92
+
93
+ <Space>
94
+ <a
95
+ onClick={() => {
96
+ historyAction?.push({
97
+ pathname: `/account-info`,
98
+ search: `?id=${rowdata.id}`,
99
+ });
100
+ }}
101
+ >
102
+ 配置
103
+ </a>
104
+ </Space>
105
+ ),
106
+ },
107
+ ];
108
+
109
+ const handleOnReset: any = async (values: any) => {
110
+ searchFormRef.current = { ...values }
111
+ execute({
112
+ innerPageNo: 1,
113
+ })
114
+ }
115
+
116
+ const handleOnFinish: any = async (values: any) => {
117
+ searchFormRef.current = { ...values }
118
+ execute()
119
+ }
120
+
121
+ const readDataList = ({
122
+ innerPageNo,
123
+ innerPageSize,
124
+ }: any) => {
125
+ return accountPage({
126
+ currentPage: innerPageNo,
127
+ pageSize: innerPageSize,
128
+ ...searchFormRef.current,
129
+ }).then((res: any) => {
130
+ let records = get(res, "records", [])
131
+ let total = get(res, "total", 0)
132
+ return {
133
+ dataList: records,
134
+ totalCount: total
135
+ }
136
+ })
137
+ }
138
+
139
+ const { execute, dataList, isLoading, pagination } = useTableHooks({
140
+ asyncFunction: readDataList
141
+ })
142
+
143
+ const handleRoload = () => {
144
+ execute()
145
+ }
31
146
 
32
147
  return (
33
148
  <PageContainer>
@@ -0,0 +1,26 @@
1
+ import request from "../../../apiRequest/config"
2
+
3
+ //按账号id查询账号信息
4
+ export const getAccount= (data?: any) => {
5
+ return request.post("/api/permission/account/getAccount.json", { ...data })
6
+ }
7
+ //根据账号查询绑定的角色 分页
8
+ export const pageBoundRoles= (data?: any) => {
9
+ return request.post("/api/permission/accountRole/pageBoundRoles.json", { ...data })
10
+ }
11
+ //根据账号查询绑定的角色
12
+ export const queryBoundRoles= (data?: any) => {
13
+ return request.post("/api/permission/accountRole/queryBoundRoles.json", { ...data })
14
+ }
15
+ //获取所有角色
16
+ export const rolelistRole = (data?: any) => {
17
+ return request.get("/api/permission/role/listRole.json", { ...data })
18
+ }
19
+ //账号下绑定角色
20
+ export const accountBoundRoles= (data?: any) => {
21
+ return request.post("/api/permission/accountRole/accountBoundRoles.json", { ...data })
22
+ }
23
+ //账号下解绑角色
24
+ export const accountUnboundRoles= (data?: any) => {
25
+ return request.post("/api/permission/accountRole/accountUnboundRoles.json", { ...data })
26
+ }
@@ -3,46 +3,177 @@ import PageContainer from '../../base-component/PageContainer';
3
3
  import QueryFilter from '../../base-component/QueryFilter';
4
4
  import ProTable from '../../base-component/ProTable';
5
5
  import Pagination from '../../base-component/Pagination';
6
-
6
+ import { get } from 'lodash';
7
7
  import { Modal, Button, Divider, Descriptions, Space, message, Avatar } from 'antd';
8
8
  import { UserOutlined } from '@ant-design/icons';
9
9
  import EditAccountDrawer from './EditAccountDrawer/index'
10
-
10
+ import { timeFormatter, getUrlParams } from '../../../utils';
11
+ import {
12
+ getAccount,
13
+ pageBoundRoles,
14
+ queryBoundRoles,
15
+ rolelistRole,
16
+ accountBoundRoles,
17
+ accountUnboundRoles
18
+ } from './api'
11
19
  import "./index.scss"
12
20
 
13
- export interface AccountInfoProps {
14
- accountInfo: any;
15
- timeFormatter: (item: any) => any;
16
- dataList: any;
17
- columns: any;
18
- isLoading: any;
19
- handleRoload: () => any;
20
- pagination: any;
21
- isBoundRolesFunc: (type: any, item: any) => any;
22
- getQueryBoundRolesFunc: () => any;
23
- editAccountOpen: any
24
- setEditAccountOpen: (item: any) => any;
25
- rolelistRoleData: any,
26
- roleCheckData: any,
27
- }
28
21
 
29
- export default function AccountInfo({
30
- accountInfo,//用户详情
31
- timeFormatter,//时间戳转换
32
- dataList,//表格数据
33
- columns,//列
34
- isLoading,//加载
35
- handleRoload,//分页
36
- pagination,//分页配置
37
- isBoundRolesFunc,//绑定/解绑事件
38
- getQueryBoundRolesFunc,//绑定打开弹框
39
- editAccountOpen, //弹框状态
40
- setEditAccountOpen, //关闭弹框
41
- rolelistRoleData, //总角色数据
42
- roleCheckData, //当前选中
43
22
 
44
- }: AccountInfoProps) {
23
+ export default function AccountInfo() {
24
+ const [accountInfo, setAccountInfoInfo]: any = useState({})
25
+ const [pageId, setPageId] = useState('')
26
+ const [rolelistRoleData, setRolelistRoleData]: any = useState([]); // 角色总数据
27
+ const [roleCheckData, setRoleCheckData]: any = useState([]); //当前选中的角色list
28
+ const [editAccountOpen, setEditAccountOpen] = useState(false);
29
+
30
+ useEffect(() => {
31
+ let id = getUrlParams('id')
32
+ if (!id) return
33
+ setPageId(id)
34
+ initGetData()
35
+ }, [])
36
+
37
+ const columns: any = [
38
+ {
39
+ title: '角色名称',
40
+ dataIndex: 'roleName',
41
+ key: 'roleName',
42
+ },
43
+ {
44
+ title: '角色编码',
45
+ dataIndex: 'roleCode',
46
+ key: 'roleCode',
47
+ },
48
+ {
49
+ title: '来源',
50
+ dataIndex: 'source',
51
+ key: 'source',
52
+ render: (cell: any) => {
53
+ if (cell == 'system') {
54
+ return '系统创建'
55
+ } else if (cell == 'user') {
56
+ return '用户自建'
57
+ } else if (cell == 'user') {
58
+ return '未知'
59
+ }
60
+ }
61
+ },
62
+ {
63
+ title: '描述',
64
+ dataIndex: 'description',
65
+ key: 'description',
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
+ isBoundRolesFunc(false, { roleCodes: [rowdata.roleCode] })
94
+ }
95
+ })
96
+ }}>解绑</a>
97
+ </Space>
98
+ },
99
+ ];
100
+
101
+
102
+ //初始化请求数据
103
+ const initGetData = () => {
104
+ let id = getUrlParams('id')
105
+ getAccountFunc({ id })
106
+ execute({ "accountId": id })
107
+ }
108
+
109
+ const getAccountFunc = (data: any) => {
110
+ setAccountInfoInfo({})
111
+ getAccount({
112
+ ...data,
113
+ }).then((res: any) => {
114
+ setAccountInfoInfo(res || {})
115
+ })
116
+ }
117
+
118
+ const readDataList = ({
119
+ innerPageNo,
120
+ innerPageSize,
121
+ ...otherOptions
122
+ }: any) => {
123
+ return pageBoundRoles({
124
+ currentPage: innerPageNo,
125
+ pageSize: innerPageSize,
126
+ ...otherOptions
127
+ }).then((res: any) => {
128
+ let records = get(res, "records", [])
129
+ let total = get(res, "total", 0)
130
+ return {
131
+ dataList: records,
132
+ totalCount: total
133
+ }
134
+ })
135
+ }
136
+ const { execute, dataList, isLoading, pagination } = useTableHooks({
137
+ asyncFunction: readDataList
138
+ })
139
+
140
+ const handleRoload = () => {
141
+ execute({ "accountId": pageId })
142
+ }
45
143
 
144
+ const getQueryBoundRolesFunc = () => {
145
+ Promise.all([queryBoundRoles({ accountId: pageId }), rolelistRole()]).then((res) => {
146
+ let boundRoles: any = res[0]
147
+ let roleList: any = res[1]
148
+ let result = []
149
+ for (var i = 0; i < roleList.length; i++) {
150
+ var item = roleList[i]
151
+ var repeat = false
152
+ for (var j = 0; j < boundRoles.length; j++) {
153
+ if (item.roleCode === boundRoles[j].roleCode) {
154
+ repeat = true
155
+ break
156
+ }
157
+ }
158
+ if (repeat) {
159
+ result.push(item.roleCode)
160
+ }
161
+ }
162
+ setRolelistRoleData(roleList)
163
+ setRoleCheckData(result)
164
+ setEditAccountOpen(true)
165
+ })
166
+ }
167
+ const isBoundRolesFunc = (type: any, { roleCodes }: any) => {
168
+ return (type ? accountBoundRoles : accountUnboundRoles)({
169
+ "accountId": pageId,
170
+ "roleCodes": roleCodes
171
+ }).then(() => {
172
+ message.success(`${type ? '绑定' : '解绑'}成功`)
173
+ execute({ "accountId": pageId })
174
+ setEditAccountOpen(false)
175
+ })
176
+ }
46
177
  return (
47
178
  <PageContainer>
48
179
  <Divider orientation="left">
@@ -0,0 +1,9 @@
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 updateConfig = (data?: any) => {
8
+ return request.post("/api/wifi/device/bound/radioConfig/updateConfig.json", { ...data })
9
+ }
@@ -1,32 +1,120 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
+ import useTableHooks from "../../../hooks/useTableHooks"
3
+
2
4
  import PageContainer from '../../base-component/PageContainer';
3
5
  import QueryFilter from '../../base-component/QueryFilter';
4
6
  import ProTable from '../../base-component/ProTable';
5
7
  import Pagination from '../../base-component/Pagination';
6
- import {
7
- ProFormText,
8
- } from '@ant-design/pro-components';
9
- import "./index.scss"
8
+ import { get } from 'lodash';
9
+ import { Space, } from 'antd';
10
+ import { pageRequest, } from "./api"
10
11
 
12
+ import { ProFormText, } from '@ant-design/pro-components';
13
+ import { timeFormatter } from '../../../utils';
14
+
15
+ import "./index.scss"
11
16
  export interface RoleProps {
12
- dataList: any;
13
- columns: any;
14
- isLoading: any;
15
- handleRoload: () => any;
16
- pagination: any;
17
- handleOnReset: (item: any) => any;
18
- handleOnFinish: (item: any) => any;
17
+ historyAction: any;
19
18
  }
20
19
 
21
20
  export default function Role({
22
- dataList,
23
- columns,
24
- isLoading,
25
- handleRoload,
26
- pagination,
27
- handleOnReset,
28
- handleOnFinish
21
+ historyAction
29
22
  }: RoleProps) {
23
+ const searchFormRef: any = useRef()
24
+
25
+ useEffect(() => {
26
+ init()
27
+ execute()
28
+ }, [])
29
+
30
+ const init = () => {
31
+ }
32
+
33
+ const columns: any = [
34
+ {
35
+ title: '角色名称',
36
+ dataIndex: 'roleName',
37
+ key: 'roleName',
38
+ },
39
+ {
40
+ title: '角色编码',
41
+ dataIndex: 'roleCode',
42
+ key: 'roleCode',
43
+ },
44
+ {
45
+ title: '角色描述',
46
+ dataIndex: 'description',
47
+ key: 'description',
48
+ },
49
+ {
50
+ title: '创建时间',
51
+ dataIndex: 'gmtCreate',
52
+ key: 'gmtCreate',
53
+ render: (cell: any) => {
54
+ return timeFormatter(cell)
55
+ }
56
+ },
57
+ {
58
+ title: '更新时间',
59
+ dataIndex: 'gmtModified',
60
+ key: 'gmtModified',
61
+ render: (cell: any) => {
62
+ return timeFormatter(cell)
63
+ }
64
+ },
65
+ {
66
+ title: '操作',
67
+ width: 80,
68
+ fixed: "right",
69
+ render: (rowdata: any,) => <Space>
70
+ <a onClick={() => {
71
+ historyAction?.push({
72
+ pathname: `/role-info`,
73
+ search: `?roleCode=${rowdata.roleCode}`,
74
+ });
75
+ }}>赋予账号</a>
76
+ </Space>
77
+ },
78
+ ];
79
+
80
+ const handleOnReset: any = async (values: any) => {
81
+ searchFormRef.current = { ...values }
82
+ execute({
83
+ innerPageNo: 1,
84
+ })
85
+ }
86
+
87
+ const handleOnFinish: any = async (values: any) => {
88
+ searchFormRef.current = { ...values }
89
+ execute()
90
+ }
91
+
92
+ const readDataList = ({
93
+ innerPageNo,
94
+ innerPageSize,
95
+ }: any) => {
96
+ return pageRequest({
97
+ currentPage: innerPageNo,
98
+ pageSize: innerPageSize,
99
+ ...searchFormRef.current
100
+ }).then((res: any) => {
101
+ let records = get(res, "records", [])
102
+ let total = get(res, "total", 0)
103
+ return {
104
+ dataList: records,
105
+ totalCount: total
106
+ }
107
+ })
108
+ }
109
+
110
+ const { execute, dataList, isLoading, pagination } = useTableHooks({
111
+ asyncFunction: readDataList
112
+ })
113
+
114
+ const handleRoload = () => {
115
+ execute()
116
+ }
117
+
30
118
  return (
31
119
  <PageContainer >
32
120
  <QueryFilter
@@ -20,6 +20,7 @@ export default function index({
20
20
 
21
21
  useEffect(() => {
22
22
  form.resetFields()
23
+ if(open)queryByKeywordSearch('')
23
24
  }, [open])
24
25
 
25
26
  const editModelOpen = (type: boolean) => {
@@ -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
+ }
@@ -1,52 +1,197 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import useTableHooks from "../../../hooks/useTableHooks"
3
+
2
4
  import PageContainer from '../../base-component/PageContainer';
3
5
  import QueryFilter from '../../base-component/QueryFilter';
4
6
  import ProTable from '../../base-component/ProTable';
5
7
  import Pagination from '../../base-component/Pagination';
6
- import {
7
- ProFormText,
8
- } from '@ant-design/pro-components';
9
- import { Button, Divider, Modal, Descriptions, Space, } from 'antd';
8
+ import { get } from 'lodash';
9
+ import { ProFormText, } from '@ant-design/pro-components';
10
+ import { Button, Divider, Modal, Descriptions, Space, message } from 'antd';
10
11
  import EditAccountDrawer from './EditAccountDrawer/index'
11
-
12
+ import { timeFormatter, getUrlParams } from '../../../utils';
13
+ import {
14
+ pageBoundAccounts,
15
+ roleBoundAccounts,
16
+ roleUnboundAccounts,
17
+ getRole,
18
+ queryByKeyword
19
+ } from './api'
12
20
  import "./index.scss"
13
- export interface RoleProps {
14
- roleInfo: any;
15
- timeFormatter: (item: any) => any;
16
- handleOnReset: () => any;
17
- handleOnFinish: () => any;
18
- dataList: any;
19
- columns: any;
20
- isLoading: any;
21
- handleRoload: () => any;
22
- pagination: any;
23
- getQueryBoundRolesFunc: () => any;
24
- editAccountOpen: any
25
- setEditAccountOpen: (item: any) => any;
26
- roleBoundAccountsFunc: (item: any) => any;
27
- queryByKeywordFunc: (item: any) => any;
28
-
29
- // rolelistRoleData: any,
30
- // roleCheckData: any,
31
- }
32
- export default function RoleInfo({
33
- roleInfo,
34
- timeFormatter,
35
- handleOnReset,
36
- handleOnFinish,
37
- dataList,
38
- columns,
39
- isLoading,
40
- handleRoload,
41
- pagination,
42
- getQueryBoundRolesFunc,
43
- editAccountOpen,
44
- setEditAccountOpen,
45
- roleBoundAccountsFunc,
46
- queryByKeywordFunc
47
- }:RoleProps){
48
- return(
49
- <PageContainer>
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>
50
195
  <Divider orientation="left">{roleInfo?.roleName || "-"}</Divider>
51
196
  <Descriptions className="basicInfoWrap">
52
197
  <Descriptions.Item label="角色名称">{roleInfo?.roleName || ''}</Descriptions.Item>
@@ -0,0 +1,60 @@
1
+ import React, { useState } from 'react'
2
+ import { get } from "lodash"
3
+
4
+ function useTableHooks({
5
+ asyncFunction
6
+ }: any) {
7
+ const [isLoading, setIsLoading] = useState<any>(false)
8
+ const [pageNo, setPageNo] = useState(1)
9
+ const [pageSize, setPageSize] = useState(10)
10
+ const [total, setTotal] = useState(0)
11
+ const [dataList, setDataList] = useState([])
12
+
13
+ const execute: any = async (options: any) => {
14
+ const { innerPageNo = pageNo, innerPageSize = pageSize, ...otherOptions } = options || {}
15
+
16
+ setPageNo(innerPageNo);
17
+ setPageSize(innerPageSize);
18
+ setIsLoading(true);
19
+
20
+ try {
21
+ const res = await asyncFunction({
22
+ innerPageNo,
23
+ innerPageSize,
24
+ ...otherOptions
25
+ })
26
+
27
+ setIsLoading(false)
28
+
29
+ const list: any = get(res, "dataList", [])
30
+ const totalCount: any = get(res, "totalCount", 0)
31
+
32
+ setTotal(totalCount)
33
+ setDataList(list)
34
+
35
+ } catch {
36
+ setIsLoading(false)
37
+ }
38
+ }
39
+
40
+ const pagination = {
41
+ current: pageNo,
42
+ pageSize,
43
+ total,
44
+ onChange: (innerPageNo: number, innerPageSize: number) => {
45
+ execute({
46
+ innerPageNo,
47
+ innerPageSize
48
+ })
49
+ }
50
+ }
51
+
52
+ return {
53
+ execute,
54
+ pagination,
55
+ isLoading,
56
+ dataList,
57
+ }
58
+ }
59
+
60
+ export default useTableHooks
package/src/index.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import LiosLayout, { LiosLayoutlProps } from './components/layout'
2
+
2
3
  import PageContainer from './components/base-component/PageContainer'
3
4
  import QueryFilter from './components/base-component/QueryFilter'
4
5
  import ProTable from './components/base-component/ProTable'
@@ -7,7 +8,9 @@ import Account from './components/universal-pages/account'
7
8
  import AccountInfo from './components/universal-pages/accountInfo'
8
9
  import Role from './components/universal-pages/role'
9
10
  import RoleInfo from './components/universal-pages/roleInfo'
10
-
11
+ import request from './apiRequest/config'
12
+ import iotRequest from './apiRequest/iotConfig'
13
+ import { getUrlParams, downloadFile, timeFormatter } from './utils/index'
11
14
  export {
12
15
  LiosLayout,
13
16
  LiosLayoutlProps,
@@ -15,8 +18,15 @@ export {
15
18
  QueryFilter,
16
19
  ProTable,
17
20
  Pagination,
21
+
18
22
  Account,
19
23
  AccountInfo,
20
24
  Role,
21
- RoleInfo
25
+ RoleInfo,
26
+
27
+ request,
28
+ iotRequest,
29
+ getUrlParams,
30
+ downloadFile,
31
+ timeFormatter
22
32
  }
@@ -0,0 +1,29 @@
1
+ import dayjs from "dayjs"
2
+ //获取url上的参数
3
+ export const getUrlParams = (id: string) => {
4
+ let params = new URLSearchParams(location.search);
5
+ return params.get(id) || ""
6
+ }
7
+
8
+ export const downloadFile = (url: string, name: string, suffix?: string) => {
9
+ if (!url || !name) return
10
+ const link = document.createElement('a');
11
+ link.target = '_blank'
12
+ link.style.display = 'none';
13
+ fetch(url, {
14
+ method: 'post',
15
+ }).then(res => res.blob()).then((blob) => {
16
+ link.href = URL.createObjectURL(blob);
17
+ link.download = name + "." + (suffix || 'xlsx');
18
+ document.body.appendChild(link);
19
+ link.click();
20
+ link.remove();
21
+ });
22
+ }
23
+
24
+ export const timeFormatter = (timestamp: number, format?: string) => {
25
+ if (isNaN(Number(timestamp))) {
26
+ return "-"
27
+ }
28
+ return dayjs(timestamp).format(format || "YYYY-MM-DD HH:mm:ss")
29
+ }