kn-cli 1.0.91 → 1.0.93
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/readme.md +3 -0
- package/src/.DS_Store +0 -0
- package/templates/template_admin/.gitignore +6 -0
- package/templates/template_admin/public/index.html +5 -2
- package/templates/template_admin/public/src/_antd.less +7 -1
- package/templates/template_admin/public/src/components/menu/index.jsx +47 -100
- package/templates/template_admin/public/src/components/menu/topMenu/index.jsx +119 -0
- package/templates/template_admin/public/src/dictionary/index.js +4 -1
- package/templates/template_admin/public/src/hooks/index.jsx +4 -1
- package/templates/template_admin/public/src/hooks/useRouteMenu.jsx +232 -0
- package/templates/template_admin/public/src/provider/menu.jsx +261 -10
- package/templates/template_admin/public/src/route.jsx +18 -9
- package/templates/template_app/.gitignore +6 -0
- package/templates/template_oa/.gitignore +6 -0
- package/templates/template_oa/jsconfig.json +5 -1
- package/templates/template_oa/public/src/components/dialog/index.jsx +237 -0
- package/templates/template_oa/public/src/components/{Empty → empty}/index.jsx +9 -0
- package/templates/{template_oa_jwt/public/src/components/FormRow → template_oa/public/src/components/formRow}/index.jsx +25 -3
- package/templates/{template_oa_jwt/public/src/components/FormTable → template_oa/public/src/components/formTable}/index.jsx +39 -1
- package/templates/template_oa/public/src/components/iconFont/index.jsx +22 -0
- package/templates/template_oa/public/src/components/{IFrame → iframe}/index.jsx +18 -4
- package/templates/template_oa/public/src/components/{Layout/Basic → layout/basic}/index.jsx +7 -1
- package/templates/{template_oa_jwt/public/src/components/Layout/CenterBody → template_oa/public/src/components/layout/centerBody}/index.jsx +2 -0
- package/templates/{template_oa_jwt/public/src/components/Layout/FormBlock → template_oa/public/src/components/layout/formBlock}/index.jsx +3 -1
- package/templates/template_oa/public/src/components/{Layout → layout}/index.jsx +12 -6
- package/templates/{template_oa_jwt/public/src/components/Layout/Provider → template_oa/public/src/components/layout/provider}/index.jsx +4 -0
- package/templates/template_oa/public/src/components/{Link → link}/index.jsx +16 -0
- package/templates/template_oa/public/src/components/{Nav → nav}/index.jsx +8 -2
- package/templates/{template_oa_jwt/public/src/components/Page/PageLoading → template_oa/public/src/components/page/pageLoading}/index.jsx +25 -4
- package/templates/template_oa/public/src/components/{Popup → popup}/index.jsx +13 -0
- package/templates/template_oa/public/src/components/{Select/DepSelect → select/depSelect}/index.jsx +15 -0
- package/templates/template_oa/public/src/components/{Select/StaffSelect → select/staffSelect}/index.jsx +27 -0
- package/templates/template_oa/public/src/components/title/index.jsx +3 -0
- package/templates/template_oa/public/src/components/{Toast → toast}/index.jsx +21 -1
- package/templates/template_oa/public/src/components/{Upload → upload}/index.jsx +41 -3
- package/templates/template_oa/public/src/hooks/index.jsx +1 -0
- package/templates/template_oa/public/src/hooks/useDelay.jsx +5 -0
- package/templates/template_oa/public/src/hooks/useImageLoader.jsx +1 -2
- package/templates/template_oa/public/src/hooks/useLoading.jsx +5 -1
- package/templates/template_oa/public/src/hooks/usePreload.jsx +2 -1
- package/templates/template_oa/public/src/hooks/useScrollTop.jsx +12 -0
- package/templates/template_oa/public/src/hooks/useSearch.jsx +28 -2
- package/templates/template_oa/public/src/hooks/useUpdate.jsx +5 -0
- package/templates/template_oa/public/src/index.jsx +15 -1
- package/templates/template_oa/public/src/pages/video/index.jsx +17 -13
- package/templates/template_oa/public/src/provider/app.jsx +33 -2
- package/templates/template_oa/public/src/route.jsx +4 -2
- package/templates/template_oa/public/src/services/common.js +11 -0
- package/templates/template_oa/public/src/services/index.js +44 -2
- package/templates/template_oa/public/src/type.js +48 -0
- package/templates/template_oa/public/src/utils/index.js +34 -17
- package/templates/template_oa_jwt/.gitignore +6 -0
- package/templates/template_oa_jwt/jsconfig.json +5 -1
- package/templates/template_oa_jwt/public/src/components/dialog/index.jsx +237 -0
- package/templates/template_oa_jwt/public/src/components/{Empty → empty}/index.jsx +9 -0
- package/templates/{template_oa/public/src/components/FormRow → template_oa_jwt/public/src/components/formRow}/index.jsx +25 -3
- package/templates/{template_oa/public/src/components/FormTable → template_oa_jwt/public/src/components/formTable}/index.jsx +41 -2
- package/templates/template_oa_jwt/public/src/components/formTable/index.less +18 -0
- package/templates/template_oa_jwt/public/src/components/iconFont/index.jsx +22 -0
- package/templates/template_oa_jwt/public/src/components/{IFrame → iframe}/index.jsx +15 -0
- package/templates/template_oa_jwt/public/src/components/{Layout/Basic → layout/basic}/index.jsx +11 -6
- package/templates/{template_oa/public/src/components/Layout/CenterBody → template_oa_jwt/public/src/components/layout/centerBody}/index.jsx +2 -0
- package/templates/{template_oa/public/src/components/Layout/FormBlock → template_oa_jwt/public/src/components/layout/formBlock}/index.jsx +3 -1
- package/templates/template_oa_jwt/public/src/components/{Layout → layout}/index.jsx +10 -4
- package/templates/{template_oa/public/src/components/Layout/Provider → template_oa_jwt/public/src/components/layout/provider}/index.jsx +4 -0
- package/templates/template_oa_jwt/public/src/components/{Link → link}/index.jsx +16 -0
- package/templates/template_oa_jwt/public/src/components/{Nav → nav}/index.jsx +11 -5
- package/templates/{template_oa/public/src/components/Page/PageLoading → template_oa_jwt/public/src/components/page/pageLoading}/index.jsx +25 -4
- package/templates/template_oa_jwt/public/src/components/{Popup → popup}/index.jsx +13 -0
- package/templates/template_oa_jwt/public/src/components/{Select/DepSelect → select/depSelect}/index.jsx +15 -0
- package/templates/template_oa_jwt/public/src/components/{Select/StaffSelect → select/staffSelect}/index.jsx +27 -0
- package/templates/template_oa_jwt/public/src/components/title/index.jsx +3 -0
- package/templates/template_oa_jwt/public/src/components/{Toast → toast}/index.jsx +21 -1
- package/templates/template_oa_jwt/public/src/components/{Upload → upload}/index.jsx +41 -3
- package/templates/template_oa_jwt/public/src/dictionary/index.js +2 -0
- package/templates/template_oa_jwt/public/src/hooks/index.jsx +2 -2
- package/templates/template_oa_jwt/public/src/hooks/useDelay.jsx +5 -0
- package/templates/template_oa_jwt/public/src/hooks/useImageLoader.jsx +1 -2
- package/templates/template_oa_jwt/public/src/hooks/useLoading.jsx +5 -1
- package/templates/template_oa_jwt/public/src/hooks/usePreload.jsx +2 -1
- package/templates/template_oa_jwt/public/src/hooks/useScrollTop.jsx +12 -0
- package/templates/template_oa_jwt/public/src/hooks/useSearch.jsx +28 -2
- package/templates/template_oa_jwt/public/src/hooks/useUpdate.jsx +5 -0
- package/templates/template_oa_jwt/public/src/pages/demo/index.jsx +17 -11
- package/templates/template_oa_jwt/public/src/provider/app.jsx +30 -1
- package/templates/template_oa_jwt/public/src/route.jsx +4 -2
- package/templates/template_oa_jwt/public/src/services/common.js +13 -1
- package/templates/template_oa_jwt/public/src/services/index.js +52 -8
- package/templates/template_oa_jwt/public/src/services/token.js +7 -0
- package/templates/template_oa_jwt/public/src/utils/index.js +62 -22
- package/templates/template_offcial/.gitignore +6 -0
- package/templates/template_admin/public/src/components/topMenu/index.jsx +0 -267
- package/templates/template_oa/public/src/components/Alert/index.jsx +0 -0
- package/templates/template_oa/public/src/components/Alert/index.less +0 -0
- package/templates/template_oa/public/src/components/Auth/index.jsx +0 -44
- package/templates/template_oa/public/src/components/Dialog/index.jsx +0 -150
- package/templates/template_oa/public/src/components/Footer/index.jsx +0 -17
- package/templates/template_oa/public/src/components/Footer/index.less +0 -28
- package/templates/template_oa/public/src/components/IconFont/index.jsx +0 -10
- package/templates/template_oa/public/src/components/Loading/index.jsx +0 -14
- package/templates/template_oa/public/src/components/Loading/index.less +0 -85
- package/templates/template_oa_jwt/public/src/components/Alert/index.jsx +0 -0
- package/templates/template_oa_jwt/public/src/components/Alert/index.less +0 -0
- package/templates/template_oa_jwt/public/src/components/Auth/index.jsx +0 -44
- package/templates/template_oa_jwt/public/src/components/Dialog/index.jsx +0 -150
- package/templates/template_oa_jwt/public/src/components/Footer/index.jsx +0 -17
- package/templates/template_oa_jwt/public/src/components/Footer/index.less +0 -28
- package/templates/template_oa_jwt/public/src/components/IconFont/index.jsx +0 -10
- package/templates/template_oa_jwt/public/src/components/Loading/index.jsx +0 -16
- package/templates/template_oa_jwt/public/src/components/Loading/index.less +0 -96
- /package/templates/template_admin/public/src/components/{topMenu → menu/topMenu}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Dialog → dialog}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Empty → empty}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{FormRow → formRow}/index.less +0 -0
- /package/templates/{template_oa_jwt/public/src/components/FormTable → template_oa/public/src/components/formTable}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{IconFont → iconFont}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{IFrame → iframe}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Layout/Basic → layout/basic}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Layout/CenterBody → layout/centerBody}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Layout/FormBlock → layout/formBlock}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Layout → layout}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Link → link}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Nav → nav}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Page/PageLoading → page/pageLoading}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Popup → popup}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Select/StaffSelect → select/staffSelect}/index.less +0 -0
- /package/templates/template_oa/public/src/components/{Toast → toast}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Dialog → dialog}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Empty → empty}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{FormRow → formRow}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{IconFont → iconFont}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{IFrame → iframe}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Layout/Basic → layout/basic}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Layout/CenterBody → layout/centerBody}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Layout/FormBlock → layout/formBlock}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Layout → layout}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Link → link}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Nav → nav}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Page/PageLoading → page/pageLoading}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Popup → popup}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Select/StaffSelect → select/staffSelect}/index.less +0 -0
- /package/templates/template_oa_jwt/public/src/components/{Toast → toast}/index.less +0 -0
package/package.json
CHANGED
package/readme.md
CHANGED
package/src/.DS_Store
ADDED
|
Binary file
|
|
@@ -21,8 +21,11 @@
|
|
|
21
21
|
var docEl = document.documentElement;
|
|
22
22
|
function setRemUnit(type) {
|
|
23
23
|
let w = Math.max(window.innerWidth, docEl.clientWidth, docEl.offsetWidth);
|
|
24
|
-
let defaultWidth =
|
|
25
|
-
|
|
24
|
+
let defaultWidth = 1440;//填入设计稿上的宽度
|
|
25
|
+
let minWidth=1200;
|
|
26
|
+
let maxWidth=1440;
|
|
27
|
+
w = w < minWidth ? minWidth :w;
|
|
28
|
+
w = w > maxWidth ? maxWidth :w;
|
|
26
29
|
var rem = w / defaultWidth * 100;
|
|
27
30
|
docEl.style.fontSize = rem + 'px'
|
|
28
31
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import React, { useEffect, useRef, useState } from 'react';
|
|
3
3
|
// @ts-ignore
|
|
4
|
-
import { Menu } from 'antd';
|
|
4
|
+
import { Menu,Badge } from 'antd';
|
|
5
5
|
// @ts-ignore
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { AppstoreOutlined, MailOutlined, SettingOutlined } from '@ant-design/icons';
|
|
6
|
+
import {useNavigate,} from 'react-router-dom';
|
|
7
|
+
|
|
9
8
|
|
|
10
9
|
import {useLoading} from '@/hooks/index';
|
|
11
10
|
import ProviderMenu from '@/provider/menu';
|
|
@@ -13,11 +12,6 @@ import ProviderMenu from '@/provider/menu';
|
|
|
13
12
|
// @ts-ignore
|
|
14
13
|
import styles from './index.less';
|
|
15
14
|
|
|
16
|
-
const ICON_NAME={
|
|
17
|
-
'AppstoreOutlined':<AppstoreOutlined />,
|
|
18
|
-
'MailOutlined':<MailOutlined />,
|
|
19
|
-
'SettingOutlined':<SettingOutlined />,
|
|
20
|
-
}
|
|
21
15
|
|
|
22
16
|
|
|
23
17
|
|
|
@@ -28,113 +22,66 @@ const ICON_NAME={
|
|
|
28
22
|
*/
|
|
29
23
|
const LeftMenu=()=>{
|
|
30
24
|
|
|
25
|
+
|
|
31
26
|
const providerMenu = ProviderMenu.useContainer();
|
|
32
27
|
const loader = useLoading();
|
|
33
28
|
const [menus,setMenus] = useState([]);
|
|
34
|
-
const [
|
|
35
|
-
const [selectedKeys,setSelectKeys] = useState([]);
|
|
36
|
-
const curRoute = useLocation();
|
|
29
|
+
const [subMenuOpen,setSubMenuOpen]= useState([]);
|
|
37
30
|
const nav = useNavigate();
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
label:`${label}`,
|
|
47
|
-
source:data,
|
|
48
|
-
path,
|
|
49
|
-
routepath:parent?`${parent.key}-${myKey}`:myKey
|
|
50
|
-
}
|
|
51
|
-
MENU_KEY.current[myKey] = item;
|
|
52
|
-
MENU_KEY_COUNTER.current++;
|
|
53
|
-
if(icon){
|
|
54
|
-
item.icon= ICON_NAME[icon];
|
|
55
|
-
}
|
|
56
|
-
if(children){
|
|
57
|
-
item.children = children.map(childData=>{
|
|
58
|
-
return translateMenu(childData,item)
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
return item;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
window.matchPath=matchPath;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const GET_ROUTE_MENU=(menuList)=>{
|
|
69
|
-
let groupKeys=[];
|
|
70
|
-
for(let key in menuList){
|
|
71
|
-
const menuItem = menuList[key];
|
|
72
|
-
const {path,routeTemplate,subRoute}= menuItem.source;
|
|
73
|
-
if(path){
|
|
74
|
-
let fn = matchPath;
|
|
75
|
-
let match= fn(routeTemplate||path,curRoute.pathname);
|
|
76
|
-
if(!match&&subRoute){
|
|
77
|
-
match= subRoute.some(sub=>{
|
|
78
|
-
let subMatch= fn(sub.routeTemplate||sub.path,curRoute.pathname);
|
|
79
|
-
if(subMatch){
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
if(match){
|
|
86
|
-
groupKeys = menuItem.routepath?menuItem.routepath.split('-'):'';
|
|
87
|
-
}
|
|
31
|
+
|
|
32
|
+
const translateMenu=(list)=>{
|
|
33
|
+
if(!list||list.length<=0)return [];
|
|
34
|
+
let req=list.map(menu=>{
|
|
35
|
+
const {key,name:label,icon,url,msgCount}=menu;
|
|
36
|
+
|
|
37
|
+
let item={
|
|
38
|
+
key,label,icon,url
|
|
88
39
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
})
|
|
99
|
-
setMenus(menuList);
|
|
100
|
-
}else{
|
|
101
|
-
setMenus([]);
|
|
102
|
-
}
|
|
103
|
-
loader.setLoading(false);
|
|
40
|
+
if(msgCount&&msgCount>0){
|
|
41
|
+
item.label=<span>{label}<Badge size='small' count={msgCount} offset={[5,-5]} /></span>
|
|
42
|
+
}
|
|
43
|
+
if(menu.children){
|
|
44
|
+
item.children = translateMenu(menu.children)
|
|
45
|
+
}
|
|
46
|
+
return item;
|
|
47
|
+
})
|
|
48
|
+
return req;
|
|
104
49
|
}
|
|
105
50
|
|
|
106
51
|
useEffect(()=>{
|
|
107
|
-
|
|
108
|
-
|
|
52
|
+
let menuList = translateMenu(providerMenu.leftMenu);
|
|
53
|
+
setMenus(menuList);
|
|
54
|
+
},[providerMenu.leftMenu])
|
|
109
55
|
|
|
110
|
-
useEffect(()=>{
|
|
111
|
-
let groupKeys= GET_ROUTE_MENU(MENU_KEY.current);
|
|
112
|
-
setOpenKeys(groupKeys);
|
|
113
|
-
let selectKey =groupKeys[groupKeys.length-1];
|
|
114
|
-
setSelectKeys([selectKey])
|
|
115
|
-
},[curRoute,menus]);
|
|
116
56
|
|
|
117
57
|
const onClickMenuItem=(e)=>{
|
|
118
58
|
const { item, key, keyPath, domEvent } = e;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
nav(menuData.path);
|
|
122
|
-
}
|
|
59
|
+
let menu = providerMenu.findMenuData(key);
|
|
60
|
+
nav(menu.url);
|
|
123
61
|
}
|
|
124
|
-
|
|
125
|
-
|
|
62
|
+
|
|
63
|
+
const onOpenSubMenu=(keys)=>{
|
|
64
|
+
setSubMenuOpen(keys)
|
|
126
65
|
}
|
|
66
|
+
useEffect(()=>{
|
|
67
|
+
if(providerMenu.selectMenus.keys && providerMenu.selectMenus.keys.length>0){
|
|
68
|
+
setSubMenuOpen([...subMenuOpen,...providerMenu.selectMenus.keys]);
|
|
69
|
+
}
|
|
70
|
+
},[providerMenu.selectMenus.keys])
|
|
127
71
|
return (
|
|
128
72
|
<section className={styles.nav}>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
73
|
+
{
|
|
74
|
+
providerMenu.selectMenus.keys&&
|
|
75
|
+
<Menu
|
|
76
|
+
theme='dark'
|
|
77
|
+
openKeys={subMenuOpen}
|
|
78
|
+
onOpenChange={onOpenSubMenu}
|
|
79
|
+
selectedKeys={providerMenu.selectMenus.keys}
|
|
80
|
+
onClick={onClickMenuItem}
|
|
81
|
+
mode="inline"
|
|
82
|
+
items={loader.loading?[]:menus}
|
|
83
|
+
/>
|
|
84
|
+
}
|
|
138
85
|
</section>
|
|
139
86
|
)
|
|
140
87
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import React, { useState,useEffect, useRef} from 'react';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { useLocation,useNavigate } from 'react-router-dom';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { LogoutOutlined, UserOutlined } from '@ant-design/icons';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { Menu,Dropdown,Badge } from 'antd';
|
|
9
|
+
|
|
10
|
+
import ProviderApp from '@/provider/app';
|
|
11
|
+
import ProviderMenu from '@/provider/menu';
|
|
12
|
+
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
import imgAvatar from '@/assets/images/avatar.png';
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import styles from './index.less';
|
|
17
|
+
|
|
18
|
+
const TopMenu=()=>{
|
|
19
|
+
const app = ProviderApp.useContainer();
|
|
20
|
+
const providerMenu = ProviderMenu.useContainer();
|
|
21
|
+
const navigate = useNavigate();
|
|
22
|
+
|
|
23
|
+
const [menus,setMenus]=useState([]);
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const translateMenu=(list)=>{
|
|
27
|
+
if(!list||list.length<=0)return [];
|
|
28
|
+
let req=list.map(menu=>{
|
|
29
|
+
const {key,name:label,icon,url,msgCount}=menu;
|
|
30
|
+
|
|
31
|
+
let item={
|
|
32
|
+
key,label,icon,url
|
|
33
|
+
}
|
|
34
|
+
if(msgCount&&msgCount>0){
|
|
35
|
+
item.label=<span>{label}<Badge size='small' count={msgCount} offset={[5,-5]} /></span>
|
|
36
|
+
}
|
|
37
|
+
if(menu.children){
|
|
38
|
+
item.children = translateMenu(menu.children)
|
|
39
|
+
}
|
|
40
|
+
return item;
|
|
41
|
+
})
|
|
42
|
+
return req;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const reload= async ()=>{
|
|
46
|
+
providerMenu.reload();
|
|
47
|
+
}
|
|
48
|
+
useEffect(()=>{
|
|
49
|
+
let menuList = translateMenu(providerMenu.topMenu);
|
|
50
|
+
menuList.forEach(menu=>{
|
|
51
|
+
menu.children=null;//顶级菜单这里设计为不需要展示子菜单
|
|
52
|
+
})
|
|
53
|
+
setMenus(menuList);
|
|
54
|
+
},[providerMenu.topMenu]);
|
|
55
|
+
|
|
56
|
+
useEffect(()=>{
|
|
57
|
+
reload();
|
|
58
|
+
},[])
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// 推出登录
|
|
62
|
+
const onAvatarClick = (e)=>{
|
|
63
|
+
if (e?.key === 'logout') {
|
|
64
|
+
app.logout();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const onHome=()=>{
|
|
68
|
+
navigate('/');
|
|
69
|
+
}
|
|
70
|
+
const onClickMenuItem=(e)=>{
|
|
71
|
+
const { item, key, keyPath, domEvent } = e;
|
|
72
|
+
let menu = providerMenu.findMenuData(key);
|
|
73
|
+
navigate(menu.url);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<section className={styles.topMenu}>
|
|
78
|
+
<div className={styles.left}>
|
|
79
|
+
<span className={styles.title} onClick={onHome}>后管系统</span>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<div className={styles.center}>
|
|
83
|
+
{
|
|
84
|
+
menus&&menus.length>1&&
|
|
85
|
+
<Menu
|
|
86
|
+
items={menus}
|
|
87
|
+
mode="horizontal"
|
|
88
|
+
onClick={onClickMenuItem}
|
|
89
|
+
selectedKeys={providerMenu.selectMenus.keys}
|
|
90
|
+
className={styles.menu}
|
|
91
|
+
/>
|
|
92
|
+
}
|
|
93
|
+
</div>
|
|
94
|
+
<div className={styles.right}>
|
|
95
|
+
|
|
96
|
+
<span className={styles.username}>Hi,{app?.user?.username||''}!</span>
|
|
97
|
+
<Dropdown menu={(
|
|
98
|
+
<Menu onClick={onAvatarClick} className={styles.avatarMenu}>
|
|
99
|
+
<Menu.Item key="user">
|
|
100
|
+
<UserOutlined />
|
|
101
|
+
用户名
|
|
102
|
+
</Menu.Item>
|
|
103
|
+
|
|
104
|
+
<Menu.Item key="logout">
|
|
105
|
+
<LogoutOutlined />
|
|
106
|
+
退出登录
|
|
107
|
+
</Menu.Item>
|
|
108
|
+
</Menu>
|
|
109
|
+
)}>
|
|
110
|
+
<img className={styles.avatar} src={imgAvatar}/>
|
|
111
|
+
</Dropdown>
|
|
112
|
+
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
</section>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default TopMenu;
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
import {useDictionary} from 'kn-hooks';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import {Select,Radio} from 'antd';
|
|
6
8
|
|
|
7
9
|
import {GET_USER_TYPE} from '@/services/user';
|
|
8
10
|
import ShowToast from '@/components/toast';
|
|
9
11
|
|
|
12
|
+
|
|
10
13
|
export const SelectOption=(props)=>{
|
|
11
14
|
const {value}=props;
|
|
12
15
|
const name = props['data-keyname'];
|
|
@@ -18,7 +21,7 @@ export const SelectOption=(props)=>{
|
|
|
18
21
|
return <hgroup onClick={onClick} key={value} name={name} value={value}>{props.children}</hgroup>
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
useDictionary.SetConfig({SelectOption})
|
|
24
|
+
useDictionary.SetConfig({SelectOption:Select.Option, RadioOption: Radio })
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
export const useUserType = useDictionary.createDictionary({
|
|
@@ -6,6 +6,8 @@ import usePreload from './usePreload';
|
|
|
6
6
|
import useSearch from './useSearch';
|
|
7
7
|
import useUpdate from './useUpdate';
|
|
8
8
|
import useLoading from './useLoading';
|
|
9
|
+
import useRouteMenu from './useRouteMenu';
|
|
10
|
+
|
|
9
11
|
// @ts-ignore
|
|
10
12
|
import {usePagination,usePaginationWithForm} from 'kn-hooks';
|
|
11
13
|
|
|
@@ -17,5 +19,6 @@ export {
|
|
|
17
19
|
usePreload,
|
|
18
20
|
useSearch,
|
|
19
21
|
useUpdate,
|
|
20
|
-
useLoading
|
|
22
|
+
useLoading,
|
|
23
|
+
useRouteMenu
|
|
21
24
|
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import React,{ useRef, useState} from 'react';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { matchPath } from 'react-router-dom';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 设置菜单属性
|
|
11
|
+
* @typedef MenuConfig
|
|
12
|
+
* @property {string} primaryId - 菜单的primaryId值
|
|
13
|
+
* @property {('msgCount'|'icon'|'name')} key - 需要设置的字段名称
|
|
14
|
+
* @property {any} value - 字段值
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 菜单项
|
|
19
|
+
* @typedef RouteMenuItem
|
|
20
|
+
* @property {string} name - 菜单展示的名称
|
|
21
|
+
* @property {string|JSX.Element} [icon] - 菜单图标
|
|
22
|
+
* @property {string} [url] - 菜单的URL地址
|
|
23
|
+
* @property {string} [routeTemplate] - 菜单的路由模版,用于匹配动态路由
|
|
24
|
+
* @property {number} [msgCount] - 菜单的未读消息数量
|
|
25
|
+
* @property {boolean} [hideMenu=false] - 是否为隐藏的菜单,隐藏的菜单不会展示独立菜单,但是会匹配路由
|
|
26
|
+
* @property {string[]} [auth] - 允许访问该菜单的权限列表
|
|
27
|
+
* @property {RouteMenuItem[]} [children] - 子菜单
|
|
28
|
+
* @property {string} [primaryId] - 菜单的唯一ID,如果存在primaryId,则菜单的key同primaryId
|
|
29
|
+
* @property {string} [key] - 会自动生成的菜单唯一ID,如果菜单配置内存在了primaryId,则会取该id
|
|
30
|
+
* @property {string} [parentKey] - 父级菜单的key,自动生成的
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
// const MenuData=[
|
|
35
|
+
// {
|
|
36
|
+
// name:'用户中心',
|
|
37
|
+
// icon:'AppstoreOutlined',
|
|
38
|
+
// url:'/user',
|
|
39
|
+
// children:[
|
|
40
|
+
// {
|
|
41
|
+
// key:'myAccount',
|
|
42
|
+
// name:'账号管理',
|
|
43
|
+
// url:'/user/accouunt',
|
|
44
|
+
// msgCount:0,
|
|
45
|
+
// },
|
|
46
|
+
// ]
|
|
47
|
+
// },
|
|
48
|
+
// {
|
|
49
|
+
// name:'消息中心',
|
|
50
|
+
// icon:'AppstoreOutlined',
|
|
51
|
+
// url:'/message',
|
|
52
|
+
// children:[
|
|
53
|
+
// {
|
|
54
|
+
// name:'我的消息',
|
|
55
|
+
// url:'/message/my',
|
|
56
|
+
// msgCount:3,
|
|
57
|
+
// children:[
|
|
58
|
+
// {
|
|
59
|
+
// label: '创建消息',
|
|
60
|
+
// url: '/message/edit/create',
|
|
61
|
+
// routeTemplate:'/message/edit/:type',
|
|
62
|
+
// msgCount:0,
|
|
63
|
+
// },
|
|
64
|
+
// {
|
|
65
|
+
// label: '编辑消息',
|
|
66
|
+
// url: '/message/edit/edit',
|
|
67
|
+
// routeTemplate:'/message/edit/:type',
|
|
68
|
+
// msgCount:0,
|
|
69
|
+
// auth:['super'],
|
|
70
|
+
// },
|
|
71
|
+
// {
|
|
72
|
+
// url:'/message/detail',
|
|
73
|
+
// hideMenu:true,//是否是隐藏
|
|
74
|
+
// routeTemplate:'/message/detail/:id',
|
|
75
|
+
// },
|
|
76
|
+
|
|
77
|
+
// ]
|
|
78
|
+
// },
|
|
79
|
+
|
|
80
|
+
// ]
|
|
81
|
+
// }
|
|
82
|
+
// ]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const useRouteMenu=()=>{
|
|
86
|
+
/**
|
|
87
|
+
* @type [RouteMenuItem[], React.Dispatch<React.SetStateAction<RouteMenuItem[]>>]
|
|
88
|
+
*/
|
|
89
|
+
const [source,setSource]= useState([]);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @type React.MutableRefObject<number>
|
|
93
|
+
*/
|
|
94
|
+
const refKey = useRef(1);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @type React.MutableRefObject<Object<string,RouteMenuItem>>
|
|
98
|
+
*/
|
|
99
|
+
const refKeyMap = useRef();
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 遍历菜单,给菜单创建key,并创建map表以便快速查找菜单数据
|
|
103
|
+
* @param {RouteMenuItem[]} data - 菜单列表数据
|
|
104
|
+
* @param {RouteMenuItem} [parent] - 父级菜单数据,如果没有则代表是顶层菜单
|
|
105
|
+
*/
|
|
106
|
+
const setSourceMap=(data,parent=null)=>{
|
|
107
|
+
if(parent==null){
|
|
108
|
+
// 重置
|
|
109
|
+
refKey.current=1;
|
|
110
|
+
refKeyMap.current={};
|
|
111
|
+
}
|
|
112
|
+
data.forEach(menu=>{
|
|
113
|
+
if(menu.primaryId){
|
|
114
|
+
menu.key = menu.primaryId
|
|
115
|
+
}else{
|
|
116
|
+
menu.key=`${refKey.current++}`;
|
|
117
|
+
}
|
|
118
|
+
refKeyMap.current[menu.key] = menu;
|
|
119
|
+
|
|
120
|
+
if(parent){
|
|
121
|
+
menu.parentKey = parent.key;
|
|
122
|
+
}
|
|
123
|
+
if(menu.children && menu.children.length>0){
|
|
124
|
+
setSourceMap(menu.children,menu);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
if(parent==null){
|
|
128
|
+
setSource([...data]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 获取当前菜单数据,用于渲染
|
|
135
|
+
* 会将没权限的菜单、隐藏菜单过滤掉
|
|
136
|
+
* @param {RouteMenuItem[]} menus - 需要被检查的菜单列表
|
|
137
|
+
* @param {string[]} userAuth - 用户当前的权限列表
|
|
138
|
+
* @returns {RouteMenuItem[]}
|
|
139
|
+
*/
|
|
140
|
+
const getMenu=(menus=source, userAuth=[])=>{
|
|
141
|
+
const list = [];
|
|
142
|
+
menus.forEach(menu=>{
|
|
143
|
+
let auth= true;
|
|
144
|
+
// 判断用户有没有权限可以访问这个菜单
|
|
145
|
+
if(menu.auth){
|
|
146
|
+
if(menu.auth.some(menuAuthName=>userAuth.includes(menuAuthName)) == false){
|
|
147
|
+
auth=false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// 隐藏的菜单
|
|
151
|
+
if(menu.hideMenu){
|
|
152
|
+
auth=false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 只有当前菜单有权限的前提下,才可以继续遍历子菜单查询子菜单是否有权限
|
|
156
|
+
if(auth){
|
|
157
|
+
const item= {...menu};
|
|
158
|
+
if(item.children&&item.children.length>0){
|
|
159
|
+
const chidList= getMenu(item.children, userAuth);
|
|
160
|
+
item.children = chidList.length>0?chidList:null;
|
|
161
|
+
}
|
|
162
|
+
list.push(item)
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
if(menus == source){
|
|
166
|
+
console.warn('[useRouteMenu]getMenu:',list)
|
|
167
|
+
}
|
|
168
|
+
return list
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 计算pathname路由路径下的菜单路径
|
|
173
|
+
* @param {string} pathname - 需要匹配的路由路径
|
|
174
|
+
* @returns {RouteMenuItem[]}
|
|
175
|
+
*/
|
|
176
|
+
const getOpenMenus=(pathname='/')=>{
|
|
177
|
+
/** @type RouteMenuItem */
|
|
178
|
+
let matchMenu;
|
|
179
|
+
for(const menuKeyName in refKeyMap.current){
|
|
180
|
+
const menu= refKeyMap.current[menuKeyName];
|
|
181
|
+
if( matchPath(menu.routeTemplate||menu.url, pathname) ){
|
|
182
|
+
matchMenu = menu;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const getParentMenus = (menu,menus=[])=>{
|
|
188
|
+
menus.push(menu);
|
|
189
|
+
if(menu.parentKey){
|
|
190
|
+
return getParentMenus( refKeyMap.current[menu.parentKey],menus );
|
|
191
|
+
}
|
|
192
|
+
return menus;
|
|
193
|
+
}
|
|
194
|
+
if(matchMenu){
|
|
195
|
+
const menus= getParentMenus(matchMenu);
|
|
196
|
+
console.warn(`[useRouteMenu]openMenus:`,menus)
|
|
197
|
+
return menus;
|
|
198
|
+
}
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 根据menu的key来查找menu数据
|
|
204
|
+
* @param {string} menuKey - 菜单的key
|
|
205
|
+
* @returns {RouteMenuItem}
|
|
206
|
+
*/
|
|
207
|
+
const findMenuData= (menuKey)=>{
|
|
208
|
+
return refKeyMap.current[menuKey]
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 设置菜单的属性
|
|
213
|
+
* @param {MenuConfig[]} params
|
|
214
|
+
*/
|
|
215
|
+
const setMenuConfig=(params)=>{
|
|
216
|
+
|
|
217
|
+
params.forEach(param=>{
|
|
218
|
+
const {primaryId,key,value}= param;
|
|
219
|
+
const menu = refKeyMap.current[primaryId];
|
|
220
|
+
if(menu){
|
|
221
|
+
// @ts-ignore
|
|
222
|
+
menu[`${key}`] = value;
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
setSource([...source])
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return {setSourceMap,getOpenMenus,getMenu,source,findMenuData,setMenuConfig}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export default useRouteMenu;
|
|
232
|
+
|