fix eslint && refine code

This commit is contained in:
Pan 2017-06-23 15:39:13 +08:00
parent 1072572ac6
commit 7549eb8044
2 changed files with 17 additions and 20 deletions

View File

@ -104,8 +104,5 @@ export function html2Text(val) {
export function toThousandslsFilter(num) {
return (+num || 0).toString()
.replace(/^\-?\d+/g, function (m) {
return m.replace(/(?=(?!\b)(\d{3})+$)/g, ',');
});
return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','));
}

View File

@ -1,5 +1,10 @@
import { asyncRouterMap, constantRouterMap } from 'src/router';
/**
* 通过meta.role判断是否与当前用户权限匹配
* @param roles
* @param route
*/
function hasPermission(roles, route) {
if (route.meta && route.meta.role) {
return roles.some(role => route.meta.role.indexOf(role) >= 0)
@ -12,12 +17,11 @@ function hasPermission(roles, route) {
* 递归过滤异步路由表返回符合用户角色权限的路由表
* @param asyncRouterMap
* @param roles
* @returns {Array.<T>|*}
*/
function filterAsyncRouter(asyncRouterMap, roles) {
let accessedRouters = asyncRouterMap.filter(route => {
if(hasPermission(roles, route)) {
if(route.children && route.children.length) {
const accessedRouters = asyncRouterMap.filter(route => {
if (hasPermission(roles, route)) {
if (route.children && route.children.length) {
route.children = filterAsyncRouter(route.children, roles)
}
return true
@ -27,24 +31,21 @@ function filterAsyncRouter(asyncRouterMap, roles) {
return accessedRouters
}
const permission = {
state: {
routers: constantRouterMap,
addRouters: []
},
mutations: {
SET_ROUTERS: (state, routers) => {
state.addRouters = routers;
state.routers = constantRouterMap.concat(routers);
}
},
actions: {
GenerateRoutes({ commit }, data) {
return new Promise(resolve => {
const { roles } = data;
const { roles } = data
let accessedRouters
if (roles.indexOf('admin') >= 0) {
accessedRouters = asyncRouterMap
@ -58,5 +59,4 @@ const permission = {
}
};
export default permission;