add promise

This commit is contained in:
Pan 2017-05-17 17:53:37 +08:00
parent faea4d8bf6
commit 523a9b3de3

View file

@ -24,25 +24,28 @@ const permission = {
actions: { actions: {
// s // s
GenerateRoutes({ commit }, data) { GenerateRoutes({ commit }, data) {
const { roles } = data; return new Promise(resolve => {
const accessedRouters = asyncRouterMap.filter(v => { const { roles } = data;
if (roles.indexOf('admin') >= 0) return true; const accessedRouters = asyncRouterMap.filter(v => {
if (hasPermission(roles, v)) { if (roles.indexOf('admin') >= 0) return true;
if (v.children && v.children.length > 0) { if (hasPermission(roles, v)) {
v.children = v.children.filter(child => { if (v.children && v.children.length > 0) {
if (hasPermission(roles, child)) { v.children = v.children.filter(child => {
return child if (hasPermission(roles, child)) {
} return child
return false; }
}); return false;
return v });
} else { return v
return v } else {
return v
}
} }
} return false;
return false; });
}); commit('SET_ROUTERS', accessedRouters);
commit('SET_ROUTERS', accessedRouters); resolve();
})
} }
} }
}; };