34 lines
894 B
JavaScript
34 lines
894 B
JavaScript
const BASE_URL = 'http://127.0.0.1:8089/'; // 👈 换成你的后端地址
|
|
|
|
function request({ url, method = 'GET', data = {}, header = {} }) {
|
|
const token = '';
|
|
|
|
return new Promise((resolve, reject) => {
|
|
wx.request({
|
|
url: BASE_URL + url,
|
|
method,
|
|
data,
|
|
header: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': token ? `Bearer ${token}` : '',
|
|
...header
|
|
},
|
|
success(res) {
|
|
// FastAdmin 接口风格通常是 { code: 1, data: ..., msg: "success" }
|
|
if (res.data.code === 1) {
|
|
resolve(res.data.data);
|
|
} else {
|
|
wx.showToast({ title: res.data.msg || '请求失败', icon: 'none' });
|
|
reject(res.data);
|
|
}
|
|
},
|
|
fail(err) {
|
|
wx.showToast({ title: '网络错误', icon: 'none' });
|
|
reject(err);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = request;
|