import Vue from 'vue'
import axios from '@/common/http';
import qs from 'qs';
import Loading from '@/common/plugins/loading'
axios.defaults.timeout = 600000
const instance = axios.create({
  baseURL:process.env.VUE_APP_MOBILE_API_BASE_URL
});

instance.interceptors.request.handlers = [...axios.interceptors.request.handlers]

instance.interceptors.request.handlers.splice(0,1,{
  fulfilled(config) {
    if(config.data.contentType){
      config.headers['Content-Type'] = config.data.contentType;
    }else {
      config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
      config.transformRequest = function (data) {
        return qs.stringify(data)
      }
    }
    return config;
  }
})
instance.interceptors.response.handlers = [...axios.interceptors.response.handlers]

Vue.use(Loading(),{
  http:instance
})

export default instance