wx-chant/api/request.js
邹方成 8ebe968b1b fix(contact): 替换用户授权弹窗为静默登录提示
将用户授权弹窗改为静默登录提示,优化登录流程。同时更新API基础URL配置,移除废弃代码。
2025-10-22 03:57:38 +08:00

44 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;