From 3921561e5ca989708b16a9c9bbaf44e293d1044b Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Fri, 2 Nov 2018 23:05:19 +0800 Subject: [PATCH] =?UTF-8?q?feat[litemall-wx=EF=BC=8C=20litemall-wx-api]:?= =?UTF-8?q?=20=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../litemall/wx/service/UserTokenManager.java | 7 + .../litemall/wx/web/WxAuthController.java | 9 + litemall-wx/config/api.js | 1 + litemall-wx/pages/ucenter/index/index.js | 244 ++++++++++-------- litemall-wx/pages/ucenter/index/index.wxml | 34 +-- litemall-wx/pages/ucenter/index/index.wxss | 69 +---- 6 files changed, 180 insertions(+), 184 deletions(-) diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/UserTokenManager.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/UserTokenManager.java index a8a9db7c..67717b68 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/UserTokenManager.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/UserTokenManager.java @@ -72,4 +72,11 @@ public class UserTokenManager { return userToken.getSessionKey(); } + + public static void removeToken(Integer userId) { + UserToken userToken = idMap.get(userId); + String token = userToken.getToken(); + idMap.remove(userId); + tokenMap.remove(token); + } } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java index c52d467e..9cd27d5a 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java @@ -356,4 +356,13 @@ public class WxAuthController { } return ResponseUtil.ok(); } + + @PostMapping("logout") + public Object logout(@LoginUser Integer userId) { + if (userId == null) { + return ResponseUtil.unlogin(); + } + UserTokenManager.removeToken(userId); + return ResponseUtil.ok(); + } } diff --git a/litemall-wx/config/api.js b/litemall-wx/config/api.js index bf0dd5cf..57e611f3 100644 --- a/litemall-wx/config/api.js +++ b/litemall-wx/config/api.js @@ -15,6 +15,7 @@ module.exports = { AuthLoginByWeixin: WxApiRoot + 'auth/login_by_weixin', //微信登录 AuthLoginByAccount: WxApiRoot + 'auth/login', //账号登录 + AuthLogout: WxApiRoot + 'auth/logout', //账号登出 AuthRegister: WxApiRoot + 'auth/register', //账号注册 AuthReset: WxApiRoot + 'auth/reset', //账号密码重置 AuthRegisterCaptcha: WxApiRoot + 'auth/regCaptcha', //验证码 diff --git a/litemall-wx/pages/ucenter/index/index.js b/litemall-wx/pages/ucenter/index/index.js index 45321b3f..b6798cff 100644 --- a/litemall-wx/pages/ucenter/index/index.js +++ b/litemall-wx/pages/ucenter/index/index.js @@ -14,7 +14,8 @@ Page({ unship: 0, unrecv: 0, uncomment: 0 - } + }, + hasLogin: false }, onLoad: function(options) { // 页面初始化 options为页面跳转所带来的参数 @@ -29,10 +30,11 @@ Page({ let userInfo = wx.getStorageSync('userInfo'); this.setData({ userInfo: userInfo, + hasLogin: true }); let that = this; - util.request(api.UserIndex).then(function (res) { + util.request(api.UserIndex).then(function(res) { if (res.errno === 0) { that.setData({ order: res.data.order @@ -50,14 +52,14 @@ Page({ // 页面关闭 }, goLogin() { - if (!app.globalData.hasLogin) { + if (!this.data.hasLogin) { wx.navigateTo({ url: "/pages/auth/login/login" }); } }, goOrder() { - if (app.globalData.hasLogin) { + if (this.data.hasLogin) { wx.navigateTo({ url: "/pages/ucenter/order/order" }); @@ -67,56 +69,67 @@ Page({ }); } }, - goOrderIndex(e) { - let tab = e.currentTarget.dataset.index - let route = e.currentTarget.dataset.route - try { - wx.setStorageSync('tab', tab); - } catch (e) { + goOrderIndex(e) { + if (this.data.hasLogin) { + let tab = e.currentTarget.dataset.index + let route = e.currentTarget.dataset.route + try { + wx.setStorageSync('tab', tab); + } catch (e) { - } - wx.navigateTo({ - url: route, - success: function(res) {}, - fail: function(res) {}, - complete: function(res) {}, - }) + } + wx.navigateTo({ + url: route, + success: function(res) {}, + fail: function(res) {}, + complete: function(res) {}, + }) + } else { + wx.navigateTo({ + url: "/pages/auth/login/login" + }); + }; }, goCoupon() { - if (app.globalData.hasLogin) { + wx.showToast({ + title: '目前不支持', + icon: 'none', + duration: 2000 + }); + // if (this.data.hasLogin) { + // wx.navigateTo({ + // url: "/pages/ucenter/coupon/coupon" + // }); + // } else { + // wx.navigateTo({ + // url: "/pages/auth/login/login" + // }); + // }; + }, + goGroupon() { + if (this.data.hasLogin) { wx.navigateTo({ - url: "/pages/ucenter/coupon/coupon" + url: "/pages/groupon/myGroupon/myGroupon" }); } else { wx.navigateTo({ url: "/pages/auth/login/login" }); }; - }, - goGroupon() { - if (app.globalData.hasLogin) { - wx.navigateTo({ - url: "/pages/groupon/myGroupon/myGroupon" - }); - } else { - wx.navigateTo({ - url: "/pages/auth/login/login" - }); - }; - }, - goCollect() { - if (app.globalData.hasLogin) { - wx.navigateTo({ - url: "/pages/ucenter/collect/collect" - }); - } else { - wx.navigateTo({ - url: "/pages/auth/login/login" - }); - }; - }, - goFeedback(e) { - if (app.globalData.hasLogin) { + }, + goCollect() { + if (this.data.hasLogin) { + wx.navigateTo({ + url: "/pages/ucenter/collect/collect" + }); + } else { + wx.navigateTo({ + url: "/pages/auth/login/login" + }); + }; + }, + goFeedback(e) { + if (this.data.hasLogin) { wx.navigateTo({ url: "/pages/ucenter/feedback/feedback" }); @@ -126,80 +139,87 @@ Page({ }); }; }, - goFootprint() { - if (app.globalData.hasLogin) { - wx.navigateTo({ - url: "/pages/ucenter/footprint/footprint" - }); - } else { - wx.navigateTo({ - url: "/pages/auth/login/login" - }); - }; - }, - goAddress() { - if (app.globalData.hasLogin) { - wx.navigateTo({ - url: "/pages/ucenter/address/address" - }); - } else { - wx.navigateTo({ - url: "/pages/auth/login/login" - }); - }; - }, -bindPhoneNumber: function (e) { - if (e.detail.errMsg !== "getPhoneNumber:ok"){ - // 拒绝授权 - return; - } + goFootprint() { + if (this.data.hasLogin) { + wx.navigateTo({ + url: "/pages/ucenter/footprint/footprint" + }); + } else { + wx.navigateTo({ + url: "/pages/auth/login/login" + }); + }; + }, + goAddress() { + if (this.data.hasLogin) { + wx.navigateTo({ + url: "/pages/ucenter/address/address" + }); + } else { + wx.navigateTo({ + url: "/pages/auth/login/login" + }); + }; + }, + bindPhoneNumber: function(e) { + if (e.detail.errMsg !== "getPhoneNumber:ok") { + // 拒绝授权 + return; + } - if (!app.globalData.hasLogin) { + if (!this.data.hasLogin) { + wx.showToast({ + title: '绑定失败:请先登录', + icon: 'none', + duration: 2000 + }); + return; + } + + util.request(api.AuthBindPhone, { + iv: e.detail.iv, + encryptedData: e.detail.encryptedData + }, 'POST').then(function(res) { + if (res.errno === 0) { + wx.showToast({ + title: '绑定手机号码成功', + icon: 'success', + duration: 2000 + }); + } + }); + }, + goAfterSale: function() { wx.showToast({ - title: '绑定失败:请先登录', + title: '目前不支持', icon: 'none', duration: 2000 }); - return; - } + }, + aboutUs: function() { + wx.navigateTo({ + url: '/pages/about/about' + }); + }, + exitLogin: function() { + wx.showModal({ + title: '', + confirmColor: '#b4282d', + content: '退出登录?', + success: function(res) { + if (!res.confirm) { + return; + } - util.request(api.AuthBindPhone, { iv: e.detail.iv, encryptedData: e.detail.encryptedData }, 'POST').then(function (res) { - if (res.errno === 0) { - wx.showToast({ - title: '绑定手机号码成功', - icon: 'success', - duration: 2000 - }); - } - }); -}, -goAfterSale: function () { - wx.showToast({ - title: '目前不支持', - icon: 'none', - duration: 2000 - }); -}, -aboutUs: function () { - wx.navigateTo({ - url: '/pages/about/about' - }); -}, - exitLogin: function() { - wx.showModal({ - title: '', - confirmColor: '#b4282d', - content: '退出登录?', - success: function(res) { - if (res.confirm) { - wx.removeStorageSync('token'); - wx.removeStorageSync('userInfo'); - wx.switchTab({ - url: '/pages/index/index' - }); - } - } - }) + util.request(api.AuthLogout, {}, 'POST'); + app.globalData.hasLogin = false; + wx.removeStorageSync('token'); + wx.removeStorageSync('userInfo'); + wx.reLaunch({ + url: '/pages/index/index' + }); + } + }) } }) \ No newline at end of file diff --git a/litemall-wx/pages/ucenter/index/index.wxml b/litemall-wx/pages/ucenter/index/index.wxml index 8830b7b4..2dc0826e 100644 --- a/litemall-wx/pages/ucenter/index/index.wxml +++ b/litemall-wx/pages/ucenter/index/index.wxml @@ -71,30 +71,30 @@ 必备工具 - - - - 地址管理 + + + + 地址管理 - - - - 意见反馈 + + + 意见反馈 - + - - 联系客服 + + 联系客服 - - - 关于我们 + + + 关于我们 - + 退出登录 \ No newline at end of file diff --git a/litemall-wx/pages/ucenter/index/index.wxss b/litemall-wx/pages/ucenter/index/index.wxss index 676ee14d..81f96008 100644 --- a/litemall-wx/pages/ucenter/index/index.wxss +++ b/litemall-wx/pages/ucenter/index/index.wxss @@ -135,60 +135,8 @@ page { height: 6rpx; } -.box_bottom_area { - /* border: 1px solid black; *//* margin-top: 32rpx; */ - height: auto; - background: #fff; -} - -.user_tool_item { - width: 187.5rpx; - height: 142rpx; - /* border: 1px solid #757575; */ - text-align: center; - display: flex; - justify-content: center; - align-items: center; - flex-wrap: wrap; - float: left; - background: #fff; - border-bottom: 1px solid #fafafa; -} - -.user_tool_item_image { - /* border: 1px solid #757575; */ - width: 50rpx; - height: 50rpx; - margin-top: 23rpx; -} - -.user_tool_item_text { - /* border: 1px solid #757575; */ - width: 187.5rpx; - margin-bottom: 12rpx; - height: 42rpx; - line-height: 42rpx; - font-size: 23rpx; - color: #555; -} - -.user_tool_item { - width: 187.5rpx; - height: 142rpx; - /* border: 1px solid #757575; */ - text-align: center; - display: flex; - justify-content: center; - align-items: center; - flex-wrap: wrap; - float: left; - background: #fff; - border-bottom: 1px solid #fafafa; -} - -.user_tool_item_phone { - width:187.5rpx; - height:142rpx; +.user_column_item_phone { + width: 30%; text-align:center; display:flex; justify-content:center; @@ -198,6 +146,17 @@ page { background:#fff; border-bottom:1px solid #fafafa; } -.user_tool_item_phone::after{ +.user_column_item_phone::after{ border: none; } + +.logout{ + margin-top: 30rpx; + height: 100rpx; + width: 100%; + line-height: 100rpx; + text-align: center; + background: #fff; + color: red; + font-size: 30rpx; +}