
import axios from 'axios'
import common from "./common.js";
import vue from '../../components/common/bus';
axios.defaults.baseURL = common.ctx//'bus.common.ctx';//配置你的接口请求地址
axios.defaults.headers.post['Content-Type'] = 'application/json';//'multipart/form-data';//配置请求头信息。


// http response 拦截器
axios.interceptors.response.use(
  response => {
    //vue.$store.commit('endLoading');
    if(response.config.url.indexOf('8880')!=-1 || response.config.url.indexOf('8099')!=-1){
      return response.data;
    }else{
      return response;
    }
  },
  error => {
    //vue.$store.commit('endLoading');
    if (error.response) {
      switch (error.response.status) {
        case 401:
          // 401 清除token信息并跳转到登录页面
          vue.$store.commit('signOut');
          vue.$router.push('/login');
          break;
        case 500:

          vue.$store.commit('signOut');

          vue.$router.push('/login');

          break;
        default:
          break;
      }
    }
    let msg = "系统出现错误，请重试";
    vue.$message.error(msg);
    return Promise.reject(msg)

  });

export default axios;
