export const hasPermission = {
install(Vue) {
Vue.directive('hasPermission', {
bind(el, binding, node) {
var flag = false;//默认不显示
let userInfo = node.context.$store.state.userInfoVO;
//获取使用组件的value中
var value = binding.value;
//若是超级管理员
let len = userInfo.permissions.length;
for (let index = 0; index < len; index++) {
if (userInfo.permissions[index].permissionName === 'super_admin') {
flag = true;
break;
}
}
for (let index = 0; index < userInfo.permissions.length; index++) {
if (userInfo.permissions[index].permissionName == value) {
//若有该权限的按钮则显示
flag = true;
}
}
if (!flag) {
el.setAttribute("disabled", true);
el.classList.add("is-disabled");
}
}
})
}
}