|
|
|
@ -16,7 +16,6 @@ const createRouter = () => new Router({ |
|
|
|
|
routes |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
console.log(routes); |
|
|
|
|
export function resetRouter() { |
|
|
|
|
const newRouter = createRouter(); |
|
|
|
|
router.matcher = newRouter.matcher; |
|
|
|
@ -57,7 +56,7 @@ function getPermission() { |
|
|
|
|
// 取得路由的值,使用addRouter添加进路由里
|
|
|
|
|
// 该项目的路由实际上做了两层处理,一层指向了默认的路由,对应模块,用于基础布局的nav,下面一层才是实际上的路由跳转,
|
|
|
|
|
// 所以需要默认进行赋值,实际操作时根据path去禁用掉对应的nav即可。
|
|
|
|
|
const arr = ["student", "evaluation", "assessment", "achievement", "course", "information", "match", "project", "system"]; |
|
|
|
|
const arr = ['achievement','assessment','course',"evaluation",'information','match','project','setting','student','system']; |
|
|
|
|
let permissionRouters = []; // 最后处理好的路由数组
|
|
|
|
|
|
|
|
|
|
let data = res.permissionMenu[0].children; |
|
|
|
@ -66,7 +65,6 @@ 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, |
|
|
|
@ -81,8 +79,6 @@ function getPermission() { |
|
|
|
|
if (e.children && e.children.length > 0) { |
|
|
|
|
e.children.forEach(i => { |
|
|
|
|
// 避免重复生成路由
|
|
|
|
|
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 = { |
|
|
|
@ -158,10 +154,50 @@ function getPermission() { |
|
|
|
|
} else { |
|
|
|
|
meta.push(i.name+"-"+j.name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (j.children && j.children.length) { |
|
|
|
|
j.children.forEach(k => { |
|
|
|
|
if (k.path && permissionRouters[index] && !permissionRouters[index].children.some(e => k.path === e.path)) { |
|
|
|
|
// console.log(j.path,'当前四级路由的路径')
|
|
|
|
|
let obj = { |
|
|
|
|
path: k.path, |
|
|
|
|
name: arr[index] + "-" + k.path.split("/").pop(), |
|
|
|
|
component: () => import(`@/pages${k.path}`), |
|
|
|
|
meta: { title: k.name, btn: [] }, |
|
|
|
|
children: [] |
|
|
|
|
}; |
|
|
|
|
// 没找到第一级就生成一个
|
|
|
|
|
if (!permissionRouters.some(e => e.path === `/${str}`)) { |
|
|
|
|
let one = { |
|
|
|
|
path: "/" + arr[index], |
|
|
|
|
name: arr[index], |
|
|
|
|
redirect: { |
|
|
|
|
name: `${arr[index]}-list` |
|
|
|
|
}, |
|
|
|
|
component: BasicLayout, |
|
|
|
|
children: []// 传来的路由实际上传入对应的children中
|
|
|
|
|
}; |
|
|
|
|
one.children.push(obj); |
|
|
|
|
permissionRouters.push(one); |
|
|
|
|
} else { |
|
|
|
|
// 找到第一级,判断没有重复地址直接塞进去
|
|
|
|
|
let nowIndex = permissionRouters.findIndex(e => { |
|
|
|
|
return e.path === `/${str}`; |
|
|
|
|
}); |
|
|
|
|
if (nowIndex != -1 && permissionRouters[nowIndex] && !permissionRouters[nowIndex].children.some(e => e.path === obj.path)) { |
|
|
|
|
permissionRouters[nowIndex].children.push(obj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// permissionRouters.push(obj) // path是页面,要塞入上一级同级里,需要单独push进去生成路由
|
|
|
|
|
meta.push(j.name+"-"+k.name); |
|
|
|
|
} else { |
|
|
|
|
meta.push(j.name+"-"+k.name); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
obj.meta.btn = meta; |
|
|
|
|
obj.children = children; |
|
|
|
|