From f0c3b808ca844b405f0e92ede8cfa681d3bc0803 Mon Sep 17 00:00:00 2001 From: Eratosici Date: Tue, 18 Jan 2022 09:23:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=A6=81=E7=94=A8=E8=B4=A6?= =?UTF-8?q?=E6=88=B7=E8=B7=B3=E8=BD=AC=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mall4uni/pages/accountLogin/accountLogin.vue | 10 ++--- mall4uni/utils/http.js | 46 ++++++++++++-------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/mall4uni/pages/accountLogin/accountLogin.vue b/mall4uni/pages/accountLogin/accountLogin.vue index a860913..7f01525 100644 --- a/mall4uni/pages/accountLogin/accountLogin.vue +++ b/mall4uni/pages/accountLogin/accountLogin.vue @@ -138,7 +138,7 @@ // credentials: this.credentials, // loginType: 0, //账号登录 // } - // // #endif + // // #endif if (this.principal.length == 0) { this.setData({ @@ -164,9 +164,9 @@ }, callBack: res => { console.log("login",res) - var loginResult = ''; - uni.setStorageSync("loginResult",res); - uni.setStorageSync('token', 'bearer' + res.access_token); + // var loginResult = ''; + // uni.setStorageSync("loginResult",res); + // uni.setStorageSync('token', 'bearer' + res.access_token); // return http.loginSuccess(res, () => { uni.showToast({ @@ -179,7 +179,7 @@ url: '/pages/index/index' }); },1000) - + } }) }) diff --git a/mall4uni/utils/http.js b/mall4uni/utils/http.js index 64e2248..b7c67c4 100644 --- a/mall4uni/utils/http.js +++ b/mall4uni/utils/http.js @@ -12,7 +12,7 @@ function request(params, isGetTonken) { // globalData.requestQueue.push(params); // return; // } - + if (Object.prototype.toString.call(params.data) == '[object Array]') { params.data = JSON.stringify(params.data); } else if (Object.prototype.toString.call(params.data) == '[object Number]') { @@ -81,7 +81,7 @@ function request(params, isGetTonken) { url = '/pages/accountLogin/accountLogin' } // #endif - + // #ifdef APP-PLUS var url = '/pages/accountLogin/accountLogin' // #endif @@ -104,12 +104,12 @@ function request(params, isGetTonken) { success: res => { if (res.confirm) { // 跳转登录页面 - // #ifdef H5 + // #ifdef H5 uni.navigateTo({ url: uni.getStorageSync('appType') == AppType.MP ? '/pages/login/login' : '/pages/accountLogin/accountLogin' }) // #endif - + // #ifdef MP-WEIXIN uni.navigateTo({ url: '/pages/login/login' @@ -123,12 +123,12 @@ function request(params, isGetTonken) { } }) // // 跳转登录页面 - // // #ifdef H5 + // // #ifdef H5 // uni.navigateTo({ // url: uni.getStorageSync('appType') == AppType.MP ? '/pages/login/login' : '/pages/accountLogin/accountLogin' // }) // // #endif - + // // #ifdef MP-WEIXIN // uni.navigateTo({ // url: '/pages/login/login' @@ -145,7 +145,7 @@ function request(params, isGetTonken) { } else { //如果有定义了params.errCallBack,则调用 params.errCallBack(res.data) if (params.errCallBack) { - + params.errCallBack(res); } uni.hideLoading(); @@ -247,26 +247,36 @@ var getToken = function (fn) { * @param {Object} fn 登录成功后的回调 */ function loginSuccess (result, fn) { - // 保存登陆信息 - wx.setStorageSync('loginResult', result) - // 保存成功登录标识,token过期判断 - wx.setStorageSync('hadLogin', true) - // 没有获取到用户昵称,说明服务器没有保存用户的昵称,也就是用户授权的信息并没有传到服务器 - // if (!result.pic) { - // updateUserInfo(); - // } if (!result.enabled) { uni.showModal({ showCancel: false, title: "提示", content: "您已被禁用,不能购买,请联系客服", cancelText: "取消", - confirmText: "确定" + confirmText: "确定", + success: function (res) { + if (res.confirm) { + wx.switchTab({ + url: '/pages/index/index' + }); + } + } }) wx.setStorageSync('token', ''); - } else { - wx.setStorageSync('token', 'bearer' + result.access_token); //把token存入缓存,请求接口数据时要用 + return } + + // 保存登陆信息 + wx.setStorageSync('loginResult', result) + // 保存成功登录标识,token过期判断 + wx.setStorageSync('hadLogin', true) + // 没有获取到用户昵称,说明服务器没有保存用户的昵称,也就是用户授权的信息并没有传到服务器 + // if (!result.pic) { + // updateUserInfo(); + // } + + wx.setStorageSync('token', 'bearer' + result.access_token); //把token存入缓存,请求接口数据时要用 + if (result.userId) { wx.setStorageSync('hadBindUser', true); getCartCount()