金久信后台管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

33 lines
835 B

function $hasRole(...args) {
const userRoles = this.$store.state.$user.userInfo.role || [];
return args.some(arg => {
if (Array.isArray(arg)) {
return arg.every(role => userRoles.includes(role));
} else {
return userRoles.includes(arg);
}
});
}
function $hasPermission(...args) {
const userPermission = this.$store.state.$user.permission || []
return args.some(arg => {
if (Array.isArray(arg)) {
return arg.every(permission => userPermission.includes(permission));
} else {
return userPermission.includes(arg);
}
});
}
export default function(Vue) {
// #ifndef VUE3
Vue.prototype.$hasRole = $hasRole;
Vue.prototype.$hasPermission = $hasPermission;
// #endif
// #ifdef VUE3
Vue.config.globalProperties.$hasRole = $hasRole;
Vue.config.globalProperties.$hasPermission = $hasPermission;
// #endif
}