{"size": 1116, "ext": "js", "max_stars_repo_path": "src/util/ajax.js", "max_stars_repo_name": "bysir-zl/layout", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/util/ajax.js", "max_issues_repo_name": "bysir-zl/layout", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/util/ajax.js", "max_forks_repo_name": "bysir-zl/layout", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.0566037736, "max_line_length": 62, "alphanum_fraction": 0.6630824373}
// axios
import axios from 'axios'
import VueAxios from 'vue-axios'
import Vue from 'vue'

import auth from './auth.js'

let apiHost = "http://127.0.0.1:9630"
if (process.env.NODE_ENV === 'production') {
  apiHost = "http://127.0.0.1:9630"
}

let instance = axios.create({
  baseURL: apiHost+'/api',
  timeout: 15000,
})

// 添加token头
instance.interceptors.request.use(function (config) {
  config.headers['Token'] = auth.get()
  return config
}, function (error) {
  return Promise.reject(error);
});

// 出错提示与未登录跳转
instance.interceptors.response.use(function (response) {
  return response;
}, function (error) {
  if (!error.response) {
    Vue.prototype.$message({
      type: 'error',
      message: '服务器错误'
    })
    return Promise.reject(error);
  }
  let errInfo = error.response.data
  Vue.prototype.$message({
    type: 'error',
    message: errInfo.msg
  })

  if (error.response.data.code === 401) {
    localStorage.setItem("lastVisitUrl", window.location.href)
    // 跳转到用户微信登陆
    window.location = 'http://localhost:8080/#/login'
  }
  return Promise.reject(error);
});


Vue.use(VueAxios, instance)
