| | |
| | | <view class="card"> |
| | | <view class="top"> |
| | | <view class="userImage"> |
| | | <!-- <open-data type="userAvatarUrl"></open-data> --> |
| | | <u-avatar :src="src" size="146"></u-avatar> |
| | | </view> |
| | | </view> |
| | | <view class="bottom" @tap.native="Login"> |
| | | <view class="left"> |
| | | <view class="user-text"> |
| | | <!-- <open-data type="userNickName"></open-data> --> |
| | | <text style="text-align: center;">{{userNickName}}</text> |
| | | </view> |
| | | <!-- <view class="user-phone"> 171****4133 </view> --> |
| | | </view> |
| | | <view class="right flex-center"> |
| | | <u-icon class="icon" name="arrow-right"></u-icon> |
| | | </view> |
| | | </view> |
| | | <!-- <view class="settings" @click="settings"> |
| | | <view class="left"> |
| | | <view class="settings-text"> |
| | | <open-data type="userNickName"></open-data> |
| | | <text style="text-align: center;">设置</text> |
| | | </view> |
| | | <view class="user-phone"> 171****4133 </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 class="btn flex-center" @click="LastLogin"> |
| | | éåºç»å½ |
| | | </view> |
| | |
| | | </style> |
| | | |
| | | <script> |
| | | //import { } from "@/common/api/{$}.js"; |
| | | import httpInterceptor from '@/common/http.interceptor.js' |
| | | export default { |
| | | data() { |
| | | return { |
| | | src: "", |
| | | userNickName: '请ç»å½', |
| | | // è¿ææ¶é´æ£æ¥å®æ¶å¨ |
| | | checkExpirationTimer: null |
| | | }; |
| | | }, |
| | | //çå¬é¡µé¢åå§åï¼å
¶åæ°å onLoad åæ°ï¼ä¸ºä¸ä¸ªé¡µé¢ä¼ éçæ°æ®ï¼åæ°ç±»å为 Objectï¼ç¨äºé¡µé¢ä¼ åï¼ï¼è§¦åæ¶æºæ©äº onLoad |
| | | onInit() {}, |
| | | //çå¬é¡µé¢å è½½ï¼å
¶åæ°ä¸ºä¸ä¸ªé¡µé¢ä¼ éçæ°æ®ï¼åæ°ç±»å为 Objectï¼ç¨äºé¡µé¢ä¼ åï¼ |
| | | onLoad() { |
| | | let isLogin = this.hasLogin(); |
| | | if (isLogin) { |
| | | let haslogin = uni.getStorageSync('jo_user') |
| | | this.userNickName = haslogin.userName; |
| | | this.src = httpInterceptor.baseUrl + "/" + haslogin.img; |
| | | // æ£æ¥ç»å½ç¶æåæ¯å¦è¿æ |
| | | this.checkLoginStatus(); |
| | | |
| | | // è®¾ç½®å®æ¶æ£æ¥ï¼æ¯30å鿣æ¥ä¸æ¬¡ |
| | | this.checkExpirationTimer = setInterval(() => { |
| | | this.checkLoginExpiration(); |
| | | }, 30 * 60 * 1000); |
| | | }, |
| | | onUnload() { |
| | | // 页é¢å¸è½½æ¶æ¸
é¤å®æ¶å¨ |
| | | if (this.checkExpirationTimer) { |
| | | clearInterval(this.checkExpirationTimer); |
| | | } |
| | | }, |
| | | //çå¬é¡µé¢å次渲æå®æã注æå¦ææ¸²æé度快ï¼ä¼å¨é¡µé¢è¿å
¥å¨ç»å®æå触å |
| | | onReady() {}, |
| | | //çå¬é¡µé¢æ¾ç¤ºã页颿¯æ¬¡åºç°å¨å±å¹ä¸é½è§¦åï¼å
æ¬ä»ä¸çº§é¡µé¢ç¹è¿åé²åºå½åé¡µé¢ |
| | | beforeDestroy() {}, |
| | | //页颿»å¨å°åºé¨çäºä»¶ï¼ä¸æ¯scroll-viewæ»å°åºï¼ï¼å¸¸ç¨äºä¸æä¸ä¸é¡µæ°æ®ã |
| | | onReachBottom() {}, |
| | | onShareAppMessage(res) {}, |
| | | created() {}, |
| | | 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 == "") { |
| | |
| | | } |
| | | }, |
| | | |
| | | // éåºç»å½ |
| | | LastLogin() { |
| | | //uni.clearStorage(); |
| | | 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'); |
| | | }, |
| | | |
| | |
| | | } |
| | | }, |
| | | }; |
| | | </script> |
| | | </script> |