purview.js 524 Bytes
import Vue from 'vue';
import _ from 'lodash';

const getPurview = name => {
    let url = `/${_.split(name, '.').join('/')}`;

    return _.find(Vue.$purviews, p => p.menu_url === url);
};

export default {
    bind(el, binding) {
        let pur = getPurview(binding.value);

        if (!pur) {
            let routePath = _.get(Vue.$router, 'history.current.name', '');

            pur = getPurview(`${routePath}.${binding.value}`);
            if (!pur) {
                el.remove();
            }
        }
    }
};