import  Vue from 'vue'
import axios from 'axios'
import test from '@/common/plugins/test'

axios.defaults.timeout = 6000;
axios.defaults.baseURL = process.env.VUE_APP_API_BASE_URL

axios.interceptors.request.use(function (config) {
  config.headers['X-Requested-With'] = 'XMLHttpRequest';
  config.headers['Content-Type'] = 'application/json';
  return config
})

axios.interceptors.response.use(function (response) {
  const res = response.data;
  Vue.prototype.$emit('global:INTERFACE_ACTION',res)
  if(res.error_no !== '0'){
    return Promise.reject(res)
  }
  return res;
},function (err) {
  const res = { data: err, error_info: '服务异常'}
  Vue.prototype.$emit('global:INTERFACE_ACTION',res);
  return Promise.reject(res)
})

Vue.use(test(),{
  name:'plugin-test'
})

export default axios
