java注销对话框_【java小程序实战】小程序注销功能实现
小程序?qū)崙?zhàn)中,如何實現(xiàn)程序的注銷功能呢?后端代碼只要刪除用戶的redi緩存即可。小程序端在成功返回消息后,進行登陸頁面的跳轉(zhuǎn)。
文章目錄
小程序的mine.wxml代碼
mine.wxss代碼
注銷事件的代碼mine.js
RegistLoginController 中注銷代碼
頁面展示
小程序的mine.wxml代碼
{{nickname}}
上傳作品
注銷
{{fansCounts}} 粉絲
{{followCounts}} 關注
{{receiveLikeCounts}} 獲贊
mine.wxss代碼
page {
font-size: 14px;
}
.container {
background-color: whitesmoke;
display: flex;
flex-direction: column;
align-items: center;
}
.container-row {
display: flex;
flex-direction: row;
margin-bottom: 10px;
margin-top: 10px;
}
.info-items {
margin-left: 30px;
}
.face {
width: 180rpx;
height: 180rpx;
border-radius: 50%;
margin-top: 20px;
}
.nickname {
margin-top: 5px;
font-weight: bold;
font-size: 18px;
}
.logout {
margin-top: 3px;
float: right;
}
.follow {
margin-top: 3px;
}
.line {
width: 100%;
height: 1px;
background-color: gainsboro;
margin-top: 1px;
}
.container-video {
display: flex;
flex-direction: row;
margin-top: 20px;
text-align: center;
border: solid 1px;
line-height: 30px;
}
.video-info {
width: 100%;
}
.video-info-selected {
background-color: gainsboro;
}
.container-video-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.videoImage {
width: 250rpx;
height: 180px;
}
注銷事件的代碼mine.js
通過事件函數(shù)發(fā)起請求,后端處理成功返回結(jié)果,并跳轉(zhuǎn)至登陸頁面。
設置小程序的全局變量userInfo為null
//注銷事件
logout: function () {
console.log("logout")
var user = app.userInfo;
var serverUrl = app.serverUrl;
wx.showLoading({
title: '請等待',
});
wx.request({
url: serverUrl+'/logout?userId=' + user.id,
method:"POST",
header: {
'content-type': 'application/json' //默認值
},
success: function (res) {
wx.hideLoading();
if( res.data.status == 200){
wx.showToast({
title: '注銷成功',
icon: 'success',
duration: 20000
});
//注銷成功,設置全局信息為null
app.userInfo = null;
wx.navigateTo({
url: '../login/login',
})
}
}
})
},
RegistLoginController 中注銷代碼
根據(jù)用戶id,清楚redis中的緩存記錄。
@ApiOperation(value="用戶注銷" , notes = "用戶注銷的接口")
@ApiImplicitParam(name = "userId", value = "用戶id" ,required = true,
dataType = "String", paramType = "query")
@PostMapping("/logout")
public IMoocJSONResult logout(String userId) {
System.out.println("userId:"+userId);
redis.del(USER_REDIS_SESSION + ":" + userId);
return IMoocJSONResult.ok();
}
總結(jié)
以上是生活随笔為你收集整理的java注销对话框_【java小程序实战】小程序注销功能实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 世界java大神有哪些_JAVA基础复习
- 下一篇: tacacs java客户端_思科交换机