<template>
|
<view class="page">
|
<view class="top">
|
<view class="background"></view>
|
</view>
|
<view class="user-card">
|
<view class="card">
|
<view class="top">
|
<view class="userImage">
|
<u-avatar :src="src" size="146"></u-avatar>
|
</view>
|
</view>
|
<view class="bottom" @tap.native="Login">
|
<view class="left">
|
<view class="user-text">
|
<text style="text-align: center;">{{userNickName}}</text>
|
</view>
|
</view>
|
<view class="right flex-center">
|
<u-icon class="icon" name="arrow-right"></u-icon>
|
</view>
|
</view>
|
</view>
|
</view>
|
<view class="list-card">
|
</view>
|
<view class="quit flex-center">
|
<view class="btn flex-center" @click="LastLogin">
|
退出登录
|
</view>
|
</view>
|
</view>
|
</template>
|
<style lang="scss" scoped>
|
.top {
|
height: 250rpx;
|
position: relative;
|
|
.background {
|
background-color: #5199ff;
|
border-bottom-left-radius: 22px;
|
border-bottom-right-radius: 22px;
|
position: absolute;
|
height: 180rpx;
|
width: 100%;
|
}
|
}
|
|
.icon {
|
color: #96a1ae;
|
font-size: 20rpx;
|
}
|
|
.user-card {
|
height: 170rpx;
|
padding: 0 15px;
|
|
.card {
|
position: relative;
|
bottom: 62px;
|
height: 250rpx;
|
background-color: white;
|
border-radius: 5px;
|
|
.top {
|
height: 30%;
|
position: relative;
|
|
.userImage {
|
position: absolute;
|
bottom: 24%;
|
left: 10%;
|
width: 150rpx;
|
height: 150rpx;
|
overflow: hidden;
|
border-radius: 50%;
|
border: 2px solid white;
|
}
|
}
|
|
.bottom {
|
display: flex;
|
height: 70%;
|
|
.left {
|
width: 80%;
|
height: 100%;
|
position: relative;
|
|
.user-text {
|
width: 100%;
|
font-size: 1.6em;
|
padding-left: 80rpx;
|
height: 50%;
|
}
|
|
.user-phone {
|
width: 100%;
|
font-size: 1.3em;
|
padding-left: 80rpx;
|
height: 50%;
|
}
|
}
|
|
.right {
|
width: 20%;
|
height: 50%;
|
}
|
|
.right2 {
|
width: 10%;
|
height: 10%;
|
}
|
}
|
|
.settings {
|
display: flex;
|
height: 70%;
|
|
.left {
|
width: 80%;
|
height: 50%;
|
position: relative;
|
margin-left: 5%;
|
|
.settings-text {
|
width: 100%;
|
font-size: 1.2em;
|
padding-left: 80rpx;
|
height: 50%;
|
align-items: center;
|
padding-top: 10px;
|
}
|
}
|
|
.right {
|
width: 20%;
|
height: 50%;
|
}
|
|
}
|
}
|
}
|
|
.list-card {
|
padding: 0 15px;
|
|
.card {
|
border-radius: 5px;
|
position: relative;
|
background-color: white;
|
border-radius: 5px;
|
padding: 5px 30px;
|
|
.item {
|
display: flex;
|
height: 120rpx;
|
|
.left {
|
width: 15%;
|
|
image {
|
width: 70rpx;
|
height: 70rpx;
|
}
|
}
|
|
.center {
|
width: 65%;
|
display: flex;
|
justify-content: start;
|
align-items: center;
|
font-size: 1.1em;
|
}
|
|
.right {
|
width: 20%;
|
justify-content: flex-end;
|
}
|
}
|
}
|
}
|
|
.item-bottom-solid {
|
border-bottom: 1px solid #d4d6da;
|
}
|
|
.quit {
|
height: 100rpx;
|
margin-top: 50px;
|
|
.btn {
|
background-color: #4f99ff;
|
border-radius: 30px;
|
width: 80%;
|
color: white;
|
font-size: 1.2em;
|
height: 100%;
|
}
|
}
|
|
.flex-center {
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
}
|
</style>
|
|
<script>
|
import httpInterceptor from '@/common/http.interceptor.js'
|
export default {
|
data() {
|
return {
|
src: "",
|
userNickName: '请登录',
|
// 过期时间检查定时器
|
checkExpirationTimer: null
|
};
|
},
|
onLoad() {
|
// 检查登录状态和是否过期
|
this.checkLoginStatus();
|
|
// 设置定时检查,每30分钟检查一次
|
this.checkExpirationTimer = setInterval(() => {
|
this.checkLoginExpiration();
|
}, 30 * 60 * 1000);
|
},
|
onUnload() {
|
// 页面卸载时清除定时器
|
if (this.checkExpirationTimer) {
|
clearInterval(this.checkExpirationTimer);
|
}
|
},
|
onShow() {
|
// 页面显示时再次检查
|
this.checkLoginStatus();
|
},
|
methods: {
|
// 检查登录状态
|
checkLoginStatus() {
|
let isLogin = this.hasLogin();
|
if (isLogin) {
|
// 检查是否过期
|
if (this.checkLoginExpiration()) {
|
let haslogin = uni.getStorageSync('jo_user')
|
this.userNickName = haslogin.userName;
|
this.src = httpInterceptor.baseUrl + "/" + haslogin.img;
|
}
|
}
|
},
|
|
// 检查登录是否过期
|
checkLoginExpiration() {
|
const expirationTime = uni.getStorageSync('jo_expiration_time');
|
const currentTime = new Date().getTime();
|
|
// 如果没有设置过期时间,视为未登录
|
if (!expirationTime) {
|
this.logout();
|
return false;
|
}
|
|
// 检查是否过期
|
if (currentTime > expirationTime) {
|
uni.showToast({
|
title: '登录已过期,请重新登录',
|
icon: 'none',
|
duration: 2000
|
});
|
this.logout();
|
return false;
|
}
|
return true;
|
},
|
|
hasLogin() {
|
let haslogin = uni.getStorageSync('jo_user')
|
if (haslogin == null || haslogin == "") {
|
return false
|
} else {
|
return true
|
}
|
},
|
|
// 退出登录
|
LastLogin() {
|
this.logout();
|
},
|
|
// 统一的退出登录处理
|
logout() {
|
uni.removeStorageSync('jo_id_token');
|
uni.removeStorageSync('jo_user');
|
uni.removeStorageSync('jo_userImg');
|
uni.removeStorageSync('jo_expiration_time'); // 清除过期时间
|
this.userNickName = '请登录';
|
this.src = "";
|
this.$u.route('/pages/login/login');
|
},
|
|
Login() {
|
this.$u.route('/pages/login/login');
|
},
|
settings(){
|
this.$u.route('/pages/index/settings');
|
}
|
},
|
};
|
</script>
|