SecurityDirective.ts 1.05 KB
// @ts-ignore
import store from '@/store';
import {Privilege} from './Privilege';

const SecurityDirective = {
    // 在绑定元素的父组件挂载之前调用
    beforeMount(el: any, binding: any, vnode: any, prevVnode: any) {

    },
    // 在绑定元素的 attribute 或事件监听器被应用之前调用
    created() {
        //
    },
    // 在绑定元素的父组件挂载之后调用
    mounted(el: any, binding: any) {
        const privileges = store.getters['security/getPrivileges'];
        const privilege = Privilege.findPrivilegeByCode(binding.value, privileges);
        if (!privilege) {
            el.remove();
        }
    },
    // 在包含组件的 VNode 更新之前调用
    beforeUpdate() {
        //
    },
    // 在包含组件的 VNode 及其子组件的 VNode 更新之后调用
    updated() {
        //
    },
    // 在绑定元素的父组件卸载之前调用
    beforeUnmount() {
        //
    },
    // 在绑定元素的父组件卸载之后调用
    unmounted() {
        //
    }
}

export default SecurityDirective;