import request from '@/service/request.js';
import globalConfig from '@/config/index';

import store from '@/store/index';
export default config => {
  const { createApp } = config;
  window.onload = async function() {
    try {
      // 获取用户企业id
      let loginUserRes = await request.get('/api-auth/get-current-memu-data?project=integral-mall&path=giftExchange&requestProject=integral-mall');
      const leftMenu = loginUserRes.data.result.leftMenu || [];
      let _leftMenuLimit = [];
      leftMenu.forEach(element => {
        if (element.level4List) {
          element.level4List.forEach(level4 => {
            _leftMenuLimit.push(`/${level4.menuUrl}`);
          });
        } else {
          _leftMenuLimit.push(`/${element.menuUrl}`);
        }
      });
      _leftMenuLimit = [...new Set(_leftMenuLimit)];
      store.commit('mutations_updateMenuUrl', _leftMenuLimit); // 更新企业id
      createApp();
    } catch (error) {
      // 未登录
      window.location.href = globalConfig.api + 'gic-web/';
    }
  };
};
