kn-cli 1.0.107 → 1.0.108
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/package.json +1 -1
- package/templates/template_admin/cli.config.js +1 -0
- package/templates/template_admin/public/src/_mixin.less +38 -0
- package/templates/template_admin/public/src/_reset.less +0 -7
- package/templates/template_admin/public/src/assets/images/permission/403.png +0 -0
- package/templates/template_admin/public/src/assets/images/permission/404.png +0 -0
- package/templates/template_admin/public/src/assets/images/permission/503.png +0 -0
- package/templates/template_admin/public/src/components/antd/index.jsx +145 -0
- package/templates/template_admin/public/src/components/antd/tooltip/detail/index.jsx +70 -0
- package/templates/template_admin/public/src/components/antd/tooltip/detail/index.less +12 -0
- package/templates/template_admin/public/src/components/antd/tooltip/index.jsx +69 -0
- package/templates/template_admin/public/src/components/antd/tooltip/index.less +28 -0
- package/templates/template_admin/public/src/components/auth/index.jsx +60 -3
- package/templates/template_admin/public/src/components/auth/navCheck.jsx +27 -0
- package/templates/template_admin/public/src/components/button/index.jsx +17 -0
- package/templates/template_admin/public/src/components/debug/index.jsx +1 -1
- package/templates/template_admin/public/src/components/error/index.jsx +39 -0
- package/templates/template_admin/public/src/components/image/index.jsx +1 -1
- package/templates/template_admin/public/src/components/image/preview.jsx +1 -1
- package/templates/template_admin/public/src/components/layout/provider/index.jsx +2 -2
- package/templates/template_admin/public/src/components/leftMenu/index.jsx +31 -6
- package/templates/template_admin/public/src/components/menuIcon/index.jsx +33 -0
- package/templates/template_admin/public/src/components/menuIcon/index.less +49 -0
- package/templates/template_admin/public/src/components/react/index.jsx +7 -0
- package/templates/template_admin/public/src/components/select/defaultServicesSelect/index.jsx +182 -0
- package/templates/template_admin/public/src/components/select/dictSelect/index.jsx +84 -0
- package/templates/template_admin/public/src/components/select/index.jsx +7 -0
- package/templates/template_admin/public/src/components/select/useSelectList.jsx +217 -0
- package/templates/template_admin/public/src/components/table/index.jsx +1 -1
- package/templates/template_admin/public/src/components/text/index.jsx +1 -1
- package/templates/template_admin/public/src/components/topMenu/index.jsx +6 -1
- package/templates/template_admin/public/src/components/topMenu/index.less +10 -1
- package/templates/template_admin/public/src/components/topMenu/topBar/index.jsx +6 -1
- package/templates/template_admin/public/src/components/topMenu/topBar/index.less +9 -0
- package/templates/template_admin/public/src/config.js +28 -0
- package/templates/template_admin/public/src/dictionary/dictionary.js +289 -0
- package/templates/template_admin/public/src/dictionary/index.js +22 -126
- package/templates/template_admin/public/src/hooks/useRouteMenu.jsx +25 -3
- package/templates/template_admin/public/src/hooks/useThrottole.jsx +68 -0
- package/templates/template_admin/public/src/index.jsx +33 -15
- package/templates/template_admin/public/src/menuConfig.jsx +152 -0
- package/templates/template_admin/public/src/pages/auth/user/create/index.jsx +1 -9
- package/templates/template_admin/public/src/pages/auth/user/dialog/index.jsx +1 -1
- package/templates/template_admin/public/src/pages/auth/user/index.jsx +3 -60
- package/templates/template_admin/public/src/pages/components/select/user.jsx +18 -0
- package/templates/template_admin/public/src/pages/demo/page1.jsx +21 -0
- package/templates/template_admin/public/src/pages/demo/page2.jsx +21 -0
- package/templates/template_admin/public/src/pages/demo/page3.jsx +21 -0
- package/templates/template_admin/public/src/pages/error/403.jsx +15 -0
- package/templates/template_admin/public/src/pages/error/404.jsx +15 -0
- package/templates/template_admin/public/src/pages/error/503.jsx +15 -0
- package/templates/template_admin/public/src/pages/error/permission.jsx +40 -0
- package/templates/template_admin/public/src/pages/error/permission.less +16 -0
- package/templates/template_admin/public/src/pages/home.jsx +15 -4
- package/templates/template_admin/public/src/pages/login/index.jsx +3 -2
- package/templates/template_admin/public/src/pages/pageTemplate.jsx +28 -0
- package/templates/template_admin/public/src/provider/app.jsx +86 -55
- package/templates/template_admin/public/src/provider/menu.jsx +75 -108
- package/templates/template_admin/public/src/route.jsx +55 -35
- package/templates/template_admin/public/src/services/index.js +28 -4
- package/templates/template_admin/public/src/services/socket/index.jsx +1 -1
- package/templates/template_admin/public/src/utils/storage.js +30 -0
- package/templates/template_admin/webpack.api.js +24 -0
- package/templates/template_admin/public/src/pages/components/select/account/index.jsx +0 -114
- package/templates/template_admin/public/src/pages/components/select/device/index.jsx +0 -83
- package/templates/template_admin/public/src/pages/components/select/groupUser/index.jsx +0 -172
- package/templates/template_admin/public/src/pages/components/select/user/index.jsx +0 -119
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {Layout,SearchBar,TitleBar,Content,Panel} from './components/layout'
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import styles from './home.less';
|
|
7
|
+
|
|
8
|
+
const PageTemplate = (props) => {
|
|
9
|
+
const {name} = props;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Layout>
|
|
13
|
+
<SearchBar>
|
|
14
|
+
<TitleBar label={name}/>
|
|
15
|
+
</SearchBar>
|
|
16
|
+
|
|
17
|
+
<Content>
|
|
18
|
+
<Panel>
|
|
19
|
+
<section className={styles.row}>
|
|
20
|
+
</section>
|
|
21
|
+
</Panel>
|
|
22
|
+
</Content>
|
|
23
|
+
|
|
24
|
+
</Layout>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default PageTemplate;
|
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
|
-
import { useState,useMemo
|
|
2
|
+
import { useState,useMemo } from 'react';
|
|
3
3
|
// @ts-ignore
|
|
4
|
-
import { useSearchParams
|
|
4
|
+
import { useSearchParams } from 'react-router-dom';
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
import { createContainer } from "unstated-next";
|
|
7
7
|
|
|
8
8
|
// @ts-ignore
|
|
9
|
-
import { message } from "antd";
|
|
9
|
+
import { message } from "@/components/antd";
|
|
10
10
|
|
|
11
11
|
import {setJwt,setLogout} from '@/services';
|
|
12
12
|
|
|
13
13
|
import {jumpUrl} from '@/utils';
|
|
14
|
-
import { KSSO_LOGIN
|
|
14
|
+
import { KSSO_LOGIN } from '@/services/login';
|
|
15
|
+
import _Storage from '@/utils/storage';
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
const MODULE_NAME='ProviderApp';
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* @typedef AppContaniner
|
|
21
20
|
* @property {boolean} loading - 当前是否是加载状态
|
|
22
21
|
* @property {(open:boolean)=>void} setLoading - 设置加载状态
|
|
23
22
|
* @property {()=>Promise<boolean>} isLogin - 检查是否已登录状态
|
|
24
|
-
* @property {(username:string,password:string)=>Promise<boolean>} login - 触发登录
|
|
25
23
|
* @property {()=>Promise} logout - 注销病退回登录界面
|
|
26
|
-
* @property {(user:object)=>void} setUser - 注销病退回登录界面
|
|
27
24
|
* @property {(auths:string[])=>void} setAuths - 设置权限
|
|
28
25
|
* @property {object} user - 注销病退回登录界面
|
|
29
26
|
* @property {()=>Promise<boolean>} kssoLogin - 触发ksso登录
|
|
30
27
|
* @property {string[]} auths - 用户的权限列表
|
|
31
28
|
* @property {()=>void} clearLoginInfo - 清理用户登录信息
|
|
29
|
+
* @property {(authName:string|string[])=>boolean} hasAuth - 判断有误某些权限
|
|
30
|
+
* @property {(userData:any,reload?:boolean)=>Promise<boolean>} LoginSuccess - 登录成功后的校验
|
|
32
31
|
*
|
|
33
32
|
*/
|
|
34
33
|
|
|
@@ -39,41 +38,30 @@ const MODULE_NAME='ProviderApp';
|
|
|
39
38
|
*/
|
|
40
39
|
const useApp=() =>{
|
|
41
40
|
const [search] = useSearchParams();
|
|
42
|
-
const navigate= useNavigate();
|
|
43
41
|
const [loading,setLoading] = useState(true);
|
|
44
42
|
const [user,setUser] = useState(null);
|
|
45
43
|
/**
|
|
46
44
|
* @type {[string[],React.Dispatch<React.SetStateAction<string[]>>]}
|
|
47
45
|
*/
|
|
48
46
|
const [auths,setAuths]= useState(null);
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @type {React.MutableRefObject<object>}
|
|
52
|
-
*/
|
|
53
|
-
const refSelf = useRef();
|
|
54
|
-
const LocalStorageName='zeus-user';
|
|
55
47
|
|
|
56
|
-
|
|
57
48
|
const isLogin=async ()=>{
|
|
58
49
|
if(!user){
|
|
59
50
|
try{
|
|
60
|
-
let userData =
|
|
51
|
+
let userData = _Storage.load(_Storage.NAME.user)
|
|
61
52
|
if(userData){
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if(!auths){
|
|
68
|
-
await updateAuth();
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
53
|
+
setUser(userData);
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
setJwt(userData.token);
|
|
56
|
+
if(!auths){
|
|
57
|
+
await updateAuth();
|
|
71
58
|
}
|
|
59
|
+
return true;
|
|
72
60
|
}else{
|
|
73
|
-
|
|
61
|
+
jumpUrl('/#/login');
|
|
74
62
|
}
|
|
75
63
|
}catch(ex){
|
|
76
|
-
|
|
64
|
+
jumpUrl('/#/login');
|
|
77
65
|
}
|
|
78
66
|
}else{
|
|
79
67
|
if(!auths){
|
|
@@ -87,6 +75,31 @@ const useApp=() =>{
|
|
|
87
75
|
return true;
|
|
88
76
|
}
|
|
89
77
|
|
|
78
|
+
const LoginSuccess= async (userData,reload=false)=>{
|
|
79
|
+
const {token}= userData;
|
|
80
|
+
setUser(userData);
|
|
81
|
+
setJwt(token);
|
|
82
|
+
const authReq = await updateAuth();
|
|
83
|
+
if(authReq){
|
|
84
|
+
_Storage.write(_Storage.NAME.user,userData);
|
|
85
|
+
let redirect = _Storage.load(_Storage.NAME.redirect);
|
|
86
|
+
_Storage.remove(_Storage.NAME.redirect);
|
|
87
|
+
message.success('登录成功');
|
|
88
|
+
if(reload){
|
|
89
|
+
location.reload();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if(redirect){
|
|
93
|
+
jumpUrl(redirect,{replace:true});
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
jumpUrl('/',{replace:true});
|
|
97
|
+
return true;
|
|
98
|
+
}else{
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
90
103
|
const kssoLogin=async ()=>{
|
|
91
104
|
let code = search.get('code');
|
|
92
105
|
if(code){
|
|
@@ -94,27 +107,13 @@ const useApp=() =>{
|
|
|
94
107
|
const req = await KSSO_LOGIN({code,redirect_uri})
|
|
95
108
|
if(req?.code==0){
|
|
96
109
|
const userData = req?.data;
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
setJwt(token);
|
|
100
|
-
const authReq = await updateAuth();
|
|
101
|
-
if(authReq){
|
|
102
|
-
localStorage.setItem(LocalStorageName,JSON.stringify(userData));
|
|
103
|
-
let redirect = search.get('redirect');
|
|
104
|
-
message.success('登录成功');
|
|
105
|
-
if(redirect){
|
|
106
|
-
jumpUrl(redirect,{replace:true});
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
navigate('/');
|
|
110
|
-
}else{
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
110
|
+
const reqLogin = await LoginSuccess(userData);
|
|
111
|
+
return reqLogin;
|
|
113
112
|
}else{
|
|
114
|
-
|
|
115
|
-
setTimeout(()
|
|
116
|
-
jumpUrl('',{
|
|
117
|
-
},
|
|
113
|
+
message.error('ksso登录验证失败,即将重新登录');
|
|
114
|
+
setTimeout(()=>{
|
|
115
|
+
jumpUrl('/#/login',{replace:true});
|
|
116
|
+
},1000)
|
|
118
117
|
return false;
|
|
119
118
|
}
|
|
120
119
|
}else{
|
|
@@ -122,18 +121,48 @@ const useApp=() =>{
|
|
|
122
121
|
}
|
|
123
122
|
return true;
|
|
124
123
|
}
|
|
125
|
-
const logout=async ()=>{
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
const logout=async (changeAccount=false)=>{
|
|
125
|
+
try{
|
|
126
|
+
clearLoginInfo();
|
|
127
|
+
}finally{
|
|
128
|
+
// 防止在登录页出现401导致重定向又回login页面反复
|
|
129
|
+
if( !/[#]\/login/.test(location.href)){
|
|
130
|
+
_Storage.write(_Storage.NAME.redirect,location.href)
|
|
131
|
+
}
|
|
132
|
+
const redirect = `${location.protocol}//${location.host}/#/login`;
|
|
133
|
+
if(!changeAccount || user?.type!=1){
|
|
134
|
+
jumpUrl(redirect,{replace:true});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if(changeAccount){
|
|
138
|
+
jumpUrl(`https://ksso.kingnet.com/auth/logout?redirect=${encodeURIComponent(redirect)}`,{replace:true})
|
|
139
|
+
}
|
|
140
|
+
}
|
|
128
141
|
}
|
|
129
142
|
const clearLoginInfo=()=>{
|
|
130
|
-
|
|
131
|
-
localStorage.removeItem(LocalStorageName);
|
|
143
|
+
_Storage.remove(_Storage.NAME.user);
|
|
132
144
|
setUser(null);
|
|
133
145
|
setAuths(null);
|
|
134
146
|
setJwt('');
|
|
135
147
|
}
|
|
136
148
|
|
|
149
|
+
|
|
150
|
+
const hasAuth=(name)=>{
|
|
151
|
+
let req=false;
|
|
152
|
+
if(Array.isArray(name)){
|
|
153
|
+
for(let i=0;i<name.length;i++){
|
|
154
|
+
let authName = name[i];
|
|
155
|
+
if(auths?.includes(authName)){
|
|
156
|
+
req=true;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} else if(auths?.includes(name)){
|
|
161
|
+
req=true;
|
|
162
|
+
}
|
|
163
|
+
return req;
|
|
164
|
+
}
|
|
165
|
+
|
|
137
166
|
setLogout(logout);
|
|
138
167
|
|
|
139
168
|
|
|
@@ -148,9 +177,11 @@ const useApp=() =>{
|
|
|
148
177
|
kssoLogin,
|
|
149
178
|
auths,
|
|
150
179
|
setAuths,
|
|
151
|
-
clearLoginInfo
|
|
180
|
+
clearLoginInfo,
|
|
181
|
+
LoginSuccess,
|
|
182
|
+
hasAuth,
|
|
152
183
|
}
|
|
153
|
-
},[clearLoginInfo,loading,user,isLogin,kssoLogin,auths]);
|
|
184
|
+
},[clearLoginInfo,loading,user,isLogin,kssoLogin,auths,LoginSuccess,hasAuth]);
|
|
154
185
|
|
|
155
186
|
return action
|
|
156
187
|
}
|
|
@@ -8,111 +8,8 @@ import { createContainer } from "unstated-next"
|
|
|
8
8
|
import useRouteMenu from '@/hooks/useRouteMenu';
|
|
9
9
|
import ProviderApp from '@/provider/app';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const MenuIcon=(props)=>{
|
|
16
|
-
|
|
17
|
-
const [icon,setIcon]= useState('');
|
|
18
|
-
const [iconActive,setIconActive]= useState('');
|
|
19
|
-
|
|
20
|
-
const getIcon= async (iconName)=>{
|
|
21
|
-
const req = await new Promise(resolve=>{
|
|
22
|
-
let iconActive =import(`@/assets/images/nav/${iconName}-active.png`);
|
|
23
|
-
let icon = import(`@/assets/images/nav/${iconName}.png`);
|
|
24
|
-
Promise.all([icon,iconActive]).then(values=>{
|
|
25
|
-
setIcon(values[0].default);
|
|
26
|
-
setIconActive(values[1].default)
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
useEffect(()=>{
|
|
31
|
-
getIcon(props.name);
|
|
32
|
-
},[])
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<div className={styles.iconGroup}>
|
|
36
|
-
<img className={styles.icon} src={icon} />
|
|
37
|
-
<img className={styles.iconActive} src={iconActive} />
|
|
38
|
-
</div>
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const MenuRoute=[
|
|
44
|
-
{
|
|
45
|
-
name:'仪表盘',
|
|
46
|
-
url:'/',
|
|
47
|
-
children:[
|
|
48
|
-
],
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name:'发射场',
|
|
53
|
-
url:'/jet',
|
|
54
|
-
children:[],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name:'弹药库',
|
|
58
|
-
url:'/store',
|
|
59
|
-
children:[],
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name:'配件仓',
|
|
63
|
-
url:'/parts',
|
|
64
|
-
children:[],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name:'基因库',
|
|
68
|
-
url:'/dna',
|
|
69
|
-
children:[],
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name:'控制室',
|
|
73
|
-
url:'/auth',
|
|
74
|
-
msgCount:12,
|
|
75
|
-
primaryId:'auth',
|
|
76
|
-
children:[
|
|
77
|
-
{
|
|
78
|
-
name: '用户',
|
|
79
|
-
icon:<MenuIcon name='icon-user'/>,
|
|
80
|
-
url: '/auth/user',
|
|
81
|
-
auth:true,
|
|
82
|
-
primaryId:'authUser',
|
|
83
|
-
msgCount:0,
|
|
84
|
-
children:[
|
|
85
|
-
{
|
|
86
|
-
name:'新建用户',
|
|
87
|
-
url:'/auth/user/create',
|
|
88
|
-
hideMenu:true
|
|
89
|
-
}
|
|
90
|
-
]
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: '部门',
|
|
94
|
-
icon:<MenuIcon name='icon-dep'/>,
|
|
95
|
-
url: '/auth/dep',
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: '角色',
|
|
99
|
-
icon:<MenuIcon name='icon-role'/>,
|
|
100
|
-
url: '/auth/role',
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
name: '操作记录',
|
|
104
|
-
icon:<MenuIcon name='icon-log'/>,
|
|
105
|
-
url: '/auth/log',
|
|
106
|
-
msgCount:12,
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
name: '登录日志',
|
|
110
|
-
icon:<MenuIcon name='icon-loginlog'/>,
|
|
111
|
-
url: '/auth/loginLog',
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
}
|
|
115
|
-
]
|
|
11
|
+
import MenuConfig from '@/menuConfig';
|
|
12
|
+
import { AUTH_ROUTE_DEBUG_OPEN } from '@/config';
|
|
116
13
|
|
|
117
14
|
|
|
118
15
|
/**
|
|
@@ -123,12 +20,14 @@ const MenuRoute=[
|
|
|
123
20
|
* @property {(key:string)=>RouteMenuItem} findMenuData - 通过key查找菜单数据
|
|
124
21
|
* @property {(params:MenuConfig[])=>void} setMenuConfig - 设置菜单属性
|
|
125
22
|
* @property {()=>Promise<void>} reload - 重新加载渲染菜单
|
|
23
|
+
* @property {(pathname:string,auths:string[])=>any} getMenuNavigateTo - 获取菜单跳转匹配结果
|
|
24
|
+
*
|
|
126
25
|
*/
|
|
127
26
|
|
|
128
27
|
const useProvider=() =>{
|
|
129
|
-
|
|
28
|
+
const MenuRoute=MenuConfig;
|
|
130
29
|
const app = ProviderApp.useContainer();
|
|
131
|
-
const routeMenu = useRouteMenu();
|
|
30
|
+
const routeMenu = useRouteMenu({source:[...MenuRoute.map(menu=>{menu.key=menu.name;return menu})]});
|
|
132
31
|
const curLocation =useLocation();
|
|
133
32
|
const [topMenu,setTopMenu]=useState([]);
|
|
134
33
|
const [leftMenu,setLeftMenu]=useState([]);
|
|
@@ -163,6 +62,74 @@ const useProvider=() =>{
|
|
|
163
62
|
routeMenu.setMenuConfig(params);
|
|
164
63
|
}
|
|
165
64
|
|
|
65
|
+
const checkAuthMenu=(menu,userAuth=[])=>{
|
|
66
|
+
if(AUTH_ROUTE_DEBUG_OPEN)return true;
|
|
67
|
+
let auth=true;
|
|
68
|
+
if(menu.auth && Array.isArray(menu.auth)){
|
|
69
|
+
if(menu.auth.some(menuAuthName=>userAuth?.includes(menuAuthName)) == false){
|
|
70
|
+
auth=false;
|
|
71
|
+
}
|
|
72
|
+
}else{
|
|
73
|
+
return menu.auth;
|
|
74
|
+
}
|
|
75
|
+
return auth;
|
|
76
|
+
}
|
|
77
|
+
const findHasAuthMenu=(menu,userAuth=[])=>{
|
|
78
|
+
let req;
|
|
79
|
+
req = checkAuthMenu(menu,userAuth);
|
|
80
|
+
if(req){return menu;}
|
|
81
|
+
if(!menu.parent)return null;
|
|
82
|
+
let {children} = menu.parent;
|
|
83
|
+
for(let i=0;i<children.length;i++){
|
|
84
|
+
let _menu = children[i];
|
|
85
|
+
req = checkAuthMenu(_menu,userAuth);
|
|
86
|
+
if(req)return _menu;
|
|
87
|
+
}
|
|
88
|
+
if(menu.parent.noPage)return null;
|
|
89
|
+
req = findHasAuthMenu(menu.parent,userAuth);
|
|
90
|
+
return req;
|
|
91
|
+
}
|
|
92
|
+
const getHasAuthMenu=(menus,userAuth=[])=>{
|
|
93
|
+
for(let i=0;i<menus.length;i++){
|
|
94
|
+
const menu = menus[i];
|
|
95
|
+
|
|
96
|
+
if(!menu.noPage){
|
|
97
|
+
let req = checkAuthMenu(menu,userAuth);
|
|
98
|
+
if(req)return menu;
|
|
99
|
+
}else{
|
|
100
|
+
if(checkAuthMenu(menu,userAuth)){
|
|
101
|
+
if(menu.children){
|
|
102
|
+
let req = getHasAuthMenu(menu.children,userAuth);
|
|
103
|
+
if(req)return req;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 检查当前路由是否有权限访问,没有权限则匹配有权限访问的页面进行跳转
|
|
113
|
+
*/
|
|
114
|
+
const getMenuNavigateTo= (pathname,userAuths=[])=>{
|
|
115
|
+
// if(pathname=='/401'||pathname=='/404'||pathname=='/')return;
|
|
116
|
+
let curMenu = routeMenu.getMatchMenu(pathname)
|
|
117
|
+
// 找不到页面
|
|
118
|
+
if(!curMenu){
|
|
119
|
+
console.error('匹配不到路由,跳转404:',pathname)
|
|
120
|
+
return 404;
|
|
121
|
+
}
|
|
122
|
+
let req = checkAuthMenu(curMenu,userAuths);
|
|
123
|
+
// 有权限,不做任何处理
|
|
124
|
+
if(req)return curMenu;
|
|
125
|
+
let findMenu = findHasAuthMenu(curMenu,userAuths)
|
|
126
|
+
if(!findMenu){
|
|
127
|
+
return 403;
|
|
128
|
+
}else{
|
|
129
|
+
return findMenu;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
166
133
|
useEffect(()=>{
|
|
167
134
|
let menus= routeMenu.getOpenMenus(curLocation.pathname);
|
|
168
135
|
let keys=menus.map(item=>item.key);
|
|
@@ -174,7 +141,7 @@ const useProvider=() =>{
|
|
|
174
141
|
getLeftMenu(app.auths);
|
|
175
142
|
},[routeMenu.source,curLocation,app.auths])
|
|
176
143
|
|
|
177
|
-
return {leftMenu,topMenu,reload,selectMenus,findMenuData,setMenuConfig}
|
|
144
|
+
return {leftMenu,topMenu,reload,selectMenus,findMenuData,setMenuConfig,getMenuNavigateTo}
|
|
178
145
|
}
|
|
179
146
|
|
|
180
147
|
/**
|
|
@@ -1,25 +1,52 @@
|
|
|
1
1
|
import React,{Suspense} from 'react';
|
|
2
2
|
// @ts-ignore
|
|
3
|
-
import { Routes, Route, Navigate } from 'react-router-dom';
|
|
3
|
+
import { HashRouter, Routes, Route, Navigate } from 'react-router-dom';
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
import { LayoutBasic, AbsoluteLayout } from '@/components/layout';
|
|
6
|
+
import ErrorBoundary from '@/components/error';
|
|
7
|
+
|
|
8
|
+
|
|
6
9
|
import PageLoading from '@/components/page/pageLoading';
|
|
7
10
|
import { AuthLogin } from '@/components/auth';
|
|
11
|
+
import NavCheck from '@/components/auth/navCheck';
|
|
12
|
+
|
|
8
13
|
|
|
9
14
|
import LeftMenu from '@/components/leftMenu';
|
|
10
15
|
import TopMenu from '@/components/topMenu';
|
|
11
16
|
import ProviderMenu from '@/provider/menu';
|
|
12
|
-
|
|
13
17
|
import Login from '@/pages/login';
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
import menuConfig from './menuConfig';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const Page403 = React.lazy(() => import('@/pages/error/403'));
|
|
23
|
+
const Page404 = React.lazy(() => import('@/pages/error/404'));
|
|
24
|
+
const Page503 = React.lazy(() => import('@/pages/error/503'));
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const renderMenuConfig=(menu)=>{
|
|
28
|
+
let req=[];
|
|
29
|
+
if(menu.component){
|
|
30
|
+
console.log(`${menu.routeTemplate||menu.url}->component`)
|
|
31
|
+
req.push(
|
|
32
|
+
<Route path={menu.routeTemplate||menu.url} element={menu.component} />
|
|
33
|
+
)
|
|
34
|
+
}else{
|
|
35
|
+
if(menu.children && menu.children[0]){
|
|
36
|
+
console.log(`${menu.routeTemplate||menu.url}->${menu.children[0].url}`)
|
|
37
|
+
req.push(
|
|
38
|
+
<Route path={menu.routeTemplate||menu.url} element={<NavCheck to={menu.children[0].url} />} />
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if(menu.children){
|
|
43
|
+
menu.children.forEach(child=>{
|
|
44
|
+
let menus = renderMenuConfig(child);
|
|
45
|
+
req = [...req,...menus];
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
return req;
|
|
49
|
+
}
|
|
23
50
|
export const RouteList = (
|
|
24
51
|
<Routes>
|
|
25
52
|
<Route path='/' element={
|
|
@@ -37,32 +64,25 @@ export const RouteList = (
|
|
|
37
64
|
</ProviderMenu.Provider>
|
|
38
65
|
}
|
|
39
66
|
>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<Route path='/
|
|
45
|
-
|
|
46
|
-
<Route path='
|
|
47
|
-
{/* 控制室-角色 */}
|
|
48
|
-
<Route path='/auth/role' element={<Home />} />
|
|
49
|
-
{/* 控制室-操作记录 */}
|
|
50
|
-
<Route path='/auth/log' element={<Home />} />
|
|
51
|
-
{/* 控制室-登录日志 */}
|
|
52
|
-
<Route path='/auth/loginLog' element={<Home />} />
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<Route path='/jet' element={<Home />} />
|
|
56
|
-
<Route path='/store' element={<Home />} />
|
|
57
|
-
<Route path='/parts' element={<Home />} />
|
|
58
|
-
<Route path='/dna' element={<Home />} />
|
|
59
|
-
<Route path='/auth/dep' element={<Home />} />
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
{
|
|
68
|
+
menuConfig.map(menu=>renderMenuConfig(menu))
|
|
69
|
+
}
|
|
70
|
+
<Route path='/403' element={<Page403/>} />
|
|
71
|
+
<Route path='/404' element={<Page404/>} />
|
|
72
|
+
<Route path='/503' element={<Page503/>} />
|
|
73
|
+
<Route path='*' element={<Navigate to='/404' />} />
|
|
64
74
|
</Route>
|
|
65
75
|
</Route>
|
|
66
76
|
</Routes>
|
|
67
77
|
);
|
|
68
78
|
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
export default ()=>(
|
|
83
|
+
<HashRouter>
|
|
84
|
+
<ErrorBoundary>
|
|
85
|
+
{RouteList}
|
|
86
|
+
</ErrorBoundary>
|
|
87
|
+
</HashRouter>
|
|
88
|
+
)
|
|
@@ -3,14 +3,19 @@ import Axios from 'axios';
|
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import qs from 'qs';
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import { message } from 'antd';
|
|
6
|
+
import { message } from '@/components/antd';
|
|
7
7
|
import {WriteLog} from '@/utils';
|
|
8
8
|
|
|
9
|
+
import {DEBUG_API_HOST,DEBUG_REPORT_API_HOST } from '@/config';
|
|
10
|
+
|
|
11
|
+
|
|
9
12
|
const axios = Axios.create();
|
|
13
|
+
|
|
10
14
|
// @ts-ignore
|
|
11
|
-
|
|
15
|
+
export const API_ROOT= BUILD_ENV=='localdebug'?DEBUG_API_HOST:API_HOST;
|
|
12
16
|
// @ts-ignore
|
|
13
|
-
|
|
17
|
+
console.log(`========API_ROOT:${API_ROOT}========`);
|
|
18
|
+
|
|
14
19
|
const tokenMode='header';//header,cookie
|
|
15
20
|
const tokenName='Authorization';
|
|
16
21
|
|
|
@@ -80,6 +85,7 @@ axios.interceptors.response.use(
|
|
|
80
85
|
// setJwt(response?.headers['set-token'] || jwt);
|
|
81
86
|
ERROR_401_COUNT=0;
|
|
82
87
|
// 不需要接口统一处理异常错误
|
|
88
|
+
// @ts-ignore
|
|
83
89
|
if (response.config.noInterceptors) {
|
|
84
90
|
return response;
|
|
85
91
|
}
|
|
@@ -342,9 +348,27 @@ export const FormatTableService = (response)=>{
|
|
|
342
348
|
*/
|
|
343
349
|
export const FormatGetRequest=(requestParams)=>{
|
|
344
350
|
for(let key in requestParams){
|
|
345
|
-
if(requestParams[key]==''
|
|
351
|
+
if(requestParams[key]==''
|
|
352
|
+
||requestParams[key]===null
|
|
353
|
+
||requestParams[key]==undefined
|
|
354
|
+
){
|
|
346
355
|
delete requestParams[key];
|
|
347
356
|
}
|
|
348
357
|
}
|
|
349
358
|
return requestParams;
|
|
350
359
|
}
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* 清理以_开头的不参与接口提交的参数
|
|
364
|
+
* @param {object} requestParams
|
|
365
|
+
* @returns {object}
|
|
366
|
+
*/
|
|
367
|
+
export const FormatRequestClean=(requestParams)=>{
|
|
368
|
+
for(let key in requestParams){
|
|
369
|
+
if(/^[_].*/.test(key)){
|
|
370
|
+
delete requestParams[key];
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return requestParams;
|
|
374
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
const prevName='admin';
|
|
3
|
+
const STORAGE_NAME={
|
|
4
|
+
user:'user',
|
|
5
|
+
dep:'dep',
|
|
6
|
+
redirect:'redirect'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const load=(name)=>{
|
|
10
|
+
let value = localStorage.getItem(prevName+name);
|
|
11
|
+
if(value){
|
|
12
|
+
value = JSON.parse(value);
|
|
13
|
+
}
|
|
14
|
+
let _value = value || null;
|
|
15
|
+
return _value;
|
|
16
|
+
}
|
|
17
|
+
const write=(name,data)=>{
|
|
18
|
+
if(!data){
|
|
19
|
+
localStorage.removeItem(prevName+name);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
data = JSON.stringify(data);
|
|
23
|
+
localStorage.setItem(prevName+name,data);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const remove=(name)=>{
|
|
27
|
+
localStorage.removeItem(prevName+name);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default {load,write,remove,NAME:STORAGE_NAME};
|