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) { export function toThousandslsFilter(num) {
return (+num || 0).toString() return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','));
.replace(/^\-?\d+/g, function (m) {
return m.replace(/(?=(?!\b)(\d{3})+$)/g, ',');
});
} }

View File

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