refactor: 优化代码
This commit is contained in:
parent
b0f720bb1e
commit
ac3093641f
|
@ -1,6 +1,6 @@
|
||||||
import router from './components/common/router/router'
|
import router from './components/common/router/router'
|
||||||
import {TokenKey} from '../common/js/constants';
|
import {TokenKey} from '@/common/js/constants';
|
||||||
import {hasRolePermissions, hasRoles} from "../common/js/utils";
|
import {hasRolePermissions, hasRoles} from "@/common/js/utils";
|
||||||
|
|
||||||
const whiteList = ['/login']; // no redirect whitelist
|
const whiteList = ['/login']; // no redirect whitelist
|
||||||
|
|
||||||
|
@ -17,22 +17,18 @@ export const roles = {
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkRolePermission(el, binding, type) {
|
function checkRolePermission(el, binding, type) {
|
||||||
const { value } = binding;
|
const {value} = binding;
|
||||||
const rolesString = localStorage.getItem("roles");
|
|
||||||
const roles = rolesString.split(',');
|
|
||||||
if (value && value instanceof Array && value.length > 0) {
|
if (value && value instanceof Array && value.length > 0) {
|
||||||
const permissionRoles = value;
|
const permissionRoles = value;
|
||||||
let hasPermission = false;
|
let hasPermission = false;
|
||||||
if (type === 'roles') {
|
if (type === 'roles') {
|
||||||
hasPermission = hasRoles(...permissionRoles);
|
hasPermission = hasRoles(...permissionRoles);
|
||||||
} else if (type === 'permission') {
|
} else if (type === 'permission') {
|
||||||
hasPermission = hasRolePermissions(...permissionRoles);
|
hasPermission = hasRolePermissions(...permissionRoles);
|
||||||
}
|
}
|
||||||
if (!hasPermission) {
|
if (!hasPermission) {
|
||||||
el.parentNode && el.parentNode.removeChild(el)
|
el.parentNode && el.parentNode.removeChild(el)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// throw new Error(`need roles! Like v-permission="['admin','editor']"`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue