//不显示对话框的请求
|
|
const app = getApp()
|
|
|
|
function request(url, params, success, fail) {
|
|
this.requestLoading(url, params, "", success, fail)
|
|
}
|
|
|
|
//原来的请求方式 。现在首页五个接口沿用,直接在中转服务器获取数据
|
|
function previousRequestLoading(method, params, successaction) {
|
|
wx.showLoading({
|
|
title: "加载中",
|
|
})
|
|
var data = {
|
|
'id': 1,
|
|
'method': method,
|
|
'params': params
|
|
};
|
|
var baseUrl = app.globalData.BaseUrl;
|
|
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) {
|
|
wx.showModal({
|
|
title: '执行出错',
|
|
content: res,
|
|
})
|
|
},
|
|
complete: function(res) {
|
|
wx.hideLoading()
|
|
},
|
|
})
|
|
}
|
|
|
|
// 新请求方式,添加中转服务器
|
|
function requestLoading(method, params, successaction) {
|
|
wx.showLoading({
|
|
title: "加载中",
|
|
})
|
|
var newData = {
|
|
"DecryptCookie": "",
|
|
"CustomerId": app.globalData.CustomerId,
|
|
"AppendUrlString": "?appid=" + app.globalData.AppId + "&phone=" + app.globalData.Phone,
|
|
"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) {
|
|
wx.showModal({
|
|
title: '执行出错',
|
|
content: res,
|
|
})
|
|
},
|
|
complete: function(res) {
|
|
wx.hideLoading()
|
|
},
|
|
})
|
|
}
|
|
|
|
module.exports = {
|
|
request: request,
|
|
requestLoading: requestLoading,
|
|
previousRequestLoading: previousRequestLoading
|
|
}
|