import { requests } from '@/service/api/index';
import globalConfig from '@/config/index';
import axios from 'axios';
import store from '@/store/index';
import router from '../router';
export default config => {
  const { createApp } = config;

  window.onload = async function() {
    try {
      // 获取用户企业id
      let loginUserRes = await requests('/api-auth/get-login-user-info', { requestProject: 'gic-web', f: 1 });
      let enterpriseId = loginUserRes.result.userId;
      store.commit('updateEnterpriseId', enterpriseId); // 更新企业id
      // 获取是否限流
      let limitRes = await axios.get(`/api-plug/rate-limit?requestPath=gic-web&enterpriseId=${enterpriseId}`); // 这个接口不规范 不用封装的request
      createApp();
      // code: 0正常 1必填参数未填写 2限流
      if (limitRes.data.resultCode == 2) {
        store.commit('updateLimit', true); // 更新正在限流
        router.push('/limit');
      } else {
        store.commit('updateLimit', false);
      }
    } catch (error) {
      // 未登录
      window.location.href = globalConfig.api + 'gic-web/';
    }
  };
};
