fix eslint && refine code
This commit is contained in:
parent
1072572ac6
commit
7549eb8044
|
@ -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, ','));
|
||||
}
|
||||
|
|
|
@ -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,39 +17,35 @@ 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) {
|
||||
route.children = filterAsyncRouter(route.children, roles)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return accessedRouters
|
||||
const accessedRouters = asyncRouterMap.filter(route => {
|
||||
if (hasPermission(roles, route)) {
|
||||
if (route.children && route.children.length) {
|
||||
route.children = filterAsyncRouter(route.children, roles)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue