Files
fitness-coach/miniprogram/utils/request.js
wm b3b58e66fb feat: init fitness-coach (backend + miniprogram)
- backend: NestJS service with exercise/plan data
- miniprogram: WeChat mini program client
- exclude node_modules, dist, runtime data-store, local env
2026-07-22 00:35:40 +08:00

32 lines
881 B
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.

// 统一的网络请求封装:所有请求都经过此包装器。
// 后端为公开 API无需鉴权头失败时统一 toast 提示。
const { BASE_URL } = require('../config');
function request({ url, method = 'GET', data = {} }) {
return new Promise((resolve, reject) => {
wx.request({
url: BASE_URL + url,
method,
data,
header: { 'content-type': 'application/json' },
success(res) {
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res.data);
} else {
wx.showToast({
title: '请求失败 (' + res.statusCode + ')',
icon: 'none'
});
reject(res);
}
},
fail(err) {
wx.showToast({ title: '网络错误,请稍后重试', icon: 'none' });
reject(err);
}
});
});
}
module.exports = { request };