permission.ts 566 B

12345678910111213141516171819
  1. import { ObjectDirective } from 'vue'
  2. import { usePermission } from '@/hooks/web/usePermission'
  3. export const permission: ObjectDirective = {
  4. mounted(el: HTMLButtonElement, binding) {
  5. if (binding.value == undefined) return
  6. const { action, effect } = binding.value
  7. const { hasPermission } = usePermission()
  8. if (!hasPermission(action)) {
  9. if (effect == 'disabled') {
  10. el.disabled = true
  11. el.style['disabled' as any] = 'disabled'
  12. el.classList.add('n-button--disabled')
  13. } else {
  14. el.remove()
  15. }
  16. }
  17. }
  18. }