routes.js
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import Login from './views/Login.vue'
import NotFound from './views/404.vue'
import Home from './views/Home.vue'
import Main from './views/Main.vue'
// import Table from './views/nav1/Table.vue'
import Role from './views/nav1/role.vue'
import Perm from './views/nav1/perm.vue'
// import Form from './views/nav1/Form.vue'
import User from './views/nav1/user.vue'
import Page4 from './views/nav2/Page4.vue'
import Page5 from './views/nav2/Page5.vue'
import Page6 from './views/nav3/Page6.vue'
import echarts from './views/charts/echarts.vue'
let routes = [
{
path: '/login',
component: Login,
name: '登录',
hidden: true
},
{
path: '/404',
component: NotFound,
name: '错误',
hidden: true
},
{
path: '/',
component: Home,
name: '主页',
leaf: true,
iconCls: 'el-icon-menu',
children: [
{ path: '/main', component: Main, name: '首页'},
]
},
// { path: '/test', component: Main },
{
path: '/admin',
component: Home,
name: '用户管理',
iconCls: 'el-icon-setting',//图标样式class
children: [
{ path: '/user', component: User, name: '用户管理' },
{ path: '/role', component: Role, name: '角色管理' },
{ path: '/perm', component: Perm, name: '权限管理' },
]
},
{
path: '/',
component: Home,
name: '导航二',
iconCls: 'fa fa-id-card-o',
children: [
{ path: '/page4', component: Page4, name: '页面4' },
{ path: '/page5', component: Page5, name: '页面5' }
]
},
{
path: '/',
component: Home,
name: '导航三',
iconCls: 'fa fa-address-card',
leaf: true,//只有一个节点
children: [
{ path: '/page6', component: Page6, name: '导航三' }
]
},
{
path: '/',
component: Home,
name: 'Charts',
iconCls: 'fa fa-bar-chart',
children: [
{ path: '/echarts', component: echarts, name: 'echarts' }
]
},
{
path: '*',
hidden: true,
redirect: { path: '/404' }
}
];
let initRouters = routes.concat();
let setUserMenus = function (list) {
routes = list;
}
/**
* 处理登陆后的账号对应的菜单
* @param menuList
*/
let handleMenuList = function (router,menu) {
var _self = this;
var routerName = "";
router.forEach(function (v_router) {
routerName = v_router.name;
menu.forEach(function (v_menu) {
//查找返回的目录列表是否包含路由名称,有就返回匹配到的元素,没有就移除
let result = menu.find(item => {
return item.name === routerName;
});
//匹配到继续判断是否子元素,有子元素继续递归
if (result) {
if(v_router.children) {
_self.handleMenuList(v_router.children,result.children);
}
//没有则可以移除
}else {
router.splice(router.findIndex(itm => itm.name === routerName ),1);
}
})
});
}
export default {
routes,setUserMenus,handleMenuList,initRouters
};