action.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { useUserStore } from '@/stores/modules/user';
  2. import { MenuType } from '@/enum/app';
  3. function checkAction(el: any, action: any) {
  4. if (action.value && typeof action.value === 'string') {
  5. const userStore = useUserStore();
  6. const permissions = userStore.getPermissions;
  7. action = action.value.replace('@', '.').toLowerCase();
  8. const hasAction = permissions?.some(permission => {
  9. if (permission.type === MenuType.Button_Type) {
  10. const a: string =
  11. permission.module +
  12. '.' +
  13. permission.permission_mark.replace('@', '.');
  14. return action === a.toLowerCase();
  15. }
  16. });
  17. if (!hasAction) {
  18. // el.style.display = 'none'
  19. el.parentNode && el.parentNode.removeChild(el);
  20. }
  21. } else {
  22. throw new Error(
  23. `need action! Like v-action="module.controller.action" || v-action="module@controller@action" `
  24. );
  25. }
  26. }
  27. export default {
  28. mounted(el: any, binding: any) {
  29. checkAction(el, binding);
  30. },
  31. updated(el: any, binding: any) {
  32. checkAction(el, binding);
  33. }
  34. };