Newer
Older
KaiFengPC / src / directive / permission / hasPermi.js
@zhangdeliang zhangdeliang on 23 May 752 bytes 初始化项目
  1. /**
  2. * v-hasPermi 操作权限处理
  3. * Copyright (c) 2019 newfiber
  4. */
  5.  
  6. import useUserStore from "@/store/modules/user";
  7.  
  8. export default {
  9. mounted (el, binding, vnode) {
  10. const { value } = binding;
  11. const all_permission = "*:*:*";
  12. const permissions = useUserStore().permissions;
  13.  
  14. if (value && value instanceof Array && value.length > 0) {
  15. const permissionFlag = value;
  16.  
  17. const hasPermissions = permissions.some((permission) => {
  18. return (
  19. all_permission === permission || permissionFlag.includes(permission)
  20. );
  21. });
  22.  
  23. if (!hasPermissions) {
  24. el.parentNode && el.parentNode.removeChild(el);
  25. }
  26. } else {
  27. throw new Error(`请设置操作权限标签值`);
  28. }
  29. },
  30. };