38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { ObjectDirective } from 'vue';
|
|
import { usePermission } from '@/hooks/web/usePermission';
|
|
|
|
export const perm: ObjectDirective = {
|
|
mounted(el: HTMLButtonElement, binding) {
|
|
if (binding.value == undefined) return;
|
|
const { action, effect } = binding.value;
|
|
const { hasSomePermission } = usePermission();
|
|
if (!hasSomePermission(binding.value)) {
|
|
if (effect == 'disabled') {
|
|
el.disabled = true;
|
|
el.style['disabled'] = 'disabled';
|
|
el.classList.add('n-button--disabled');
|
|
} else {
|
|
el.parentNode.removeChild(el)
|
|
}
|
|
}
|
|
},
|
|
};
|
|
|
|
|
|
export const perms: ObjectDirective = {
|
|
mounted(el: HTMLButtonElement, binding) {
|
|
if (binding.value == undefined) return;
|
|
const { action, effect } = binding.value;
|
|
const { hasEveryPermission } = usePermission();
|
|
if (!hasEveryPermission(action)) {
|
|
if (effect == 'disabled') {
|
|
el.disabled = true;
|
|
el.style['disabled'] = 'disabled';
|
|
el.classList.add('n-button--disabled');
|
|
} else {
|
|
el.parentNode.removeChild(el)
|
|
}
|
|
}
|
|
},
|
|
};
|