liudong
2024-08-24 cd8ea3d115de633ecf0f65febe51013e762ecb8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { DirectiveBinding } from 'vue';
import { useUserStore } from '@/store';
import { getUserResources } from "@/utils/auth";
 
function hasPermissionDirective(el: HTMLElement, binding: DirectiveBinding) {
 
  // 获取用户权限
  const userStore = useUserStore();
  const roleData = JSON.parse( getUserResources())
  const roleBtn = roleData.map((item: any) => item.component)
  const permission = binding.value as string;
 
    if (!roleBtn.includes(permission)) {
      el.style.display = 'none';
    }
}
 
 
 
export default {
  mounted(el: HTMLElement, binding: DirectiveBinding) {
  
    hasPermissionDirective(el, binding);
  },
  updated(el: HTMLElement, binding: DirectiveBinding) {
   
    hasPermissionDirective(el, binding);
  },
};