// 展示进度条的网络请求 // url:网络请求的url // params:请求参数 // message:进度条的提示信息 // success:成功的回调函数 // fail:失败的回调 function requestLoading(url, params, message, success, fail, method = 'get') { // console.log(params) wx.showNavigationBarLoading(); if (message != "") { wx.showLoading({ title: message, }) } var sessionid = wx.getStorageSync('wx_outin') || wx.getStorageSync('wx'); if (sessionid != "" && sessionid != null) { var header = {'content-type': 'application/x-www-form-urlencoded', 'Cookie': 'wx=' + sessionid} } else { var header = {'content-type': 'application/x-www-form-urlencoded'} }; wx.request({ url: url, data: params, header: header, method: method, success: function (res) { var headerStr = JSON.stringify(res.header); // 判断响应头cookie里是否有wx,若有则存储到wxCookie里 if (sessionid == "" || sessionid == null){ if (headerStr.indexOf("wx=") > -1) { var reg = /wx=(w+)[;|"]/; var wxCookie = reg.exec(headerStr)[1]; wx.setStorageSync('wx', wxCookie); } } // console.log(wx.getStorageSync('wx')) wx.hideNavigationBarLoading() if (message != "") { wx.hideLoading() } if (res.statusCode == 200) { console.log(res.data.stat) if (res.data.stat==2){ wx.showModal({ title: '提示', content: '账号已退出,请重新登录', showCancel: false, success: function (res) { wx.redirectTo({ url: '../regist/index' }); } }) } success(res.data) } else { typeof fail == "function" && fail() } }, fail: function (res) { console.log(res); if (res.errMsg == 'request:fail ') { wx.showModal({ title: '提示', content: '当前网络状态差,请重试', success: function(res) { if (res.confirm) { setTimeout(function () { requestLoading(url, params, message, success, fail, method); }, 1000); } else if (res.cancel) { console.log('用户点击取消'); wx.redirectTo({ url:'../regist/index' }); } } }) } wx.hideNavigationBarLoading(); if (message != "") { wx.hideLoading() } typeof fail == "function" && fail() }, complete: function (res) { }, }) }