lanan-app/request/index.js

43 lines
769 B
JavaScript
Raw Normal View History

2024-08-20 20:02:05 +08:00
// 同时发送异步代码的次数
let ajaxTimes = 0;
export const request = (params) => {
var openid = wx.getStorageSync("openid") || '';
let header = {
...params.header
};
let urls;
if (params.url.indexOf('?')) {
urls = params.url
} else {
urls = params.url
}
// 定义公共的url
// const baseUrl="https://jfsc.lmweixin.com/";
const baseUrl = "http://192.168.1.159:8080/";
return new Promise((resolve, reject) => {
wx.request({
...params,
header: header,
url: baseUrl + urls,
success: (result) => {
resolve(result.data);
},
fail: (err) => {
reject(err);
},
complete: () => {
ajaxTimes--;
if (ajaxTimes === 0) {
// 关闭正在等待的图标
wx.hideLoading();
}
}
});
})
}