import axios from 'axios'
import Vue from 'vue'
let baseURL
if (process.env.NODE_ENV === 'development') {
baseURL = 'http://36.26.8.99:9080'
} else if (process.env.NODE_ENV === 'production') {
baseURL = 'http://36.26.8.99:9080'
}
const SUCCESS_CODE = 0
const FAILURE_CODE = -1
const baseConfig = {
withCredentials: true,
method: 'post',
baseURL
}
const a = axios.create(baseConfig)
a.interceptors.response.use(handleResponse, handleResponseError)
a.defaults.timeout = 30000;
function handleResponse(config) {
const { data } = config
const errMsg = config.config.errMsg
const { code } = data
if (code === FAILURE_CODE) {
return Promise.reject(showInfo(`${errMsg || ''}${data.msg}`))
} else {
return data
}
}
function handleResponseError(err) {
return Promise.reject(showInfo(`请求失败:${err?.message}`))
}
function showInfo(msg) {
Vue.prototype?.$aInfo(msg)
}
export default a