|
@@ -45,31 +45,30 @@ const mutations = {
|
|
}
|
|
}
|
|
|
|
|
|
const actions = {
|
|
const actions = {
|
|
- generateRoutes({ commit }, roles) {//authList roles
|
|
|
|
|
|
+ generateRoutes({ commit }, authList) {//authList roles
|
|
return new Promise(resolve => {
|
|
return new Promise(resolve => {
|
|
- let accessedRoutes
|
|
|
|
|
|
+ /* let accessedRoutes
|
|
if (roles.includes('admin')) {
|
|
if (roles.includes('admin')) {
|
|
accessedRoutes = asyncRoutes || []
|
|
accessedRoutes = asyncRoutes || []
|
|
} else {
|
|
} else {
|
|
accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
|
|
accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)
|
|
- }
|
|
|
|
- /* let accessedRoutes=[];
|
|
|
|
- if(authList!=undefined){
|
|
|
|
-
|
|
|
|
- let tempRoutes=asyncRoutes.filter(o=>{
|
|
|
|
- return authList.filter(u=>u.type==o.type).length>0;
|
|
|
|
- });
|
|
|
|
- tempRoutes=tempRoutes.map((res)=>{
|
|
|
|
- if(res.children.length>0){
|
|
|
|
- res.children=res.children.filter(o=>authList.filter(u=>u.code==o.name).length>0);
|
|
|
|
|
|
+ } */
|
|
|
|
+ let accessedRoutes=[];
|
|
|
|
+ if (authList != undefined) {
|
|
|
|
+ let tempRoutes = asyncRoutes.filter(o => {
|
|
|
|
+ return authList.filter(u => u.parent_id == o.type).length > 0;
|
|
|
|
+ });
|
|
|
|
+ tempRoutes = tempRoutes.map((res) => {
|
|
|
|
+ if (res.children && res.children.length > 0) { // 检查 res.children 是否存在
|
|
|
|
+ res.children = res.children.filter(o => authList.filter(u => u.code == o.name).length > 0);
|
|
}
|
|
}
|
|
return res;
|
|
return res;
|
|
});
|
|
});
|
|
|
|
|
|
- console.log("tempRoutes",tempRoutes);
|
|
|
|
- accessedRoutes=tempRoutes;
|
|
|
|
|
|
+ console.log("tempRoutes", tempRoutes);
|
|
|
|
+ accessedRoutes = tempRoutes;
|
|
accessedRoutes.push({ path: '*', redirect: '/404', hidden: true });
|
|
accessedRoutes.push({ path: '*', redirect: '/404', hidden: true });
|
|
- } */
|
|
|
|
|
|
+ }
|
|
commit('SET_ROUTES', accessedRoutes)
|
|
commit('SET_ROUTES', accessedRoutes)
|
|
console.log(accessedRoutes);
|
|
console.log(accessedRoutes);
|
|
resolve(accessedRoutes)
|
|
resolve(accessedRoutes)
|