Skip to content

Commit

Permalink
add promise
Browse files Browse the repository at this point in the history
  • Loading branch information
PanJiaChen committed May 17, 2017
1 parent faea4d8 commit 523a9b3
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/store/modules/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,28 @@ const permission = {
actions: {
// s
GenerateRoutes({ commit }, data) {
const { roles } = data;
const accessedRouters = asyncRouterMap.filter(v => {
if (roles.indexOf('admin') >= 0) return true;
if (hasPermission(roles, v)) {
if (v.children && v.children.length > 0) {
v.children = v.children.filter(child => {
if (hasPermission(roles, child)) {
return child
}
return false;
});
return v
} else {
return v
return new Promise(resolve => {
const { roles } = data;
const accessedRouters = asyncRouterMap.filter(v => {
if (roles.indexOf('admin') >= 0) return true;
if (hasPermission(roles, v)) {
if (v.children && v.children.length > 0) {
v.children = v.children.filter(child => {
if (hasPermission(roles, child)) {
return child
}
return false;
});
return v
} else {
return v
}
}
}
return false;
});
commit('SET_ROUTERS', accessedRouters);
return false;
});
commit('SET_ROUTERS', accessedRouters);
resolve();
})
}
}
};
Expand Down

0 comments on commit 523a9b3

Please sign in to comment.