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 @@
必备工具
-
-
-
- 地址管理
+
+
+
+ 地址管理
-