permission.ts 985 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Global authority directive
  3. * Used for fine-grained control of component permissions
  4. * @Example v-auth="RoleEnum.TEST"
  5. */
  6. import type { App, Directive, DirectiveBinding } from 'vue';
  7. import { usePermission } from '/@/hooks/web/usePermission';
  8. function isAuth(el: Element, binding: any) {
  9. // update-begin--author:liaozhiyang---date:20240529---for【TV360X-460】basicForm支持v-auth指令(权限控制显隐)
  10. const value = binding.value;
  11. if (!value) return;
  12. // update-end--author:liaozhiyang---date:20240529---for【TV360X-460】basicForm支持v-auth指令(权限控制显隐)
  13. const { hasPermission } = usePermission();
  14. if (!hasPermission(value)) {
  15. el.parentNode?.removeChild(el);
  16. }
  17. }
  18. const mounted = (el: Element, binding: DirectiveBinding<any>) => {
  19. isAuth(el, binding);
  20. };
  21. const authDirective: Directive = {
  22. mounted,
  23. };
  24. export function setupPermissionDirective(app: App) {
  25. app.directive('auth', authDirective);
  26. }
  27. export default authDirective;