Skip to content

Commit bc9b5fe

Browse files
committed
fix(view): roles
1 parent 3a727d5 commit bc9b5fe

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

admin/src/permission.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@ router.beforeEach((to, from, next) => {
2525
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
2626
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
2727
})
28-
if (!to.meta.role || res.data.roles.indexOf('Super Administrator') >= 0 || res.data.roles.indexOf(to.meta.role) >= 0) {
28+
if (!to.meta.role || whiteList.indexOf(to.path) !== -1 || hasPermission(res.data.roles, to.meta.roles)) {
2929
next()
3030
} else {
31-
if (whiteList.indexOf(to.path) !== -1) {
32-
next()
33-
} else {
34-
next({ path: '/404' })
35-
NProgress.done()
36-
}
31+
next({ path: '/404' })
32+
NProgress.done()
3733
}
3834
}).catch((err) => {
3935
store.dispatch('FedLogOut').then(() => {
@@ -42,15 +38,12 @@ router.beforeEach((to, from, next) => {
4238
})
4339
})
4440
} else {
45-
if (!to.meta.role || store.getters.roles.indexOf('Super Administrator') >= 0 || store.getters.roles.indexOf(to.meta.role) >= 0) {
41+
// 动态改变权限
42+
if (!to.meta.role || whiteList.indexOf(to.path) !== -1 || hasPermission(store.getters.roles, to.meta.roles)) {
4643
next()
4744
} else {
48-
if (whiteList.indexOf(to.path) !== -1) {
49-
next()
50-
} else {
51-
next({ path: '/404' })
52-
NProgress.done()
53-
}
45+
next({ path: '/404' })
46+
NProgress.done()
5447
}
5548
}
5649
}
@@ -67,3 +60,10 @@ router.beforeEach((to, from, next) => {
6760
router.afterEach(() => {
6861
NProgress.done() // 结束Progress
6962
})
63+
64+
// permissiom judge function
65+
function hasPermission(roles, permissionRoles) {
66+
if (roles.indexOf('Super Administrator') >= 0) return true // admin permission passed directly
67+
if (!permissionRoles) return true
68+
return roles.some(role => permissionRoles.indexOf(role) >= 0)
69+
}

admin/src/router/router.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ export const routeManage = [
2323
component: Layout,
2424
redirect: '/api_excel/index',
2525
name: 'Excel-List',
26-
meta: { title: '批量测试管理', icon: 'ico-table', role: Admin },
26+
meta: { title: '批量测试管理', icon: 'ico-table', roles: [Super, Admin] },
2727
children: [
2828
{ path: '/api_excel/edit/:id', name: 'EditExcel', component: () => import('@/views/api_excel/edit'), hidden: true },
2929
{
3030
path: '/api_excel/add',
3131
name: 'AddExcel',
3232
component: () => import('@/views/api_excel/add'),
33-
meta: { title: '上传测试', icon: 'excel', role: Admin }
33+
meta: { title: '上传测试', icon: 'excel', roles: [Super, Admin] }
3434
},
3535
{
3636
path: '/api_excel/index',
3737
name: 'Excel',
3838
component: () => import('@/views/api_excel/index'),
39-
meta: { title: '测试管理', icon: 'ico-aliyun', role: Admin }
39+
meta: { title: '测试管理', icon: 'ico-aliyun', roles: [Super, Admin] }
4040
},
4141
{ path: '/api_param/add', name: 'AddApiParam', component: () => import('@/views/api_param/add'), hidden: true },
4242
{ path: '/api_param/edit/:id', name: 'EditApiParam', component: () => import('@/views/api_param/edit'), hidden: true },
4343
{
4444
path: '/api_param/index',
4545
name: 'ApiParam',
4646
component: () => import('@/views/api_param/index'),
47-
meta: { title: '接口列表', icon: 'api', role: Admin }
47+
meta: { title: '接口列表', icon: 'api', roles: [Super, Admin] }
4848
}
4949
]
5050
}
@@ -58,31 +58,31 @@ export const routerAdmin = [
5858
component: Layout,
5959
redirect: '/category/index',
6060
name: 'Category-Nav',
61-
meta: { title: '栏目菜单', icon: 'category', role: Super },
61+
meta: { title: '栏目菜单', icon: 'category', roles: [Super] },
6262
children: [
6363
{ path: '/category/add', name: 'AddCategory', component: () => import('@/views/category/add'), meta: { title: '添加栏目' }, hidden: true },
6464
{ path: '/category/edit/:id', name: 'EditCategory', component: () => import('@/views/category/edit'), hidden: true },
6565
{
6666
path: '/category/index',
6767
name: 'Category',
6868
component: () => import('@/views/category/index'),
69-
meta: { title: '栏目管理', icon: 'ico-category', role: Super }
69+
meta: { title: '栏目管理', icon: 'ico-category', roles: [Super] }
7070
},
7171
{ path: '/nav/add', name: 'AddNav', component: () => import('@/views/nav/add'), hidden: true },
7272
{ path: '/nav/edit/:id', name: 'EditNav', component: () => import('@/views/nav/edit'), hidden: true },
7373
{
7474
path: '/nav',
7575
name: 'Nav',
7676
component: () => import('@/views/nav'),
77-
meta: { title: '导航管理', icon: 'nav', role: Super }
77+
meta: { title: '导航管理', icon: 'nav', roles: [Super] }
7878
},
7979
{ path: '/tag/add', name: 'AddTag', component: () => import('@/views/tag/add'), meta: { title: '添加标签' }, hidden: true },
8080
{ path: '/tag/edit/:id', name: 'EditTag', component: () => import('@/views/tag/edit'), hidden: true },
8181
{
8282
path: '/tag',
8383
name: 'Tag',
8484
component: () => import('@/views/tag/index'),
85-
meta: { title: '标签列表', icon: 'tag', role: Super }
85+
meta: { title: '标签列表', icon: 'tag', roles: [Super] }
8686
}
8787
]
8888
},
@@ -92,20 +92,20 @@ export const routerAdmin = [
9292
component: Layout,
9393
// redirect: '/article',
9494
name: 'Article-List',
95-
meta: { title: '文章管理', icon: 'article', role: Super },
95+
meta: { title: '文章管理', icon: 'article', roles: [Super] },
9696
children: [
9797
{ path: '/article/edit/:id', name: 'EditArticle', component: () => import('@/views/article/edit'), hidden: true },
9898
{
9999
path: '/article/index',
100100
name: 'Article',
101101
component: () => import('@/views/article/index'),
102-
meta: { title: '文章管理', icon: 'ico-article', role: Super }
102+
meta: { title: '文章管理', icon: 'ico-article', roles: [Super] }
103103
},
104104
{
105105
path: '/article/add',
106106
name: 'AddArticle',
107107
component: () => import('@/views/article/add'),
108-
meta: { title: '添加文章', icon: 'add', role: Super }
108+
meta: { title: '添加文章', icon: 'add', roles: [Super] }
109109
}
110110
]
111111
},
@@ -115,7 +115,7 @@ export const routerAdmin = [
115115
component: Layout,
116116
redirect: '/task',
117117
name: '公交',
118-
meta: { title: '公交管理', icon: 'bus', role: Super },
118+
meta: { title: '公交管理', icon: 'bus', roles: [Super] },
119119
children: [
120120
{ path: '/task/search', name: 'search', component: () => import('@/views/task/search'), hidden: true },
121121
{ path: '/task/newBus', name: 'NewBus', component: () => import('@/views/task/newBus'), hidden: true },
@@ -124,27 +124,27 @@ export const routerAdmin = [
124124
path: '/task',
125125
name: '定时任务',
126126
component: () => import('@/views/task/index'),
127-
meta: { title: '定时任务', icon: 'task', role: Super }
127+
meta: { title: '定时任务', icon: 'task', roles: [Super] }
128128
},
129129
{ path: 'lines/add', name: 'linesAdd', component: () => import('@/views/lines/add'), hidden: true },
130130
{ path: 'lines/edit/:id', name: 'linesEdit', component: () => import('@/views/lines/edit'), hidden: true },
131131
{
132132
path: 'lines',
133133
name: '公交列表',
134134
component: () => import('@/views/lines/index'),
135-
meta: { title: '公交列表', icon: 'table', role: Super }
135+
meta: { title: '公交列表', icon: 'table', roles: [Super] }
136136
},
137137
{
138138
path: 'config',
139139
name: '配置管理',
140140
component: () => import('@/views/lines/index'),
141-
meta: { title: '配置列表', icon: 'table', role: Super }
141+
meta: { title: '配置列表', icon: 'table', roles: [Super] }
142142
},
143143
{
144144
path: 'tree',
145145
name: 'Tree',
146146
component: () => import('@/views/tree/index'),
147-
meta: { title: 'Tree', icon: 'tree', role: Super },
147+
meta: { title: 'Tree', icon: 'tree', roles: [Super] },
148148
hidden: true
149149
}
150150
]
@@ -155,7 +155,7 @@ export const routerAdmin = [
155155
component: Layout,
156156
redirect: '/user',
157157
name: '权限',
158-
meta: { title: '权限管理', icon: 'auth', role: Super },
158+
meta: { title: '权限管理', icon: 'auth', roles: [Super] },
159159
children: [
160160
{ path: 'index', name: 'userIndex', component: () => import('@/views/user/index'), hidden: true },
161161
{ path: 'password', name: 'userPassword', component: () => import('@/views/user/password'), hidden: true },
@@ -165,24 +165,24 @@ export const routerAdmin = [
165165
path: '/user',
166166
name: '用户管理',
167167
component: () => import('@/views/user/index'),
168-
meta: { title: '用户列表', icon: 'user', role: Super }
168+
meta: { title: '用户列表', icon: 'user', roles: [Super] }
169169
},
170170
{ path: '/permission/add', name: 'AddPermission', component: () => import('@/views/permission/add'), hidden: true },
171171
{ path: '/permission/edit/:id', name: 'EditPermission', component: () => import('@/views/permission/edit'), hidden: true },
172172
{
173173
path: '/permission',
174174
name: '权限列表',
175175
component: () => import('@/views/permission/index'),
176-
meta: { title: '权限列表', icon: 'permission', role: Super }
176+
meta: { title: '权限列表', icon: 'permission', roles: [Super] }
177177
},
178178

179-
{ path: '/role/add', name: 'AddRole', component: () => import('@/views/role/add'), hidden: true },
180-
{ path: '/role/edit/:id', name: 'EditRole', component: () => import('@/views/role/edit'), hidden: true },
179+
{ path: '/role/add', name: 'Addroles', component: () => import('@/views/role/add'), hidden: true },
180+
{ path: '/role/edit/:id', name: 'Editroles', component: () => import('@/views/role/edit'), hidden: true },
181181
{
182182
path: '/role',
183183
name: '角色管理',
184184
component: () => import('@/views/role/index'),
185-
meta: { title: '角色管理', icon: 'role', role: Super }
185+
meta: { title: '角色管理', icon: 'roles', roles: [Super] }
186186
}
187187
]
188188
}

0 commit comments

Comments
 (0)