import { VUE_APP_BASE_API } from '@/config/config'
import { getToken } from '@/utils/auth'
import Fly from 'flyio/dist/npm/wx'
const request = new Fly()
request.config.baseURL = VUE_APP_BASE_API
request.config.timeout = 3000
request.interceptors.request.use((request) => {
request.headers["content-type"] = "application/json";
if (getToken()) {
request.headers['Authorization'] = getToken()
}
return request;
})
request.interceptors.response.use(
(response) => {
return response
},
(err) => {
if (err.status == 0) {
console.log("网络连接异常");
return
} else if (err.status == 1) {
console.log("网络连接超时");
return
} else if (err.status == 401) {
console.log("用户未登录");
return
} else {
if (err.response.data.message) {
return err.response.data.message
} else {
return '请求数据失败,请稍后再试'
}
};
}
)
export default request
调用flyio
import request from '@/utils/request'
export function login(data) {
return request.post("auth/login",data)
}
export function getInfo() {
return request.get('auth/info')
}