mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-02-04 13:42:27 +08:00
20 lines
570 B
TypeScript
20 lines
570 B
TypeScript
import { ObjectDirective } from 'vue';
|
|
import { usePermission } from '@/hooks/web/usePermission';
|
|
|
|
export const permission: ObjectDirective = {
|
|
mounted(el: HTMLButtonElement, binding) {
|
|
if (binding.value == undefined) return;
|
|
const { action, effect } = binding.value;
|
|
const { hasPermission } = usePermission();
|
|
if (!hasPermission(action)) {
|
|
if (effect == 'disabled') {
|
|
el.disabled = true;
|
|
el.style['disabled'] = 'disabled';
|
|
el.classList.add('n-button--disabled');
|
|
} else {
|
|
el.remove();
|
|
}
|
|
}
|
|
},
|
|
};
|