page-my-health.component.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { Component, OnInit } from '@angular/core';
  2. import {
  3. ModalController,
  4. IonModal,
  5. IonHeader,
  6. IonToolbar,
  7. IonTitle,
  8. IonContent,
  9. IonList,
  10. IonItem,
  11. IonLabel,
  12. IonAvatar,
  13. IonButton,
  14. IonSegment,
  15. IonSegmentButton,
  16. IonSegmentContent,
  17. IonSegmentView,
  18. IonCardContent,
  19. IonCardTitle,
  20. IonCardHeader,
  21. IonCard,
  22. IonIcon,
  23. IonButtons,
  24. IonInput,
  25. IonRefresherContent,
  26. IonRefresher,
  27. LoadingController,
  28. IonSpinner,
  29. IonGrid, // 导入 IonGrid
  30. IonRow, // 导入 IonRow
  31. IonCol // 导入 IonCol
  32. } from '@ionic/angular/standalone'; // 确保导入自 '@ionic/angular/standalone'
  33. import { addIcons } from 'ionicons';
  34. import { airplane, bluetooth, call, wifi, arrowBackOutline, menuOutline, personOutline, businessOutline, medicalOutline, documentTextOutline, folderOpenOutline } from 'ionicons/icons';
  35. import { CommonModule } from '@angular/common';
  36. import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
  37. // import { FmMarkdownPreview } from 'fmode-ng';
  38. import { Router } from '@angular/router';
  39. addIcons({ airplane, bluetooth, call, wifi });
  40. @Component({
  41. selector: 'page-my-health',
  42. templateUrl: './page-my-health.component.html',
  43. styleUrls: ['./page-my-health.component.scss'],
  44. standalone: true,
  45. imports: [
  46. IonHeader,
  47. IonToolbar,
  48. IonTitle,
  49. IonContent,
  50. IonLabel,
  51. IonItem,
  52. IonList,
  53. IonAvatar,
  54. CommonModule,
  55. IonButton,
  56. IonSegment,
  57. IonSegmentButton,
  58. IonSegmentContent,
  59. IonSegmentView,
  60. IonCardContent,
  61. IonCardTitle,
  62. IonCardHeader,
  63. IonCard,
  64. IonModal,
  65. IonIcon,
  66. IonButtons,
  67. IonInput,
  68. IonRefresher,
  69. IonRefresherContent,
  70. IonSpinner,
  71. IonGrid, // 添加 IonGrid 到 imports
  72. IonRow, // 添加 IonRow 到 imports
  73. IonCol // 添加 IonCol 到 imports
  74. // FmMarkdownPreview,
  75. ]
  76. })
  77. export class PageMyHealthComponent implements OnInit {
  78. allMessage: Array<CloudObject> = [];
  79. isLoading: boolean = false;
  80. errorMessage: string = "";
  81. avatar: string = "../assets/imgs/avatar.png"; // 默认头像
  82. currentUser: CloudUser | undefined;
  83. objectId: string = "";
  84. userName: string = "";
  85. back: string = "back";
  86. // 备用头像 URL
  87. fallbackAvatarUrl: string = 'https://app.fmode.cn/dev/jxnu/202226701019/头像示例.png';
  88. constructor(
  89. private router: Router,
  90. private loadingController: LoadingController
  91. ) {
  92. this.currentUser = new CloudUser();
  93. this.avatar = this.currentUser.data["avatar"] || this.fallbackAvatarUrl;
  94. this.objectId = this.currentUser.data['objectId'];
  95. this.userName = this.currentUser.data["realname"] || "用户";
  96. }
  97. ngOnInit() {
  98. this.loadData();
  99. }
  100. async loadData() {
  101. this.isLoading = true;
  102. const loading = await this.loadingController.create({
  103. message: '加载中...',
  104. });
  105. await loading.present();
  106. try {
  107. let user = new CloudUser();
  108. console.log("objectId", this.objectId);
  109. let query = new CloudQuery('Consultation');
  110. query.include("doctor", "depart");
  111. query.equalTo("user", { "__type": "Pointer", "className": "_User", "objectId": this.objectId });
  112. const messages = await query.find();
  113. console.log("allMessage", messages);
  114. this.allMessage = messages;
  115. } catch (error) {
  116. console.error("加载数据失败:", error);
  117. this.errorMessage = "数据加载失败,请稍后再试。";
  118. } finally {
  119. this.isLoading = false;
  120. await loading.dismiss();
  121. }
  122. }
  123. handleRefresh(event: any) {
  124. setTimeout(() => {
  125. this.allMessage = [];
  126. this.loadData().then(() => {
  127. event.target.complete();
  128. });
  129. }, 2000);
  130. }
  131. backHome() {
  132. this.router.navigate(['/tabs/tab1']);
  133. }
  134. gotouser() {
  135. // 用户相关逻辑
  136. }
  137. // 处理图片加载错误,设置备用图片
  138. handleImageError() {
  139. this.avatar = this.fallbackAvatarUrl;
  140. }
  141. }