import { Local } from "@/utils/storage";
import SystemConfig from "@/utils/SystemConfig";

export default {
  inserted(el, binding, vnode) {
    const { value } = binding;
    const roles = Local.get(SystemConfig.adminAccess);
    if (roles) {
      const permissionRoles = value;
      let hasPermission = roles.some(role => {
        return permissionRoles.includes(role)
      });
      if (!hasPermission) {
        // TODO 暂时这么处理， 正常来说，应该不显示出来的
        el.classList.add('is-disabled');
        el.disabled = true;
        vnode.componentInstance.$off('click');
        // el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      console.warn('为了安全起见还是需要配置权限访问【need roles! Like v-permission="[\'admin\',\'editor】')
      throw new Error(`need roles! Like v-permission="['admin','editor']"`)
    }
  }
}
