/*
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-11-12 10:18:29
 * @LastEditors: 无尘
 * @LastEditTime: 2019-11-20 10:10:51
 */
import promise from 'es6-promise';
promise.polyfill();
// import Vue from 'vue';
import App from './App';
import router from './router';
import {
  Message
} from 'element-ui';
import VueAxios from 'vue-axios';
import axios from 'axios';
import store from './store/store';
/* eslint-disable */
import 'element-ui/lib/theme-chalk/index.css';
import * as types from './store/types';
import '../theme/index.css';
import '../static/css/index.less';
import '../static/font/iconfont.css';
import '../static/font/iconfont.js';
require('../static/font/iconfont.js');
import filters from './filters/index.js';
import VeLine from 'v-charts/lib/line.common';
import VeHistogram from 'v-charts/lib/histogram.common';
Vue.component(VeLine.name, VeLine);
Vue.component(VeHistogram.name, VeHistogram);

Vue.config.devtools = true;
Vue.use(VueAxios, axios);
Vue.axios.defaults.withCredentials = true; // cookie访问
Object.keys(filters).forEach(key => Vue.filter(key, filters[key])); // 全局注册过滤器
Vue.axios.interceptors.request.use(
  config => {
    return config;
  },
  err => {
    return Promise.reject(err);
  }
);
Vue.axios.interceptors.response.use(
  response => {
    if (response.status == 200 && response.data.errorCode == 1) {}
    return response;
  },
  error => {
    if (error.response) {
      switch (error.response.status) {
        case 401:
          // 401 清除token信息并跳转到登录页面
          // store.commit(types.LOGOUT);
          // router.replace({
          //   path: 'login',
          //   query: {redirect: router.currentRoute.fullPath}
          // });
          window.location.href = window.location.origin + '/gic-web/#/';
        case 500:
          Message.error('服务器500');
      }
    }
    return Promise.reject(error.response.data);
  }
);

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