44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const baseUrl = 'https://mini-chat.1024tool.vip/api/';
|
||
// const baseUrl = 'https://dsjhd9s.tbmw.cn/api/'
|
||
function request(url, method = 'GET', data = {}) {
|
||
|
||
const header = {
|
||
'content-type': 'application/json',
|
||
// 有其他content-type需求加点逻辑判断处理即可
|
||
};
|
||
|
||
return new Promise((resolve, reject) => {
|
||
wx.request({
|
||
url: baseUrl + url,
|
||
method,
|
||
data,
|
||
dataType: 'json', // 微信官方文档中介绍会对数据进行一次JSON.parse
|
||
header,
|
||
success(res) {
|
||
if (res.data.code) {
|
||
if (res.data.code == 10103) {
|
||
|
||
reject(res.data);
|
||
return;
|
||
}
|
||
wx.showToast({
|
||
title: res.data.message,
|
||
icon: 'none'
|
||
});
|
||
reject(res.data);
|
||
} else {
|
||
resolve(res.data);
|
||
}
|
||
|
||
},
|
||
fail(err) {
|
||
console.log(err)
|
||
// 断网、服务器挂了都会fail回调,直接reject即可
|
||
reject(err);
|
||
},
|
||
});
|
||
});
|
||
}
|
||
|
||
// 导出请求和服务地址(CommonJS 兼容)
|
||
module.exports = request; |