Browse Source

fix:tab5&user-login Login is synchronized with personal information

csdn1233 3 months ago
parent
commit
c784acb420

+ 9 - 8
AIart-app/src/app/tab5/tab5.page.html

@@ -23,11 +23,12 @@
     <div class="profile-header">
       <div class="profile-info">
         <div class="avatar-container">
-          <img src="assets/img/logo.png" alt="头像" class="avatar">
+          <img [src]="currentUser?.get('avatar') || 'assets/img/logo.png'" alt="头像" class="avatar">
         </div>
         <div class="user-info">
-          <h2>游客用户</h2>
-          <p>15 关注 · 3 关注</p>
+          <h2>{{ currentUser?.get('username') || '游客用户' }}</h2>
+          <p>{{ currentUser ? (currentUser.get('followers') || 0) + ' 关注 · ' + (currentUser.get('following') || 0) + '
+            关注' : '15 关注 · 3 关注' }}</p>
         </div>
       </div>
       <ion-button fill="clear" class="profile-action" (click)="goUserLogin()">
@@ -37,19 +38,19 @@
 
     <div class="stats-container">
       <div class="stat-item">
-        <h3>300</h3>
+        <h3>{{ currentUser?.get('credits') || 300 }}</h3>
         <p>学分</p>
       </div>
       <div class="stat-item">
-        <h3>15<span>分钟</span></h3>
+        <h3>{{ currentUser?.get('studyTime') || 15 }}<span>分钟</span></h3>
         <p>今日学习</p>
       </div>
       <div class="stat-item">
-        <h3>2</h3>
+        <h3>{{ currentUser?.get('medals') || 2 }}</h3>
         <p>勋章</p>
       </div>
       <div class="stat-item">
-        <h3>0</h3>
+        <h3>{{ currentUser?.get('certificates') || 0 }}</h3>
         <p>证书</p>
       </div>
     </div>
@@ -139,7 +140,7 @@
       <div class="feature-item">
         <ion-icon name="document-text-outline"></ion-icon>
         <div class="text-container">
-          <p>笔</p>
+          <p>笔���</p>
         </div>
       </div>
       <div class="feature-item">

+ 24 - 3
AIart-app/src/app/tab5/tab5.page.ts

@@ -1,6 +1,7 @@
-import { Component } from '@angular/core';
+import { Component, OnInit } from '@angular/core';
 import { IonHeader, IonToolbar, IonTitle, IonContent, IonSearchbar, IonIcon, IonButton } from '@ionic/angular/standalone';
 import { Router } from '@angular/router';
+import { CloudUser } from 'src/lib/ncloud';
 
 @Component({
   selector: 'app-tab5',
@@ -17,10 +18,30 @@ import { Router } from '@angular/router';
     IonButton
   ],
 })
-export class tab5Page {
+export class tab5Page implements OnInit {
+  currentUser: CloudUser | undefined;
+
   constructor(private router: Router) { }
 
+  ngOnInit() {
+    this.checkUserStatus();
+  }
+
+  ionViewWillEnter() {
+    // 每次进入页面时检查用户状态
+    this.checkUserStatus();
+  }
+
+  async checkUserStatus() {
+    const user = new CloudUser();
+    if (user.id) {
+      this.currentUser = user;
+    } else {
+      this.currentUser = undefined;
+    }
+  }
+
   goUserLogin() {
-    this.router.navigate(['/tabs/user-login'])
+    this.router.navigate(['/tabs/user-login']);
   }
 }

+ 5 - 9
AIart-app/src/app/user-login/user-login.component.ts

@@ -25,28 +25,25 @@ export class UserLoginComponent implements OnInit {
     this.currentUser = new CloudUser();
   }
   async login() {
-    // 弹出登录窗口
     let user = await openUserLoginModal(this.modalCtrl);
     if (user?.id) {
-      this.currentUser = user
+      this.currentUser = user;
+      this.router.navigate(['/tabs/tab5']);
     }
   }
   async signup() {
-    // 弹出注册窗口
     let user = await openUserLoginModal(this.modalCtrl, "signup");
     if (user?.id) {
-      this.currentUser = user
+      this.currentUser = user;
+      this.router.navigate(['/tabs/tab5']);
     }
   }
   async logout() {
     try {
       let user = new CloudUser();
       await user.logout();
-
-      // 刷新页面状态
       this.currentUser = undefined;
 
-      // 显示成功提示
       const toast = document.createElement('ion-toast');
       toast.message = '退出登录成功';
       toast.duration = 2000;
@@ -55,8 +52,7 @@ export class UserLoginComponent implements OnInit {
       document.body.appendChild(toast);
       await toast.present();
 
-      // 重定向到首页
-      this.router.navigate(['/tabs/tab1']);
+      this.router.navigate(['/tabs/tab5']);
     } catch (error) {
       console.error('Logout error:', error);
       const toast = document.createElement('ion-toast');