index.ts 562 B

123456789101112131415161718
  1. import { usePermissionStoreHook } from "/@/store/modules/permission";
  2. import { Directive } from "vue";
  3. import type { DirectiveBinding } from "vue";
  4. export const auth: Directive = {
  5. mounted(el: HTMLElement, binding: DirectiveBinding) {
  6. const { value } = binding;
  7. if (value) {
  8. const authRoles = value;
  9. const hasAuth = usePermissionStoreHook().buttonAuth.includes(authRoles);
  10. if (!hasAuth) {
  11. el.parentNode.removeChild(el);
  12. }
  13. } else {
  14. throw new Error("need roles! Like v-auth=\"['admin','test']\"");
  15. }
  16. }
  17. };