28 lines
727 B
Go
28 lines
727 B
Go
import { useAdminStoreHook } from "@/store/modules/admin";
|
|
import { Directive, DirectiveBinding } from "vue";
|
|
|
|
/**
|
|
* Ролевые права
|
|
*/
|
|
export const hasRole: Directive = {
|
|
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
|
const { value } = binding;
|
|
|
|
if (value) {
|
|
const requiredRoles = value; // Коды ролей, требуемые DOM-привязкой
|
|
const { roles } = useAdminStoreHook();
|
|
const hasRole = roles.some((perm) => {
|
|
return requiredRoles.includes(perm);
|
|
});
|
|
|
|
if (!hasRole) {
|
|
el.parentNode && el.parentNode.removeChild(el);
|
|
}
|
|
} else {
|
|
throw new Error("need roles! Like v-has-role=\"['admin', 'user']\"");
|
|
}
|
|
},
|
|
};
|
|
|
|
|