hasPermi.js 663 B

12345678910111213141516171819202122
  1. import { useUserStore } from '@/store/user.js'
  2. export default {
  3. mounted(el, binding, vnode) {
  4. const { value } = binding
  5. const all_permission = "*:*:*";
  6. const permissions = useUserStore().permissions
  7. if (value && value instanceof Array && value.length > 0) {
  8. const permissionFlag = value
  9. const hasPermissions = permissions.some(permission => {
  10. return all_permission === permission || permissionFlag.includes(permission)
  11. })
  12. if (!hasPermissions) {
  13. el.parentNode && el.parentNode.removeChild(el)
  14. }
  15. } else {
  16. throw new Error(`请设置操作权限标签值`)
  17. }
  18. }
  19. }