/*
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2018-10-08 10:45:05
 * @LastEditors: 无尘
 * @LastEditTime: 2020-03-19 09:37:40
 */
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 filters from './filters/index.js';

import vueOfficeHeader from '@gic-test/vue-office-header';
import vueOfficeAside from '@gic-test/vue-office-aside';
import vueOfficeArea from '@gic-test/vue-office-area';
import vueGicImgPreview from '@gic-test/vue-gic-img-preview';
import vueOfficeUploadImage from '@gic-test/vue-office-upload-image';
import htmlToPdf from '@/components/utils/htmlToPdf';
import VueAMap from 'vue-amap';
// import contentmenu from 'v-contextmenu';
// import 'v-contextmenu/dist/index.css';

// Vue.use(contentmenu);
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: 'd53a58848be368a7398dc56d5670fe9c',
  plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'Geocoder', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor'],
  v: '1.4.4'
});

Vue.use(htmlToPdf);
Vue.use(vueGicImgPreview);
Vue.use(vueOfficeUploadImage);
Vue.use(vueOfficeArea);
Vue.use(vueOfficeAside);
Vue.use(vueOfficeHeader);

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: '/login' });
  } else {
    next();
  }
});

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