正在显示
6 个修改的文件
包含
32 行增加
和
46 行删除
@@ -28,6 +28,7 @@ module.exports = merge(baseWebpackConfig, { | @@ -28,6 +28,7 @@ module.exports = merge(baseWebpackConfig, { | ||
28 | new HtmlWebpackPlugin({ | 28 | new HtmlWebpackPlugin({ |
29 | filename: 'index.html', | 29 | filename: 'index.html', |
30 | template: 'index.html', | 30 | template: 'index.html', |
31 | + favicon:'static/favicon.ico', | ||
31 | inject: true | 32 | inject: true |
32 | }), | 33 | }), |
33 | new FriendlyErrorsPlugin() | 34 | new FriendlyErrorsPlugin() |
@@ -29,16 +29,16 @@ let routes = [ | @@ -29,16 +29,16 @@ let routes = [ | ||
29 | { | 29 | { |
30 | path: '/', | 30 | path: '/', |
31 | component: Home, | 31 | component: Home, |
32 | - name: '', | 32 | + name: '主页', |
33 | leaf: true, | 33 | leaf: true, |
34 | iconCls: 'el-icon-menu', | 34 | iconCls: 'el-icon-menu', |
35 | children: [ | 35 | children: [ |
36 | - { path: '/main', component: Main, name: '首页', hidden: false }, | 36 | + { path: '/main', component: Main, name: '首页'}, |
37 | ] | 37 | ] |
38 | }, | 38 | }, |
39 | // { path: '/test', component: Main }, | 39 | // { path: '/test', component: Main }, |
40 | { | 40 | { |
41 | - path: '/', | 41 | + path: '/admin', |
42 | component: Home, | 42 | component: Home, |
43 | name: '用户管理', | 43 | name: '用户管理', |
44 | iconCls: 'el-icon-setting',//图标样式class | 44 | iconCls: 'el-icon-setting',//图标样式class |
@@ -62,7 +62,7 @@ let routes = [ | @@ -62,7 +62,7 @@ let routes = [ | ||
62 | { | 62 | { |
63 | path: '/', | 63 | path: '/', |
64 | component: Home, | 64 | component: Home, |
65 | - name: '', | 65 | + name: '导航三', |
66 | iconCls: 'fa fa-address-card', | 66 | iconCls: 'fa fa-address-card', |
67 | leaf: true,//只有一个节点 | 67 | leaf: true,//只有一个节点 |
68 | children: [ | 68 | children: [ |
@@ -144,8 +144,7 @@ | @@ -144,8 +144,7 @@ | ||
144 | var userRouters = sessionStorage.getItem('menu'); | 144 | var userRouters = sessionStorage.getItem('menu'); |
145 | if (userRouters) { | 145 | if (userRouters) { |
146 | userRouters = JSON.parse(userRouters); | 146 | userRouters = JSON.parse(userRouters); |
147 | - let sysMenus = _this.$router.options.routes; | ||
148 | - rt.handleMenuList(sysMenus,userRouters); | 147 | + _this.$router.options.routes = userRouters; |
149 | console.log("home:"); | 148 | console.log("home:"); |
150 | console.log(_this.$router.options.routes); | 149 | console.log(_this.$router.options.routes); |
151 | } | 150 | } |
@@ -67,31 +67,34 @@ | @@ -67,31 +67,34 @@ | ||
67 | this.$refs.ruleForm2.resetFields(); | 67 | this.$refs.ruleForm2.resetFields(); |
68 | }, | 68 | }, |
69 | handleMenuList : function (router,menu) { | 69 | handleMenuList : function (router,menu) { |
70 | - var _self = this; | 70 | + var _this = this; |
71 | var routerName = ""; | 71 | var routerName = ""; |
72 | - router.forEach(function (v_router) { | 72 | + var routerTemp = router.concat(); |
73 | + | ||
74 | + routerTemp.forEach(function (v_router,v_index,v_arr) { | ||
73 | routerName = v_router.name; | 75 | routerName = v_router.name; |
74 | - menu.forEach(function (v_menu) { | ||
75 | - //查找返回的目录列表是否包含路由名称,有就返回匹配到的元素,没有就移除 | ||
76 | - let result = menu.find(item => { | ||
77 | - return item.name === routerName; | ||
78 | - }); | ||
79 | 76 | ||
80 | - //匹配到继续判断是否子元素,有子元素继续递归 | ||
81 | - if (result) { | ||
82 | - if(v_router.children) { | ||
83 | - _self.handleMenuList(v_router.children,result.children); | ||
84 | - } | ||
85 | - //没有则可以移除 | ||
86 | - }else { | ||
87 | - router.splice(router.findIndex(itm => itm.name === routerName ),1); | 77 | + //查找返回的目录列表是否包含路由名称,有就返回匹配到的元素,没有就移除 |
78 | + let result = menu.find(item => { | ||
79 | + return item.name === routerName; | ||
80 | + }); | ||
81 | + | ||
82 | + //匹配到继续判断是否子元素,有子元素继续递归 | ||
83 | + if (result) { | ||
84 | + if (v_router.children && v_router.children.length>0) { | ||
85 | + _this.handleMenuList(v_router.children, result.children); | ||
88 | } | 86 | } |
89 | - }) | 87 | + }else { |
88 | + //没有则可以移除 | ||
89 | + let deletRouter = router.findIndex(itm => itm.name === routerName ); | ||
90 | + router.splice(deletRouter,1); | ||
91 | + } | ||
90 | }); | 92 | }); |
91 | console.log("longined router:"); | 93 | console.log("longined router:"); |
92 | - console.log(_self.$router.options.routes); | ||
93 | - //本地存储用户目录 ,防刷新目录丢失用 | ||
94 | - sessionStorage.setItem('menu', JSON.stringify(_self.$router.options.routes)); | 94 | + console.log(routerName); |
95 | + console.log(_this.$router.options.routes); | ||
96 | +// 本地存储用户目录 ,防刷新目录丢失用 | ||
97 | + sessionStorage.setItem('menu', JSON.stringify(_this.$router.options.routes)); | ||
95 | }, | 98 | }, |
96 | handleSubmit2: function (ev) { | 99 | handleSubmit2: function (ev) { |
97 | var _this = this; | 100 | var _this = this; |
@@ -127,11 +130,11 @@ | @@ -127,11 +130,11 @@ | ||
127 | console.log("sysMenus:"); | 130 | console.log("sysMenus:"); |
128 | console.log(sysMenus); | 131 | console.log(sysMenus); |
129 | 132 | ||
130 | - _this.handleMenuList(sysMenus,_this.userMenus); | 133 | + _this.handleMenuList(_this.$router.options.routes,_this.userMenus); |
131 | 134 | ||
132 | console.log("user:"); | 135 | console.log("user:"); |
133 | console.log(_this.$router.options.routes); | 136 | console.log(_this.$router.options.routes); |
134 | - this.$router.push({path: '/main'}); | 137 | + _this.$router.push({path: '/main'}); |
135 | } | 138 | } |
136 | }).catch(error => { | 139 | }).catch(error => { |
137 | let msg = error.message; | 140 | let msg = error.message; |
@@ -7,24 +7,6 @@ | @@ -7,24 +7,6 @@ | ||
7 | <script> | 7 | <script> |
8 | import rt from '../routes' | 8 | import rt from '../routes' |
9 | export default { | 9 | export default { |
10 | - mounted() { | ||
11 | - var _this = this; | ||
12 | - var user = sessionStorage.getItem('user'); | ||
13 | - if (user) { | ||
14 | - user = JSON.parse(user); | ||
15 | - this.sysUserName = user.username || ''; | ||
16 | - this.sysUserAvatar = user.userface || '/static/images/faceDefault.jpg'; | ||
17 | - } | ||
18 | - //操作路由,判断本地存储的用户栏目列表是否存在,如果存在则加载路由 | ||
19 | - var userRouters = sessionStorage.getItem('menu'); | ||
20 | - if (userRouters) { | ||
21 | - userRouters = JSON.parse(userRouters); | ||
22 | - let sysMenus = _this.$router.options.routes; | ||
23 | - rt.handleMenuList(sysMenus,userRouters); | ||
24 | - console.log("main:"); | ||
25 | - console.log(_this.$router.options.routes); | ||
26 | - } | ||
27 | - } | ||
28 | } | 10 | } |
29 | 11 | ||
30 | </script> | 12 | </script> |
-
请 注册 或 登录 后发表评论