import Vue from 'vue' import uni_request from './uni_request.js' const request = uni_request({ timeout: 123456, baseURL: 'http://fangw.jiuweiyun.cn/api', //线上 // baseURL: 'http://192.168.0.4:8114/api', //本地 // baseURL: 'http://192.168.0.15:8086/api', //本地 header: { 'content-type': 'application/json' } }) // 请求前拦截器 request.interceptors.request.use(config => { uni.showLoading({ title: '加载中', mask: true }) config.header.Authorization = 'Bearer ' + uni.getStorageSync("token") return config }) // 请求后拦截器 request.interceptors.response.use(async (response, ...args) => { // 拦截器 uni.hideLoading() if (response.data.code === 50000 || response.data.code === 40029) { //50000token过期 40029 code已使用 uni.removeStorageSync('token'); window.location = 'http://api.app.jiuweiyun.cn/api/fangwei/auth' } else { return response } }); request.onerror = (...args) => { // 请求失败统一处理方法 console.log(args) uni.hideLoading() uni.showModal({ title: '请求失败', content: '网络出错', // content: JSON.stringify(args), showCancel: false }) return Promise.reject(args) } export default request