AAA123 преди 3 месеца
родител
ревизия
3c9c8df4d5

+ 1 - 1
src/app/edit-profile/edit-profile.page.ts

@@ -29,7 +29,7 @@ export class EditProfilePage implements OnInit {
       phone: ['', [Validators.required, Validators.pattern('^[0-9]*$')]],
       gender: ['', [Validators.required]],
       birthday: ['', [Validators.required]],
-      userAvatar: ['../../assets/images/user-avatar.png', []] as [string | null, Validators[]] // 设置默认值并明确类型
+      userAvatar: ['../../assets/images/user.png', []] as [string | null, Validators[]] // 设置默认值并明确类型
     });
 
     // 预填充表单(如果有初始用户信息)

+ 7 - 4
src/app/tab1/tab1.page.html

@@ -6,11 +6,14 @@
       <ion-avatar (click)="openLoginModal()">
         <img [src]="userAvatar" alt="User Avatar" />
       </ion-avatar>
-      <ion-button fill="clear" (click)="openLoginModal()">
-        <ion-label>登录/注册</ion-label>
-      </ion-button>
+      <ng-container *ngIf="!isLoggedIn">
+        <!-- 如果用户未登录,显示登录/注册按钮 -->
+        <ion-button fill="clear" (click)="openLoginModal()">
+          <ion-label>登录/注册</ion-label>
+        </ion-button>
+      </ng-container>
     </ion-buttons>
-    <ion-title>
+    <ion-title >
       1分钟了解健康服务
     </ion-title>
     <ion-buttons slot="end">

+ 1 - 1
src/app/tab1/tab1.page.scss

@@ -22,7 +22,7 @@ ion-toolbar {
   }
   
   ion-title {
-    font-size: 18px;
+    font-size: 15px;
     font-weight: bold;
     flex: 1; /* 使标题居中 */
     text-align: center;

+ 10 - 0
src/app/tab1/tab1.page.ts

@@ -86,6 +86,7 @@ export class Tab1Page implements AfterViewInit {
   fileToUpload: File | null = null;
   private splashSubscription!: Subscription;
   isLoggedIn: boolean = false;
+  
  
 
   constructor(
@@ -110,6 +111,15 @@ export class Tab1Page implements AfterViewInit {
         await this.openLoginModal();
       }
     });
+    
+    this.userService.userInfo$.subscribe(userInfo => {
+      if (userInfo) {
+        this.isLoggedIn = true;
+        this.userAvatar = userInfo.userAvatar || this.userAvatar; // 更新头像
+      } else {
+        this.isLoggedIn = false;
+      }
+    });
   }
 
   ionViewWillEnter() {

+ 35 - 15
src/app/tab3/tab3.page.ts

@@ -3,6 +3,7 @@ import { NavController } from '@ionic/angular';
 import { UserService } from '../services/user.service';
 import { Subscription } from 'rxjs';
 
+
 @Component({
   selector: 'app-tab3',
   templateUrl: 'tab3.page.html',
@@ -11,7 +12,7 @@ import { Subscription } from 'rxjs';
 export class Tab3Page implements OnInit {
 
   username: string = '';
-  userAvatar: string | null = '../../assets/images/user.png'; // 允许 null
+  userAvatar: string | null = 'src/assets/images/user.png'; // 允许 null
   userType: string = '普通用户';
   previewImage: string | null = null;
   private userInfoSubscription?: Subscription;
@@ -41,31 +42,42 @@ export class Tab3Page implements OnInit {
   }
 
   private loadUserInfo() {
+    this.userAvatar = '/assets/images/user.png'; // 立即设置默认头像
+  
     // 取消之前的订阅(如果有)
     if (this.userInfoSubscription) {
       this.userInfoSubscription.unsubscribe();
     }
+  
     // 订阅最新的用户信息
     this.userInfoSubscription = this.userService.getUserInfo().subscribe(userInfo => {
-      if (userInfo) {
-        this.username = userInfo.username ?? this.username;
-        this.userAvatar = userInfo.userAvatar ?? null; // 确保预览图像是最新的头像或默认值
-        this.userType = userInfo.userType ?? '普通用户';
-        this.previewImage = userInfo.userAvatar ?? null; // 设置预览图像
-      } else {
-        this.userAvatar = '../../assets/images/user.png'; // 如果没有用户信息,使用默认头像
-        this.previewImage = null;
+      if (userInfo && userInfo.userAvatar) {
+        this.userAvatar = userInfo.userAvatar;
+        this.previewImage = userInfo.userAvatar;
       }
+      // 如果 userInfo 为 null 或 undefined,保持默认头像不变
     });
   }
 
   private checkStatuses() {
-    // 模拟检查各个功能区的状态
-    // 实际应用中应从服务器获取最新状态
-    this.hasUnreadHealthRecords = true;
-    this.hasPendingAppointments = true;
-    this.hasNewPromotions = true;
-    this.hasUnprocessedOrders = true;
+    // 尝试从 localStorage 加载状态
+  const savedStates = JSON.parse(localStorage.getItem('userStatuses') || '{}');
+
+  this.hasUnreadHealthRecords = savedStates.hasUnreadHealthRecords ?? false;
+  this.hasPendingAppointments = savedStates.hasPendingAppointments ?? false;
+  this.hasNewPromotions = savedStates.hasNewPromotions ?? false;
+  this.hasUnprocessedOrders = savedStates.hasUnprocessedOrders ?? false;
+  }
+
+  private saveStatuses() {
+    const userStatuses = {
+      hasUnreadHealthRecords: this.hasUnreadHealthRecords,
+      hasPendingAppointments: this.hasPendingAppointments,
+      hasNewPromotions: this.hasNewPromotions,
+      hasUnprocessedOrders: this.hasUnprocessedOrders
+    };
+  
+    localStorage.setItem('userStatuses', JSON.stringify(userStatuses));
   }
 
   editProfile() {
@@ -76,21 +88,29 @@ export class Tab3Page implements OnInit {
   viewHealthRecord() {
     console.log('查看/编辑健康档案');
     this.navCtrl.navigateForward('/health-record');
+    this.hasUnreadHealthRecords = false; // 标记为已读
+    this.saveStatuses(); // 保存状态
   }
 
   viewMedicalServices() {
     console.log('查看医疗服务');
     this.navCtrl.navigateForward('/medical-services');
+    this.hasPendingAppointments = false;
+    this.saveStatuses(); 
   }
 
   viewPointsAndCoupons() {
     console.log('查看积分与优惠');
     this.navCtrl.navigateForward('/points-and-coupons');
+    this.hasNewPromotions = false;
+    this.saveStatuses(); 
   }
 
   viewOrders() {
     console.log('查看订单管理');
     this.navCtrl.navigateForward('/orders');
+    this.hasUnprocessedOrders = false;
+    this.saveStatuses(); 
   }
 
   goToFaq() {

+ 4 - 4
src/environments/environment.prod.ts

@@ -1,4 +1,4 @@
-// export const environment = {
-//   production: true,
-//   apiUrl: 'https://your-production-api-url.com', // 生产环境下的API基础URL
-// };
+export const environment = {
+  production: true,
+  apiUrl: 'http://113.44.251.16:8080', // 生产环境下的API基础URL
+};

+ 0 - 1
src/environments/environment.ts

@@ -1,5 +1,4 @@
 
-
 export const environment = {
   production: false,
   apiUrl: 'http://113.44.251.16:8080'