"...net/mingsoft/cms/git@ustchcs.com:gujinli1118/MCMS.git" did not exist on "4c05f02b9f7c662d61c37288b7ebb02acd7af458"
Commit 3921561e authored by Junling Bu's avatar Junling Bu
Browse files

feat[litemall-wx, litemall-wx-api]: 微信小程序支持退出登录操作

parent 1e8b7cbc
...@@ -72,4 +72,11 @@ public class UserTokenManager { ...@@ -72,4 +72,11 @@ public class UserTokenManager {
return userToken.getSessionKey(); return userToken.getSessionKey();
} }
public static void removeToken(Integer userId) {
UserToken userToken = idMap.get(userId);
String token = userToken.getToken();
idMap.remove(userId);
tokenMap.remove(token);
}
} }
...@@ -356,4 +356,13 @@ public class WxAuthController { ...@@ -356,4 +356,13 @@ public class WxAuthController {
} }
return ResponseUtil.ok(); return ResponseUtil.ok();
} }
@PostMapping("logout")
public Object logout(@LoginUser Integer userId) {
if (userId == null) {
return ResponseUtil.unlogin();
}
UserTokenManager.removeToken(userId);
return ResponseUtil.ok();
}
} }
...@@ -15,6 +15,7 @@ module.exports = { ...@@ -15,6 +15,7 @@ module.exports = {
AuthLoginByWeixin: WxApiRoot + 'auth/login_by_weixin', //微信登录 AuthLoginByWeixin: WxApiRoot + 'auth/login_by_weixin', //微信登录
AuthLoginByAccount: WxApiRoot + 'auth/login', //账号登录 AuthLoginByAccount: WxApiRoot + 'auth/login', //账号登录
AuthLogout: WxApiRoot + 'auth/logout', //账号登出
AuthRegister: WxApiRoot + 'auth/register', //账号注册 AuthRegister: WxApiRoot + 'auth/register', //账号注册
AuthReset: WxApiRoot + 'auth/reset', //账号密码重置 AuthReset: WxApiRoot + 'auth/reset', //账号密码重置
AuthRegisterCaptcha: WxApiRoot + 'auth/regCaptcha', //验证码 AuthRegisterCaptcha: WxApiRoot + 'auth/regCaptcha', //验证码
......
...@@ -14,7 +14,8 @@ Page({ ...@@ -14,7 +14,8 @@ Page({
unship: 0, unship: 0,
unrecv: 0, unrecv: 0,
uncomment: 0 uncomment: 0
} },
hasLogin: false
}, },
onLoad: function(options) { onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数 // 页面初始化 options为页面跳转所带来的参数
...@@ -29,10 +30,11 @@ Page({ ...@@ -29,10 +30,11 @@ Page({
let userInfo = wx.getStorageSync('userInfo'); let userInfo = wx.getStorageSync('userInfo');
this.setData({ this.setData({
userInfo: userInfo, userInfo: userInfo,
hasLogin: true
}); });
let that = this; let that = this;
util.request(api.UserIndex).then(function (res) { util.request(api.UserIndex).then(function(res) {
if (res.errno === 0) { if (res.errno === 0) {
that.setData({ that.setData({
order: res.data.order order: res.data.order
...@@ -50,14 +52,14 @@ Page({ ...@@ -50,14 +52,14 @@ Page({
// 页面关闭 // 页面关闭
}, },
goLogin() { goLogin() {
if (!app.globalData.hasLogin) { if (!this.data.hasLogin) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/auth/login/login" url: "/pages/auth/login/login"
}); });
} }
}, },
goOrder() { goOrder() {
if (app.globalData.hasLogin) { if (this.data.hasLogin) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/ucenter/order/order" url: "/pages/ucenter/order/order"
}); });
...@@ -67,56 +69,67 @@ Page({ ...@@ -67,56 +69,67 @@ Page({
}); });
} }
}, },
goOrderIndex(e) { goOrderIndex(e) {
let tab = e.currentTarget.dataset.index if (this.data.hasLogin) {
let route = e.currentTarget.dataset.route let tab = e.currentTarget.dataset.index
try { let route = e.currentTarget.dataset.route
wx.setStorageSync('tab', tab); try {
} catch (e) { wx.setStorageSync('tab', tab);
} catch (e) {
} }
wx.navigateTo({ wx.navigateTo({
url: route, url: route,
success: function(res) {}, success: function(res) {},
fail: function(res) {}, fail: function(res) {},
complete: function(res) {}, complete: function(res) {},
}) })
} else {
wx.navigateTo({
url: "/pages/auth/login/login"
});
};
}, },
goCoupon() { 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({ wx.navigateTo({
url: "/pages/ucenter/coupon/coupon" url: "/pages/groupon/myGroupon/myGroupon"
}); });
} else { } else {
wx.navigateTo({ wx.navigateTo({
url: "/pages/auth/login/login" url: "/pages/auth/login/login"
}); });
}; };
}, },
goGroupon() { goCollect() {
if (app.globalData.hasLogin) { if (this.data.hasLogin) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/groupon/myGroupon/myGroupon" url: "/pages/ucenter/collect/collect"
}); });
} else { } else {
wx.navigateTo({ wx.navigateTo({
url: "/pages/auth/login/login" url: "/pages/auth/login/login"
}); });
}; };
}, },
goCollect() { goFeedback(e) {
if (app.globalData.hasLogin) { if (this.data.hasLogin) {
wx.navigateTo({
url: "/pages/ucenter/collect/collect"
});
} else {
wx.navigateTo({
url: "/pages/auth/login/login"
});
};
},
goFeedback(e) {
if (app.globalData.hasLogin) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/ucenter/feedback/feedback" url: "/pages/ucenter/feedback/feedback"
}); });
...@@ -126,80 +139,87 @@ Page({ ...@@ -126,80 +139,87 @@ Page({
}); });
}; };
}, },
goFootprint() { goFootprint() {
if (app.globalData.hasLogin) { if (this.data.hasLogin) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/ucenter/footprint/footprint" url: "/pages/ucenter/footprint/footprint"
}); });
} else { } else {
wx.navigateTo({ wx.navigateTo({
url: "/pages/auth/login/login" url: "/pages/auth/login/login"
}); });
}; };
}, },
goAddress() { goAddress() {
if (app.globalData.hasLogin) { if (this.data.hasLogin) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/ucenter/address/address" url: "/pages/ucenter/address/address"
}); });
} else { } else {
wx.navigateTo({ wx.navigateTo({
url: "/pages/auth/login/login" url: "/pages/auth/login/login"
}); });
}; };
}, },
bindPhoneNumber: function (e) { bindPhoneNumber: function(e) {
if (e.detail.errMsg !== "getPhoneNumber:ok"){ if (e.detail.errMsg !== "getPhoneNumber:ok") {
// 拒绝授权 // 拒绝授权
return; return;
} }
if (!this.data.hasLogin) {
wx.showToast({
title: '绑定失败:请先登录',
icon: 'none',
duration: 2000
});
return;
}
if (!app.globalData.hasLogin) { 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({ wx.showToast({
title: '绑定失败:请先登录', title: '目前不支持',
icon: 'none', icon: 'none',
duration: 2000 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) { util.request(api.AuthLogout, {}, 'POST');
if (res.errno === 0) { app.globalData.hasLogin = false;
wx.showToast({ wx.removeStorageSync('token');
title: '绑定手机号码成功', wx.removeStorageSync('userInfo');
icon: 'success', wx.reLaunch({
duration: 2000 url: '/pages/index/index'
}); });
} }
}); })
},
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'
});
}
}
})
} }
}) })
\ No newline at end of file
...@@ -71,30 +71,30 @@ ...@@ -71,30 +71,30 @@
<view class='user_row'> <view class='user_row'>
<view class='user_row_left'>必备工具</view> <view class='user_row_left'>必备工具</view>
</view> </view>
<view class='user_tool_area'> <view class='user_column'>
<view class='user_tool_item' bindtap='goAddress'> <view class='user_column_item' bindtap='goAddress'>
<image class='user_tool_item_image' src='/static/images/address.png'></image> <image class='user_column_item_image' src='/static/images/address.png'></image>
<view class='user_tool_item_text'>地址管理</view> <view class='user_column_item_text'>地址管理</view>
</view> </view>
<button class="user_tool_item_phone" open-type="getPhoneNumber" bindgetphonenumber="bindPhoneNumber"> <button class="user_column_item_phone" open-type="getPhoneNumber" bindgetphonenumber="bindPhoneNumber">
<image class='user_tool_item_image' src='/static/images/mobile.png'></image> <image class='user_column_item_image' src='/static/images/mobile.png'></image>
<view class='user_tool_item_text'>绑定手机</view> <view class='user_column_item_text'>绑定手机</view>
</button> </button>
<view class='user_tool_item' bindtap='goFeedback'> <view class='user_column_item' bindtap='goFeedback'>
<image class='user_tool_item_image' src='/static/images/feedback.png'></image> <image class='user_column_item_image' src='/static/images/feedback.png'></image>
<view class='user_tool_item_text'>意见反馈</view> <view class='user_column_item_text'>意见反馈</view>
</view> </view>
<view class='user_tool_item'> <view class='user_column_item'>
<contact-button style="opacity:0;position:absolute;" type="default-dark" session-from="weapp" size="27"> <contact-button style="opacity:0;position:absolute;" type="default-dark" session-from="weapp" size="27">
</contact-button> </contact-button>
<image class='user_tool_item_image' src='/static/images/customer.png'></image> <image class='user_column_item_image' src='/static/images/customer.png'></image>
<view class='user_tool_item_text'>联系客服</view> <view class='user_column_item_text'>联系客服</view>
</view> </view>
<view class='user_tool_item' bindtap='aboutUs'> <view class='user_column_item' bindtap='aboutUs'>
<image class='user_tool_item_image' src='/static/images/about_us.png'></image> <image class='user_column_item_image' src='/static/images/about_us.png'></image>
<view class='user_tool_item_text'>关于我们</view> <view class='user_column_item_text'>关于我们</view>
</view> </view>
</view> </view>
<!--<view class="logout" bindtap="exitLogin">退出登录</view>--> <view class="logout" wx:if="{{hasLogin}}" bindtap="exitLogin">退出登录</view>
</view> </view>
\ No newline at end of file
...@@ -135,60 +135,8 @@ page { ...@@ -135,60 +135,8 @@ page {
height: 6rpx; height: 6rpx;
} }
.box_bottom_area { .user_column_item_phone {
/* border: 1px solid black; *//* margin-top: 32rpx; */ width: 30%;
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;
text-align:center; text-align:center;
display:flex; display:flex;
justify-content:center; justify-content:center;
...@@ -198,6 +146,17 @@ page { ...@@ -198,6 +146,17 @@ page {
background:#fff; background:#fff;
border-bottom:1px solid #fafafa; border-bottom:1px solid #fafafa;
} }
.user_tool_item_phone::after{ .user_column_item_phone::after{
border: none; border: none;
} }
.logout{
margin-top: 30rpx;
height: 100rpx;
width: 100%;
line-height: 100rpx;
text-align: center;
background: #fff;
color: red;
font-size: 30rpx;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment