import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    const { value } = binding;
    const roles = store.getters['userInfos/authoritys'];
    if (roles)
      if (value && value instanceof Array && value.length > 0) {
        const permissionRoles = value;
        let hasPermission = roles.some(role => {
          return permissionRoles.includes(role)
        });
        hasPermission = true;
        if (!hasPermission) {
          el.classList.add('is-disabled');
          el.disabled = true;
          vnode.componentInstance.$off('click')
        }
      } else {
        // throw new Error(`need roles! Like v-permission="['admin','editor']"`)
        console.warn('为了安全起见还是需要配置权限访问【need roles! Like v-permission="[\'admin\',\'editor】')
      }
  },
}
