/*
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2018-10-08 10:45:05
 * @LastEditors: 无尘
 * @LastEditTime: 2020-12-03 15:33:49
 */
import 'babel-polyfill';
import promise from 'es6-promise';
promise.polyfill();
// import Vue from 'vue';
import App from './App';
import router from './router';
import ElementUI from 'element-ui'; //, { Message }
import VueAxios from 'vue-axios';
import axios from 'axios';
import store from './store/store';
/* eslint-disable  */
import * as types from './store/types';
import '../static/css/index.less';
import 'element-ui/lib/theme-chalk/index.css';
import '../static/font/iconfont.css';
import '../theme/index.css';
import '../static/css/dialog.css';
import filters from './filters/index.js';

// import contentmenu from 'v-contextmenu';
// import 'v-contextmenu/dist/index.css';

// Vue.use(contentmenu);

Vue.config.productionTip = false;
Vue.use(ElementUI, { size: 'large' });
Vue.use(VueAxios, axios);

Vue.axios.defaults.withCredentials = true; // cookie访问
// 全局注册过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

/*
 * 路由守护
 */
router.beforeEach((to, from, next) => {
  if (window.axiosPromiseArr) {
    axiosPromiseArr.forEach((ele, index) => {
      ele.cancel();
      delete axiosPromiseArr[index];
    });
  }

  let baseUrl;
  let host = window.location.origin;
  if (host.indexOf('localhost') != -1) {
    baseUrl = 'http://www.gicdev.com';
  } else {
    baseUrl = host;
  }
  if (!localStorage.getItem('userInfos')) {
    // axios
    //   .get(`${baseUrl}/haoban-manage-web/emp/get-user-info`, {})
    //   .then(res => {
    //     let resData = res.data;
    //     if (resData.errorCode == 1) {
    //       localStorage.setItem('userInfos', JSON.stringify(resData.result));
    //       return;
    //     }
    //     // Message.error({
    //     //    duration: 1000,
    //     //    message: resData.message
    //     //  })
    //   })
    //   .catch(function(error) {
    //     Message.error({
    //       duration: 1000,
    //       message: error.message
    //     });
    //   });
  }
  if (to.path == '/') {
    next({ path: '/index' });
  } else {
    next();
  }
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
});
