Files
LinHelp/miniapp/miniprogram/utils/request.js
2026-07-07 15:06:33 +08:00

27 lines
690 B
JavaScript

function request(options) {
const app = getApp()
const token = app.globalData.token
return new Promise((resolve, reject) => {
wx.request({
url: app.globalData.apiBaseUrl + options.url,
method: options.method || 'GET',
data: options.data || {},
header: Object.assign({
Authorization: token
}, options.header || {}),
success(res) {
if (res.statusCode >= 200 && res.statusCode < 300 && res.data && res.data.code === 0) {
resolve(res.data.data)
return
}
reject(new Error((res.data && res.data.message) || '请求失败'))
},
fail: reject
})
})
}
module.exports = {
request
}