import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI ,{ Message } from 'element-ui'
import VueAxios from 'vue-axios'
import axios from 'axios'
import store from './store/store'
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 vueGicHeader from '@gic-test/vue-gic-header'
import vueGicAsideMenu from '@gic-test/vue-gic-aside-menu'
import vueAreaAb from '@gic-test/vue-area-ab'
// 新增公共 footer插件
import vueGicFooter from '@gic-test/vue-gic-footer'


Vue.use(vueGicFooter)
Vue.use(vueAreaAb)
Vue.use(vueGicAsideMenu)
Vue.use(vueGicHeader)

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

Vue.axios.defaults.withCredentials = true ;// 跨域cookie访问
Vue.axios.interceptors.request.use(
  config => {
    return config;
  },
  err => {
    console.log('requesterr' + err);
    return Promise.reject(err);
  });
Vue.axios.interceptors.response.use(
  response => {
    console.log("main:",response);
    if(response.status == 200 && response.data.errorCode == 1) {
      // router.replace({
      //   path: 'login',
      //   query: {redirect: router.currentRoute.fullPath}
      // })
      console.log("main:",response);
    }
    return response;
  },
  error => {
    console.log(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)
  });

// router.beforeEach((to, from, next) => {
//   console.log("")
//   if (window.location.pathname.slice(-1) !== '/') {
//     window.location = window.location.pathname + '/';
//   }
// })

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