|
|
|
@ -16,7 +16,7 @@ const createRouter = () => new Router({ |
|
|
|
|
routes |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(routes); |
|
|
|
|
export function resetRouter() { |
|
|
|
|
const newRouter = createRouter(); |
|
|
|
|
router.matcher = newRouter.matcher; |
|
|
|
@ -57,7 +57,7 @@ function getPermission() { |
|
|
|
|
// 取得路由的值,使用addRouter添加进路由里
|
|
|
|
|
// 该项目的路由实际上做了两层处理,一层指向了默认的路由,对应模块,用于基础布局的nav,下面一层才是实际上的路由跳转,
|
|
|
|
|
// 所以需要默认进行赋值,实际操作时根据path去禁用掉对应的nav即可。
|
|
|
|
|
const arr = ["achievement", "assessment", "course", "evaluation", "information", "match", "project", "setting", "student", "system"]; |
|
|
|
|
const arr = ["student", "evaluation", "assessment", "achievement", "course", "information", "match", "project", "system"]; |
|
|
|
|
let permissionRouters = []; // 最后处理好的路由数组
|
|
|
|
|
|
|
|
|
|
let data = res.permissionMenu[0].children; |
|
|
|
@ -66,6 +66,8 @@ function getPermission() { |
|
|
|
|
// 第一级路由,需要根据匹配到的path,塞进对应的路由children里
|
|
|
|
|
let str = e.path.split("/")[1]; |
|
|
|
|
let index = arr.indexOf(str); |
|
|
|
|
console.log(index); |
|
|
|
|
if (index !== -1) { |
|
|
|
|
let obj = { |
|
|
|
|
path: e.path, |
|
|
|
|
name: arr[index] + "-list", |
|
|
|
@ -79,7 +81,9 @@ function getPermission() { |
|
|
|
|
if (e.children && e.children.length > 0) { |
|
|
|
|
e.children.forEach(i => { |
|
|
|
|
// 避免重复生成路由
|
|
|
|
|
if (i.path && !permissionRouters[index].children.some(e => i.path === e.path)) { |
|
|
|
|
console.log(i.path); |
|
|
|
|
console.log(permissionRouters[index]); |
|
|
|
|
if (i.path && permissionRouters[index] && !permissionRouters[index].children.some(e => i.path === e.path)) { |
|
|
|
|
// console.log(i.path,'当前二级路由的路径')
|
|
|
|
|
let obj = { |
|
|
|
|
path: i.path, |
|
|
|
@ -106,7 +110,7 @@ function getPermission() { |
|
|
|
|
let nowIndex = permissionRouters.findIndex(e => { |
|
|
|
|
return e.path === `/${str}`; |
|
|
|
|
}); |
|
|
|
|
if (nowIndex != -1 && !permissionRouters[nowIndex].children.some(e => e.path === obj.path)) { |
|
|
|
|
if (nowIndex != -1 && permissionRouters[nowIndex] && !permissionRouters[nowIndex].children.some(e => e.path === obj.path)) { |
|
|
|
|
permissionRouters[nowIndex].children.push(obj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -118,7 +122,7 @@ function getPermission() { |
|
|
|
|
|
|
|
|
|
if (i.children && i.children.length) { |
|
|
|
|
i.children.forEach(j => { |
|
|
|
|
if (j.path && !permissionRouters[index].children.some(e => j.path === e.path)) { |
|
|
|
|
if (j.path && permissionRouters[index] && !permissionRouters[index].children.some(e => j.path === e.path)) { |
|
|
|
|
// console.log(j.path,'当前三级路由的路径')
|
|
|
|
|
let obj = { |
|
|
|
|
path: j.path, |
|
|
|
@ -145,7 +149,7 @@ function getPermission() { |
|
|
|
|
let nowIndex = permissionRouters.findIndex(e => { |
|
|
|
|
return e.path === `/${str}`; |
|
|
|
|
}); |
|
|
|
|
if (nowIndex != -1 && !permissionRouters[nowIndex].children.some(e => e.path === obj.path)) { |
|
|
|
|
if (nowIndex != -1 && permissionRouters[nowIndex] && !permissionRouters[nowIndex].children.some(e => e.path === obj.path)) { |
|
|
|
|
permissionRouters[nowIndex].children.push(obj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -185,12 +189,18 @@ function getPermission() { |
|
|
|
|
permissionRouters[nowIndex].children.push(obj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// console.log(permissionRouters, "处理好的");
|
|
|
|
|
// 把处理完成的路由,add到router里
|
|
|
|
|
// 记录一下路由的名称,用于nav
|
|
|
|
|
let nav = data.map(e => e.path); |
|
|
|
|
router.app.$options.store.commit("routers", nav); |
|
|
|
|
let redirect = [{ |
|
|
|
|
path: "/index", |
|
|
|
|
redirect: permissionRouters[0].path |
|
|
|
|
}]; |
|
|
|
|
router.addRoutes(redirect); |
|
|
|
|
router.addRoutes(permissionRouters); |
|
|
|
|
router.addRoutes(errorPage); |
|
|
|
|
} |
|
|
|
|