car_front/utils/request.js
2025-07-14 00:16:37 +08:00

37 lines
965 B
JavaScript

const BASE_URL = 'https://car.cherrybless.com'; // 👈 换成你的后端地址
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',
'Accept': '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) {
console.log(err)
wx.showToast({ title: '网络错误', icon: 'none' });
reject(err);
}
});
});
}
module.exports = request;