// http.js页面 //#ifdef APP-PLUS export const baseUrl = "https://pfapi.86698.cn" //#endif // 判断是H5 //#ifdef H5 // const BASE_URL = "/api"; // const BASE_URL = "http://mt1.test.86698.cn/api"; const BASE_URL = "http://jifenshop1.test.86698.cn/api"; export const baseUrl = BASE_URL //#endif // 小程序 //#ifdef MP-WEIXIN // const BASE_URL = "/api"; // const BASE_URL = "https://pfapi.86698.cn"; const BASE_URL = "http://jifenshop1.test.86698.cn/api"; export const baseUrl = BASE_URL //#endif const request = (url, method, data = {}, showLoading = false) => { return new Promise((resolve, reject) => { // const token = uni.getStorageSync('token') const token = uni.getStorageSync("token") if (showLoading) { uni.showLoading({ title: "" }) } let api = baseUrl + url let tempData = data uni.request({ url: api, data: tempData, method: method, header: { //自定义请求头 'content-type': 'application/json', 'token': token }, success: res => { uni.hideLoading() if (res.data.code == 401) { uni.removeStorageSync('token') uni.reLaunch({ url: '/pages/index/index' }) } else { resolve(res); } }, fail: (error) => { uni.hideLoading() console.log('接口异常api', api) console.log('接口异常入参', tempData) console.log('接口异常返参', error) reject(error); }, complete() { uni.hideLoading() } }) }) } export default { request }