647556386
2025-08-10 75e3bca44b111c167b9389e4e51b2ce577a9f9e0
¼ª°²PDA/pages/home/home.vue
@@ -7,42 +7,24 @@
         <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>
@@ -225,35 +207,73 @@
</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 == "") {
@@ -263,11 +283,19 @@
            }
         },
         // é€€å‡ºç™»å½•
         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');
         },
@@ -279,4 +307,4 @@
         }
      },
   };
</script>
</script>