import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    const { value } = binding;
    const roles = store.getters['userInfos/authoritys'];
    console.log('permissionButton roles===>>>', roles)
    if (roles) {
      const permissionRoles = value;
      let hasPermission = roles.some(role => {
        return permissionRoles.includes(role)
      });
      // hasPermission = true;
      if (!hasPermission) {
        // TODO 暂时这么处理， 正常来说，应该不显示出来的
        el.classList.add('is-disabled');
        el.disabled = true;
        vnode.componentInstance.$off('click');
        // el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`need roles! Like v-permission="['admin','editor']"`)
    }
  }
}
