hasPermi.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * v-hasPermi 操作权限处理
  3. * Copyright (c) 2019 ruoyi
  4. */
  5. import useUserStore from '@/store/modules/user'
  6. export const hasPermi = {
  7. mounted(el, binding, vnode) {
  8. const { value } = binding
  9. const all_permission = "*:*:*";
  10. const permissions = useUserStore().permissions
  11. // debugger
  12. if (value && value instanceof Array && value.length > 0) {
  13. const permissionFlag = value
  14. const hasPermissions = permissions.some(permission => {
  15. return all_permission === permission || permissionFlag.includes(permission)
  16. })
  17. // console.log(hasPermissions)
  18. if (!hasPermissions) {
  19. el.parentNode && el.parentNode.removeChild(el)
  20. }
  21. } else {
  22. throw new Error(`请设置操作权限标签值`)
  23. }
  24. }
  25. }
  26. export const hasNoPermi = {
  27. mounted(el, binding, vnode) {
  28. const { value } = binding
  29. const all_permission = "*:*:*";
  30. const permissions = useUserStore().permissions
  31. // debugger
  32. if (value && value instanceof Array && value.length > 0) {
  33. const permissionFlag = value
  34. const hasPermissions = permissions.some(permission => {
  35. return all_permission === permission || permissionFlag.includes(permission)
  36. })
  37. // console.log(hasPermissions)
  38. if (hasPermissions) {
  39. el.parentNode && el.parentNode.removeChild(el)
  40. }
  41. } else {
  42. throw new Error(`请设置操作权限标签值`)
  43. }
  44. }
  45. }