kn-cli 1.0.45 → 1.0.47

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kn-cli",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -66,6 +66,12 @@ module.exports = {
66
66
  ```
67
67
 
68
68
  # 更新日志
69
+ * 1.0.47
70
+ 后管模板工程对菜单路由的隐藏子路由控制方法
71
+
72
+ * 1.0.46
73
+ 模板工程下增加jsconfig.json用于解决配置资源根目录别名后vscode无法快捷定位文件
74
+
69
75
  * 1.0.45
70
76
  后管模板创建不了的问题
71
77
 
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "emitDecoratorMetadata": true,
5
+ "experimentalDecorators": true,
6
+ "paths": {
7
+ "@/*": ["./public/src/*"]
8
+ }
9
+ },
10
+ }
@@ -62,10 +62,19 @@ const LeftMenu=(props)=>{
62
62
  let groupKeys=[];
63
63
  for(let key in menuList){
64
64
  const menuItem = menuList[key];
65
- const {path,routeTemplate}= menuItem.source;
65
+ const {path,routeTemplate,subRoute}= menuItem.source;
66
66
  if(path){
67
67
  let fn = matchPath;
68
68
  let match= fn(routeTemplate||path,curRoute.pathname);
69
+ if(!match&&subRoute){
70
+ match= subRoute.some(sub=>{
71
+ let subMatch= fn(sub.routeTemplate||sub.path,curRoute.pathname);
72
+ if(subMatch){
73
+ return true;
74
+ }
75
+ return false;
76
+ })
77
+ }
69
78
  if(match){
70
79
  groupKeys = menuItem.routepath?menuItem.routepath.split('-'):'';
71
80
  }
@@ -11,7 +11,22 @@ import styles from './index.less';
11
11
  import {GET_MENU} from '@/services/auth';
12
12
 
13
13
 
14
-
14
+ /**
15
+ * 菜单下的隐藏子路由集
16
+ * 当这些隐藏子路由打开的时候,导航栏的选中菜单会显示被匹配的这个子菜单
17
+ */
18
+ const SUB_MENU_CONFIG=[
19
+ {
20
+ path:'/video',//匹配菜单路由是/video的菜单
21
+ // routeTemplate:''匹配某个模板菜单的模板
22
+ subRoute:[
23
+ {
24
+ path:'/video/detail',//将video/detail这个路由匹配给菜单/video
25
+ // routeTemplate:''//也可以将某个路由模板匹配给某个菜单
26
+ }
27
+ ]
28
+ },
29
+ ]
15
30
 
16
31
  /**
17
32
  * 顶部导航栏
@@ -66,17 +81,31 @@ const TopMenu=(props)=>{
66
81
  return item;
67
82
  }
68
83
 
84
+ const getSubConfig=(menu)=>{
85
+ const {url,routeTemplate}= menu;
86
+ for(let i=0;i<SUB_MENU_CONFIG.length;i++){
87
+ let sub= SUB_MENU_CONFIG[i];
88
+ if(routeTemplate&&sub.routeTemplate&&routeTemplate==sub.routeTemplate){
89
+ return sub.subRoute;
90
+ }
91
+ if(url&&sub.path&&url==sub.path){
92
+ return sub.subRoute;
93
+ }
94
+ }
95
+ return null;
96
+ }
69
97
  const transServicesMenuChildren=(menu)=>{
70
98
  let req=[];
71
99
  for(let i=0;i<menu.length;i++){
72
100
  let item= menu[i];
73
- const {url:path,name:label,icon,children:menus}= item;
101
+ const {url:path,name:label,icon,children:menus,routeTemplate}= item;
74
102
  let children;
75
103
  if(menus&&menus.length>0){
76
104
  children= transServicesMenuChildren(menus);
77
105
  }
106
+ let subRoute= getSubConfig(item);
78
107
  req.push({
79
- path,label,icon,children
108
+ path,label,icon,children,routeTemplate,subRoute
80
109
  })
81
110
  }
82
111
  return req;
@@ -111,10 +140,20 @@ const TopMenu=(props)=>{
111
140
  }
112
141
 
113
142
  const GET_ROUTE_MENU=(menu)=>{
114
- const {routeTemplate,path} = menu;
143
+ const {routeTemplate,path,subRoute} = menu;
115
144
  const children = menu.children||menu.menus||null;
116
145
  if(routeTemplate||path){
117
146
  let match= matchPath(routeTemplate||path,curRoute.pathname);
147
+ if(!match&&subRoute){
148
+ match= subRoute.some(sub=>{
149
+ let subMatch= matchPath(sub.routeTemplate||sub.path,curRoute.pathname);
150
+ if(subMatch){
151
+ console.log(`match sub route: ${sub.routeTemplate||sub.path} -> ${curRoute.pathname}` )
152
+ return true;
153
+ }
154
+ return false;
155
+ });
156
+ }
118
157
  if(match){
119
158
  console.log(`match route: ${routeTemplate||path} -> ${curRoute.pathname}` )
120
159
  return true;
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "emitDecoratorMetadata": true,
5
+ "experimentalDecorators": true,
6
+ "paths": {
7
+ "@/*": ["./public/src/*"]
8
+ }
9
+ },
10
+ }