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 vueOfficeHeader from '@gic-test/vue-office-header'
import vueOfficeAside from '@gic-test/vue-office-aside'
import vueOfficeArea from '@gic-test/vue-office-area'
// 新增公共 footer插件
import vueGicFooter from '@gic-test/vue-gic-footer'
import vueGicImgPreview from '@gic-test/vue-gic-img-preview'
import vueOfficeUploadImage from '@gic-test/vue-office-upload-image'
import htmlToPdf from '@/components/utils/htmlToPdf'

Vue.use(htmlToPdf)
Vue.use(vueGicImgPreview)
Vue.use(vueOfficeUploadImage)
Vue.use(vueGicFooter)
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访问
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) => {

  // if (window.location.pathname.slice(-1) !== '/') {
  //   window.location = window.location.pathname + '/';
  // }
  if (to.path == '/') {
    next({ path: '/login' })
  } else {
    next()
  }
})

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