You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

151 lines
3.2 KiB

//不显示对话框的请求
const app = getApp()
function request(url, params, success, fail) {
this.requestLoading(url, params, "", success, fail)
}
// 展示进度条的网络请求
// url:网络请求的url
// params:请求参数
// message:进度条的提示信息
// success:成功的回调函数
// fail:失败的回调
function requestLoading(method, params, successaction) {
wx.showLoading({
title: "加载中",
})
var data = {
'id': 1,
'method': method,
'params': params
};
var baseUrl = app.globalData.BaseUrl
console.log(baseUrl)
console.log(data)
wx.request({
url: baseUrl,
data: data,
header: {
'content-type': 'application/json',
'cookie': app.globalData.Cookie
},
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 data = {
'DecryptCookie': app.globalData.DecryptCookie,
'AppendUrlString': '',
'Method': method,
'CustomerId': app.globalData.CustomerId,
'Data': params
};
var baseUrl = app.globalData.TransferUrl
console.log(baseUrl)
console.log(data)
wx.request({
url: baseUrl,
data: data,
header: {
'content-type': 'application/json'
},
method: 'POST',
success: function(res) {
// console.log(res)
if (res.data.error != null) {
if (res.data.error.code == '401' && res.data.error.message == "Unauthorized") {
console.log('重连系统-------------');
transfer_login()
} else {
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_login() {
wx.request({
url: app.globalData.TransferUrl,
data: {
'CustomerId': 1,
'Method': app.globalData.LoginPath,
'Data': [app.globalData.AppId, app.globalData.OpenId]
},
header: {
'content-type': 'application/json'
},
method: 'POST',
success: function(res) {
app.globalData.DecryptCookie = res.data.result;
console.log(app.globalData.DecryptCookie)
wx.showModal({
showCancel: false,
title: '提示',
content: '由于长时间未操作,需要重新连接!',
})
wx.switchTab({
url: '/pages/main/main',
})
}
})
}
module.exports = {
request: request,
requestLoading: requestLoading,
transfer_request: transfer_request
}