Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
3921561e
Commit
3921561e
authored
Nov 02, 2018
by
Junling Bu
Browse files
feat[litemall-wx, litemall-wx-api]: 微信小程序支持退出登录操作
parent
1e8b7cbc
Changes
6
Hide whitespace changes
Inline
Side-by-side
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/UserTokenManager.java
View file @
3921561e
...
...
@@ -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
);
}
}
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAuthController.java
View file @
3921561e
...
...
@@ -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
();
}
}
litemall-wx/config/api.js
View file @
3921561e
...
...
@@ -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
'
,
//验证码
...
...
litemall-wx/pages/ucenter/index/index.js
View file @
3921561e
...
...
@@ -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
.
globalD
ata
.
hasLogin
)
{
if
(
!
this
.
d
ata
.
hasLogin
)
{
wx
.
navigateTo
({
url
:
"
/pages/auth/login/login
"
});
}
},
goOrder
()
{
if
(
app
.
globalD
ata
.
hasLogin
)
{
if
(
this
.
d
ata
.
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/c
oupon/
c
oupon
"
url
:
"
/pages/
groupon/myGr
oupon/
myGr
oupon
"
});
}
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
(
!
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
({
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
litemall-wx/pages/ucenter/index/index.wxml
View file @
3921561e
...
...
@@ -71,30 +71,30 @@
<view class='user_row'>
<view class='user_row_left'>必备工具</view>
</view>
<view class='user_
tool_area
'>
<view class='user_
tool
_item' bindtap='goAddress'>
<image class='user_
tool
_item_image' src='/static/images/address.png'></image>
<view class='user_
tool
_item_text'>地址管理</view>
<view class='user_
column
'>
<view class='user_
column
_item' bindtap='goAddress'>
<image class='user_
column
_item_image' src='/static/images/address.png'></image>
<view class='user_
column
_item_text'>地址管理</view>
</view>
<button class="user_
tool
_item_phone" open-type="getPhoneNumber" bindgetphonenumber="bindPhoneNumber">
<image class='user_
tool
_item_image' src='/static/images/mobile.png'></image>
<view class='user_
tool
_item_text'>绑定手机</view>
<button class="user_
column
_item_phone" open-type="getPhoneNumber" bindgetphonenumber="bindPhoneNumber">
<image class='user_
column
_item_image' src='/static/images/mobile.png'></image>
<view class='user_
column
_item_text'>绑定手机</view>
</button>
<view class='user_
tool
_item' bindtap='goFeedback'>
<image class='user_
tool
_item_image' src='/static/images/feedback.png'></image>
<view class='user_
tool
_item_text'>意见反馈</view>
<view class='user_
column
_item' bindtap='goFeedback'>
<image class='user_
column
_item_image' src='/static/images/feedback.png'></image>
<view class='user_
column
_item_text'>意见反馈</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>
<image class='user_
tool
_item_image' src='/static/images/customer.png'></image>
<view class='user_
tool
_item_text'>联系客服</view>
<image class='user_
column
_item_image' src='/static/images/customer.png'></image>
<view class='user_
column
_item_text'>联系客服</view>
</view>
<view class='user_
tool
_item' bindtap='aboutUs'>
<image class='user_
tool
_item_image' src='/static/images/about_us.png'></image>
<view class='user_
tool
_item_text'>关于我们</view>
<view class='user_
column
_item' bindtap='aboutUs'>
<image class='user_
column
_item_image' src='/static/images/about_us.png'></image>
<view class='user_
column
_item_text'>关于我们</view>
</view>
</view>
<!--
<view class="logout" bindtap="exitLogin">退出登录</view>
-->
<view class="logout"
wx:if="{{hasLogin}}"
bindtap="exitLogin">退出登录</view>
</view>
\ No newline at end of file
litemall-wx/pages/ucenter/index/index.wxss
View file @
3921561e
...
...
@@ -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;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment