import {Directive} from "@vue/runtime-core";
|
import {useUserStore} from "@/store/modules/user";
|
|
|
/**
|
* v-hasPermi 操作权限处理
|
*/
|
export const hasPermi: Directive = {
|
mounted(el, binding, vNode) {
|
const {value} = binding;
|
const all_permission = "*:*:*";
|
const userStore = useUserStore();
|
const permissions = userStore.permissions
|
if (value && value instanceof Array && value.length > 0) {
|
const permissionFlag = value;
|
const hasPermissions = permissions.some((permission: any) => {
|
return all_permission === permission || permissionFlag.includes(permission)
|
})
|
if (!hasPermissions) {
|
el.parentNode?.removeChild(el)
|
}
|
} else {
|
throw new Error("请设置操作权限标签值")
|
}
|
}
|
}
|