|
|
@ -1,57 +1,70 @@ |
|
|
//不显示对话框的请求
|
|
|
|
|
|
const app = getApp() |
|
|
|
|
|
|
|
|
|
|
|
function request(url, params, success, fail) { |
|
|
|
|
|
this.requestLoading(url, params, "", success, fail) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var app = getApp(); |
|
|
|
|
|
|
|
|
|
|
|
var reconnectMethod = ''; |
|
|
|
|
|
var reconnectParams = []; |
|
|
|
|
|
var newReconnectMethod = ''; |
|
|
|
|
|
var newReconnectParams = []; |
|
|
|
|
|
|
|
|
// 展示进度条的网络请求
|
|
|
|
|
|
// url:网络请求的url
|
|
|
|
|
|
// params:请求参数
|
|
|
|
|
|
// message:进度条的提示信息
|
|
|
|
|
|
// success:成功的回调函数
|
|
|
|
|
|
// fail:失败的回调
|
|
|
|
|
|
function requestLoading(method, params, successaction, erroraction) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* method:接口str |
|
|
|
|
|
* params:参数[] |
|
|
|
|
|
* successaction:成功回调 |
|
|
|
|
|
*/ |
|
|
|
|
|
function requestLoading(method, params, successaction) { |
|
|
|
|
|
reconnectMethod = method; |
|
|
|
|
|
reconnectParams = params; |
|
|
wx.showLoading({ |
|
|
wx.showLoading({ |
|
|
title: "加载中", |
|
|
title: "加载中", |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
var data = { |
|
|
var data = { |
|
|
'id': 1, |
|
|
'id': 1, |
|
|
'method': method, |
|
|
'method': method, |
|
|
'params': params |
|
|
'params': params |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
var baseUrl = app.globalData.BaseUrl |
|
|
|
|
|
console.log(baseUrl) |
|
|
|
|
|
console.log(data) |
|
|
|
|
|
wx.request({ |
|
|
wx.request({ |
|
|
url: baseUrl, |
|
|
|
|
|
|
|
|
url: app.globalData.BaseUrl, |
|
|
data: data, |
|
|
data: data, |
|
|
header: { |
|
|
header: { |
|
|
'content-type': 'application/json', |
|
|
'content-type': 'application/json', |
|
|
'cookie': app.globalData.Cookie |
|
|
|
|
|
|
|
|
'cookie': app.globalData.cookie |
|
|
}, |
|
|
}, |
|
|
method: 'POST', |
|
|
method: 'POST', |
|
|
success: function(res) { |
|
|
|
|
|
|
|
|
success: function (res) { |
|
|
// console.log(res)
|
|
|
// console.log(res)
|
|
|
if (res.data.error != null) { |
|
|
if (res.data.error != null) { |
|
|
if (erroraction != null) { |
|
|
|
|
|
erroraction(res.data.error) |
|
|
|
|
|
|
|
|
if (res.data.error.code == 401) { |
|
|
|
|
|
wx.request({ |
|
|
|
|
|
url: app.globalData.BaseUrl, |
|
|
|
|
|
data: { |
|
|
|
|
|
'id': 1, |
|
|
|
|
|
'method': "/MainSystem/MainSystem/Auth/WeixinLogin", |
|
|
|
|
|
'params': [app.globalData.appID, app.globalData.openID] |
|
|
|
|
|
}, |
|
|
|
|
|
header: { |
|
|
|
|
|
'content-type': 'application/json', |
|
|
|
|
|
'cookie': app.globalData.cookie |
|
|
|
|
|
}, |
|
|
|
|
|
method: 'POST', |
|
|
|
|
|
success: function (res) { |
|
|
|
|
|
app.globalData.cookie = res.data.result; |
|
|
|
|
|
requestLoading(reconnectMethod, reconnectParams, successaction); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
} else { |
|
|
} else { |
|
|
wx.showModal({ |
|
|
wx.showModal({ |
|
|
showCancel: false, |
|
|
showCancel: false, |
|
|
title: '执行出错:', |
|
|
|
|
|
|
|
|
title: '执行出错', |
|
|
content: res.data.error.message, |
|
|
content: res.data.error.message, |
|
|
}) |
|
|
}) |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
successaction(res.data) |
|
|
successaction(res.data) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
fail: function(res) { |
|
|
|
|
|
|
|
|
fail: function (res) { |
|
|
console.log(res) |
|
|
console.log(res) |
|
|
wx.showModal({ |
|
|
wx.showModal({ |
|
|
title: '执行出错', |
|
|
title: '执行出错', |
|
|
@ -59,41 +72,58 @@ function requestLoading(method, params, successaction, erroraction) { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
complete: function(res) { |
|
|
|
|
|
|
|
|
complete: function (res) { |
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
}, |
|
|
}, |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function transfer_request(method, params, successaction) { |
|
|
function transfer_request(method, params, successaction) { |
|
|
|
|
|
|
|
|
|
|
|
newReconnectMethod = method; |
|
|
|
|
|
newReconnectParams = params; |
|
|
wx.showLoading({ |
|
|
wx.showLoading({ |
|
|
title: "加载中", |
|
|
title: "加载中", |
|
|
}) |
|
|
}) |
|
|
var data = { |
|
|
|
|
|
'DecryptCookie': app.globalData.DecryptCookie, |
|
|
|
|
|
'AppendUrlString': '', |
|
|
|
|
|
'Method': method, |
|
|
|
|
|
'CustomerId': app.globalData.CustomerId, |
|
|
|
|
|
'Data': params |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newData = { |
|
|
|
|
|
"DecryptCookie": app.globalData.cookie, |
|
|
|
|
|
"CustomerId": app.globalData.globalCustomerID, |
|
|
|
|
|
"Method": method, |
|
|
|
|
|
"Data": params |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
var baseUrl = app.globalData.TransferUrl |
|
|
|
|
|
console.log(baseUrl) |
|
|
|
|
|
console.log(data) |
|
|
|
|
|
|
|
|
var baseUrl = app.globalData.TranferBaseUrl; |
|
|
wx.request({ |
|
|
wx.request({ |
|
|
url: baseUrl, |
|
|
url: baseUrl, |
|
|
data: data, |
|
|
|
|
|
|
|
|
data: newData, |
|
|
header: { |
|
|
header: { |
|
|
'content-type': 'application/json' |
|
|
|
|
|
|
|
|
'content-type': 'application/json', |
|
|
|
|
|
'cookie': app.globalData.cookie |
|
|
}, |
|
|
}, |
|
|
method: 'POST', |
|
|
method: 'POST', |
|
|
success: function(res) { |
|
|
|
|
|
// console.log(res)
|
|
|
|
|
|
|
|
|
success: function (res) { |
|
|
|
|
|
// console.log(res)
|
|
|
if (res.data.error != null) { |
|
|
if (res.data.error != null) { |
|
|
if (res.data.error.code == '401' && res.data.error.message == "Unauthorized") { |
|
|
|
|
|
console.log('重连系统-------------'); |
|
|
|
|
|
transfer_login() |
|
|
|
|
|
|
|
|
if (res.data.error.code == 401) { |
|
|
|
|
|
wx.request({ |
|
|
|
|
|
url: app.globalData.TransferUrl, |
|
|
|
|
|
data: { |
|
|
|
|
|
"DecryptCookie": app.globalData.cookie, |
|
|
|
|
|
"CustomerId": app.globalData.globalCustomerID, |
|
|
|
|
|
"Method": "/MainSystem/MainSystem/Auth/WeixinLogin", |
|
|
|
|
|
"Data": [app.globalData.appID, app.globalData.openID] |
|
|
|
|
|
}, |
|
|
|
|
|
header: { |
|
|
|
|
|
'content-type': 'application/json', |
|
|
|
|
|
'cookie': app.globalData.cookie |
|
|
|
|
|
}, |
|
|
|
|
|
method: 'POST', |
|
|
|
|
|
success: function (res) { |
|
|
|
|
|
app.globalData.cookie = res.data.result; |
|
|
|
|
|
transfer_request(newReconnectMethod, newReconnectParams, successaction); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
} else { |
|
|
} else { |
|
|
wx.showModal({ |
|
|
wx.showModal({ |
|
|
showCancel: false, |
|
|
showCancel: false, |
|
|
@ -104,52 +134,21 @@ function transfer_request(method, params, successaction) { |
|
|
} else { |
|
|
} else { |
|
|
successaction(res.data) |
|
|
successaction(res.data) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
fail: function(res) { |
|
|
|
|
|
|
|
|
fail: function (res) { |
|
|
console.log(res) |
|
|
console.log(res) |
|
|
wx.showModal({ |
|
|
wx.showModal({ |
|
|
title: '执行出错', |
|
|
title: '执行出错', |
|
|
content: res, |
|
|
content: res, |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
complete: function(res) { |
|
|
|
|
|
|
|
|
complete: function (res) { |
|
|
wx.hideLoading() |
|
|
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 = { |
|
|
module.exports = { |
|
|
request: request, |
|
|
|
|
|
requestLoading: requestLoading, |
|
|
requestLoading: requestLoading, |
|
|
transfer_request: transfer_request |
|
|
transfer_request: transfer_request |
|
|
} |
|
|
|
|
|
|
|
|
} |