hasPermi.js 712 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * v-hasPermi 操作权限处理
  3. * Copyright (c) 2019 ruoyi
  4. */
  5. import store from '@/store'
  6. export default {
  7. inserted(el, binding, vnode) {
  8. const { value } = binding
  9. const all_permission = "*:*:*";
  10. const permissions = store.getters && store.getters.permissions
  11. if (value && value instanceof Array && value.length > 0) {
  12. const permissionFlag = value
  13. const hasPermissions = permissions.some(permission => {
  14. return all_permission === permission || permissionFlag.includes(permission)
  15. })
  16. if (!hasPermissions) {
  17. el.parentNode && el.parentNode.removeChild(el)
  18. }
  19. } else {
  20. throw new Error(`请设置操作权限标签值`)
  21. }
  22. }
  23. }