创建微服务:microservice-provider-shop-8003;小程序商品列表筛选、商品详情完成
This commit is contained in:
54
weixin-miniprogram/utils/sendRequest.js
Normal file
54
weixin-miniprogram/utils/sendRequest.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const app = getApp()
|
||||
|
||||
module.exports = function send_request({ url, method, data }) {
|
||||
wx.showLoading({
|
||||
title: '加载中'
|
||||
});
|
||||
wx.showNavigationBarLoading()
|
||||
// wx.startPullDownRefresh() // 会触发页面的刷新事件 造成死循环
|
||||
return new Promise((resolve, reject) => {
|
||||
let requestOption = {
|
||||
url: `${app.globalData.baseUrl}${url}`,
|
||||
method: method,
|
||||
data: data,
|
||||
success: function (d) {
|
||||
wx.hideLoading()
|
||||
let result = d.data;
|
||||
if (result.success) {
|
||||
// console.log('result', result)
|
||||
resolve(result.data)
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: result.msg,
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
resolve(null)
|
||||
}
|
||||
},
|
||||
fail: function (err) {
|
||||
wx.hideLoading()
|
||||
wx.showToast({
|
||||
title: "请求失败",
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
reject(err)
|
||||
},
|
||||
complete: function () {
|
||||
wx.hideNavigationBarLoading()
|
||||
wx.stopPullDownRefresh()
|
||||
}
|
||||
}
|
||||
switch (method.toUpperCase) {
|
||||
case "GET":
|
||||
break;
|
||||
case "POST":
|
||||
requestOption.header = {
|
||||
"Content-Type": "application/x-www-form-urlencoded" //用于post
|
||||
}
|
||||
break;
|
||||
}
|
||||
wx.request(requestOption)
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user