|
|
@ -27,15 +27,38 @@ let router = createRouter(); |
|
|
|
|
|
|
|
|
|
|
|
export default router; |
|
|
|
export default router; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 错误页面 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
const errorPage = [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
path: "/403", |
|
|
|
|
|
|
|
name: "403", |
|
|
|
|
|
|
|
meta: { |
|
|
|
|
|
|
|
title: "403" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
component: () => import("@/pages/exception/error/403") |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
path: "*", |
|
|
|
|
|
|
|
name: "404", |
|
|
|
|
|
|
|
meta: { |
|
|
|
|
|
|
|
title: "404" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
component: () => import("@/pages/exception/error/404") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
// 处理路由权限的方法
|
|
|
|
function getPermission(){ |
|
|
|
function getPermission(){ |
|
|
|
get(api.getUserRolesPermissionMenu).then(res => { |
|
|
|
get(api.getUserRolesPermissionMenu).then(res => { |
|
|
|
console.log(res,'权限的值') |
|
|
|
console.log(res,'权限的值') |
|
|
|
// 取得路由的值,使用addRouter添加进路由里
|
|
|
|
// 取得路由的值,使用addRouter添加进路由里
|
|
|
|
let permissionRouters = [] |
|
|
|
let permissionRouters = [] // 最后处理好的路由数组
|
|
|
|
let data = res.permissionMenu[0].children
|
|
|
|
let data = res.permissionMenu[0].children
|
|
|
|
if(data.length>0){ |
|
|
|
if(data.length>0){ |
|
|
|
data.forEach(e=>{ |
|
|
|
data.forEach(e=>{ |
|
|
|
// 循环,取得主路由以及路由信息,重复循环,取得
|
|
|
|
// 第一级路由
|
|
|
|
let obj = { |
|
|
|
let obj = { |
|
|
|
path:e.path, |
|
|
|
path:e.path, |
|
|
|
name:e.name, |
|
|
|
name:e.name, |
|
|
@ -43,32 +66,35 @@ function getPermission(){ |
|
|
|
meta:[], |
|
|
|
meta:[], |
|
|
|
children:[] |
|
|
|
children:[] |
|
|
|
} |
|
|
|
} |
|
|
|
// 取得页面内的次级路由以及页面按钮
|
|
|
|
let meta = [] |
|
|
|
|
|
|
|
let children = [] |
|
|
|
|
|
|
|
// 第二级是按钮级数据,一级归属当前页的同级页面,实际上一共就一级路由
|
|
|
|
if(e.children&&e.children.length>0){ |
|
|
|
if(e.children&&e.children.length>0){ |
|
|
|
let meta = [] |
|
|
|
|
|
|
|
let children = [] |
|
|
|
|
|
|
|
e.children.forEach(i=>{ |
|
|
|
e.children.forEach(i=>{ |
|
|
|
// 先判断是否有path,有就是页面,页面需要额外进入children,
|
|
|
|
// 避免重复生成路由
|
|
|
|
if(i.path){ |
|
|
|
if(i.path&&!permissionRouters.some(e=>i.path===e.path)){ |
|
|
|
let obj = { |
|
|
|
let obj = { |
|
|
|
path:i.path, |
|
|
|
path:i.path, |
|
|
|
name:i.name, |
|
|
|
name:i.name, |
|
|
|
component:`../pages${i.path}`, |
|
|
|
component:`../pages${i.path}`, |
|
|
|
meta:[], |
|
|
|
meta:[], |
|
|
|
|
|
|
|
children:[] |
|
|
|
}
|
|
|
|
}
|
|
|
|
// 额外处理该页面的按钮,只有两级,懒得递归
|
|
|
|
permissionRouters.push(obj) // path是页面,要塞入上一级同级里,需要单独push进去生成路由
|
|
|
|
if(i.children&&i.children.length>0){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
children.push(obj) |
|
|
|
|
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
|
|
|
|
// 其他的是归属于当前页的按钮级信息,以此为依据来做按钮权限即可
|
|
|
|
meta.push(i.name) |
|
|
|
meta.push(i.name) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
// 其他的是按钮
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
obj.meta = meta |
|
|
|
|
|
|
|
obj.children = children |
|
|
|
|
|
|
|
// 处理好的路由
|
|
|
|
|
|
|
|
permissionRouters.push(obj) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
// 把处理完成的路由,add到router里
|
|
|
|
|
|
|
|
// router.addRoutes(permissionRouters)
|
|
|
|
|
|
|
|
router.addRoutes(errorPage) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
@ -81,7 +107,6 @@ router.beforeEach(function(to,from,next){ |
|
|
|
if(util.local.get(Setting.tokenKey)){ |
|
|
|
if(util.local.get(Setting.tokenKey)){ |
|
|
|
if(!sessionStorage.getItem('handelPermission')){ |
|
|
|
if(!sessionStorage.getItem('handelPermission')){ |
|
|
|
getPermission() |
|
|
|
getPermission() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
if (to.path !== '/login') { |
|
|
|
if (to.path !== '/login') { |
|
|
|