//不显示对话框的请求
|
|
const app = getApp()
|
|
|
|
function request(url, params, success, fail) {
|
|
this.requestLoading(url, params, "", success, fail)
|
|
}
|
|
|
|
//原来的请求方式 。现在首页五个接口沿用,直接在中转服务器获取数据
|
|
function requestLoading(method, params, successaction) {
|
|
wx.showLoading({
|
|
title: "加载中",
|
|
});
|
|
var data = {
|
|
'id': 1,
|
|
'method': method,
|
|
'params': params
|
|
};
|
|
var baseUrl = app.globalData.baseUrl + "?appID=" + app.globalData.appID + "&phone=" + app.globalData.phoneNum;
|
|
wx.request({
|
|
url: baseUrl,
|
|
data: data,
|
|
header: {
|
|
'content-type': 'application/json'
|
|
},
|
|
method: 'POST',
|
|
success: function(res) {
|
|
console.log(res)
|
|
if (res.data.error != null) {
|
|
wx.showModal({
|
|
showCancel: false,
|
|
title: '执行出错',
|
|
content: res.data.error.message,
|
|
})
|
|
} else {
|
|
successaction(res.data)
|
|
}
|
|
},
|
|
fail: function(res) {
|
|
console.log(res)
|
|
wx.showModal({
|
|
title: '执行出错',
|
|
content: res,
|
|
})
|
|
},
|
|
complete: function(res) {
|
|
wx.hideLoading()
|
|
},
|
|
})
|
|
}
|
|
|
|
// 中转服务器,跳转请求
|
|
function transfer_request(method, params, successaction) {
|
|
wx.showLoading({
|
|
title: "加载中",
|
|
})
|
|
var newData = {
|
|
"DecryptCookie": "",
|
|
"CustomerId": app.globalData.globalCustomerID,
|
|
"AppendUrlString": "?appID=" + app.globalData.appID + "&phone=" + app.globalData.phoneNum,
|
|
"Method": method,
|
|
"Data": params,
|
|
};
|
|
// 中转服务器地址
|
|
var baseUrl = app.globalData.tranferBaseUrl;
|
|
wx.request({
|
|
url: baseUrl,
|
|
data: newData,
|
|
header: {
|
|
'content-type': 'application/json'
|
|
},
|
|
method: 'post',
|
|
success: function (res) {
|
|
console.log(res)
|
|
if (res.data.error != null) {
|
|
wx.showModal({
|
|
showCancel: false,
|
|
title: '执行出错',
|
|
content: res.data.error.message,
|
|
})
|
|
} else {
|
|
successaction(res.data)
|
|
}
|
|
},
|
|
fail: function (res) {
|
|
console.log(res)
|
|
wx.showModal({
|
|
title: '执行出错',
|
|
content: res,
|
|
})
|
|
},
|
|
complete: function (res) {
|
|
wx.hideLoading()
|
|
},
|
|
})
|
|
}
|
|
|
|
module.exports = {
|
|
request: request,
|
|
requestLoading: requestLoading,
|
|
transfer_request: transfer_request,
|
|
}
|