import { ONLINEHOST, QAHOST, } from "./env.js"; // console.log(process.env.NODE_ENV) const BASE_URL = process.env.NODE_ENV === "production" ? ONLINEHOST : QAHOST; //公共请求头 /* @parms url 接口地址 @parms method 请求方式 @parms data 参数 */ const request = (url,data, method='POST', contentType='application/x-www-form-urlencoded',config = { timeout:5000,isShowLoading:true }) => { return new Promise((resolve, reject) => { if(config.isShowLoading){ uni.showLoading({ title: '加载中', mask: true }) } let model=uni.getStorageSync('model'); uni.request({ url: "http://"+model.udpAdress+":"+model.baoliu20 + url, //接口地址。 data: data, method: method, header: { //请求头可自定义 'content-type': contentType, }, timeout:config.timeout,//设置超时时间,默认5秒 success: (rep) => { //具体捕获请看自己接口返回的形式 // console.log(rep) let result = rep.data; uni.hideLoading(); if ((rep.statusCode == 200 || rep.statusCode == 0)) { resolve(result) } }, fail(error) { uni.hideLoading(); uni.$u.toast('网络不通'); reject(error) }, complete() { uni.hideLoading(); } }); }) } module.exports ={ request, //向外暴露request BASE_URL }