|
@@ -39,12 +39,12 @@ const gotoLogin = (function gotoLogin() {
|
|
|
* 封封微信的的request
|
|
|
*/
|
|
|
function request(url, data = {}, method = "POST", header = "application/x-www-form-urlencoded") {
|
|
|
-
|
|
|
- // if (!~url.indexOf('/api/cart/update') && !~url.indexOf('/api/cart/index')){
|
|
|
- // wx.showLoading({
|
|
|
- // title: '加载中...',
|
|
|
- // });
|
|
|
- // }
|
|
|
+
|
|
|
+// if (!~url.indexOf('/api/cart/update') && !~url.indexOf('/api/cart/index')){
|
|
|
+// wx.showLoading({
|
|
|
+// title: '加载中...',
|
|
|
+// });
|
|
|
+// }
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
wx.request({
|
|
|
url: url,
|
|
@@ -56,27 +56,12 @@ function request(url, data = {}, method = "POST", header = "application/x-www-fo
|
|
|
},
|
|
|
success: function (res) {
|
|
|
// wx.hideLoading();
|
|
|
-
|
|
|
-
|
|
|
- if (!Object.prototype.hasOwnProperty.call(res.data, 'data')) {
|
|
|
- res.data.data = res.data.message;
|
|
|
- }
|
|
|
-
|
|
|
- if (!Object.prototype.hasOwnProperty.call(res.data, 'errno')) {
|
|
|
- if(Object.prototype.hasOwnProperty.call(res.data, 'code')){
|
|
|
- res.data.errno = (res.data.code === 200 || res.data.code === 0) ? 0 : res.data.code;
|
|
|
- }
|
|
|
- }
|
|
|
- console.log('res', res, url);
|
|
|
-
|
|
|
if (res.statusCode == 200) {
|
|
|
+
|
|
|
let pages = getCurrentPages()
|
|
|
let currPage = pages[pages.length - 1].route
|
|
|
let notLogins = ['pages/index/index', 'pages/catalog/catalog', 'pages/category/category', 'pages/ucenter/index/index']
|
|
|
- console.log('test',res.data.code == 401 && !~notLogins.indexOf(currPage))
|
|
|
-
|
|
|
- if (res.data.code == 401 && !~notLogins.indexOf(currPage)) {
|
|
|
-
|
|
|
+ if (res.data.errno == 401 && !~notLogins.indexOf(currPage)) {
|
|
|
resolve(res.data);
|
|
|
gotoLogin()
|
|
|
} else {
|
|
@@ -94,17 +79,13 @@ function request(url, data = {}, method = "POST", header = "application/x-www-fo
|
|
|
resolve(res.data);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
if (url === api.UserInfo) {
|
|
|
let info = wx.getStorageSync('userInfo')
|
|
|
-
|
|
|
- if (info) {
|
|
|
- info.isAdmin = res.data.data.isAdmin;
|
|
|
- wx.setStorageSync('userInfo', info);
|
|
|
- }
|
|
|
-
|
|
|
+ info.isAdmin = res.data.data.isAdmin
|
|
|
+ wx.setStorageSync('userInfo', info);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
reject(res.errMsg);
|
|
|
}
|
|
@@ -113,7 +94,7 @@ function request(url, data = {}, method = "POST", header = "application/x-www-fo
|
|
|
fail: function (err) {
|
|
|
reject(err)
|
|
|
},
|
|
|
- complete: function (res) {
|
|
|
+ complete:function (res){
|
|
|
wx.stopPullDownRefresh()
|
|
|
wx.hideLoading();
|
|
|
}
|
|
@@ -206,7 +187,7 @@ function checkNetStatu() {
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
-}
|
|
|
+ }
|
|
|
|
|
|
module.exports = {
|
|
|
formatTime,
|
|
@@ -218,4 +199,6 @@ module.exports = {
|
|
|
login,
|
|
|
imgServer,
|
|
|
checkNetStatu
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+
|