123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import { Component, OnInit } from '@angular/core';
- import {
- ModalController,
- IonModal,
- IonHeader,
- IonToolbar,
- IonTitle,
- IonContent,
- IonList,
- IonItem,
- IonLabel,
- IonAvatar,
- IonButton,
- IonSegment,
- IonSegmentButton,
- IonSegmentContent,
- IonSegmentView,
- IonCardContent,
- IonCardTitle,
- IonCardHeader,
- IonCard,
- IonIcon,
- IonButtons,
- IonInput,
- IonRefresherContent,
- IonRefresher,
- LoadingController,
- IonSpinner,
- IonGrid, // 导入 IonGrid
- IonRow, // 导入 IonRow
- IonCol // 导入 IonCol
- } from '@ionic/angular/standalone'; // 确保导入自 '@ionic/angular/standalone'
- import { addIcons } from 'ionicons';
- import { airplane, bluetooth, call, wifi, arrowBackOutline, menuOutline, personOutline, businessOutline, medicalOutline, documentTextOutline, folderOpenOutline } from 'ionicons/icons';
- import { CommonModule } from '@angular/common';
- import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
- // import { FmMarkdownPreview } from 'fmode-ng';
- import { Router } from '@angular/router';
- addIcons({ airplane, bluetooth, call, wifi });
- @Component({
- selector: 'page-my-health',
- templateUrl: './page-my-health.component.html',
- styleUrls: ['./page-my-health.component.scss'],
- standalone: true,
- imports: [
- IonHeader,
- IonToolbar,
- IonTitle,
- IonContent,
- IonLabel,
- IonItem,
- IonList,
- IonAvatar,
- CommonModule,
- IonButton,
- IonSegment,
- IonSegmentButton,
- IonSegmentContent,
- IonSegmentView,
- IonCardContent,
- IonCardTitle,
- IonCardHeader,
- IonCard,
- IonModal,
- IonIcon,
- IonButtons,
- IonInput,
- IonRefresher,
- IonRefresherContent,
- IonSpinner,
- IonGrid, // 添加 IonGrid 到 imports
- IonRow, // 添加 IonRow 到 imports
- IonCol // 添加 IonCol 到 imports
- // FmMarkdownPreview,
- ]
- })
- export class PageMyHealthComponent implements OnInit {
- allMessage: Array<CloudObject> = [];
- isLoading: boolean = false;
- errorMessage: string = "";
- avatar: string = "../assets/imgs/avatar.png"; // 默认头像
- currentUser: CloudUser | undefined;
- objectId: string = "";
- userName: string = "";
- back: string = "back";
- // 备用头像 URL
- fallbackAvatarUrl: string = 'https://app.fmode.cn/dev/jxnu/202226701019/头像示例.png';
- constructor(
- private router: Router,
- private loadingController: LoadingController
- ) {
- this.currentUser = new CloudUser();
- this.avatar = this.currentUser.data["avatar"] || this.fallbackAvatarUrl;
- this.objectId = this.currentUser.data['objectId'];
- this.userName = this.currentUser.data["realname"] || "用户";
- }
- ngOnInit() {
- this.loadData();
- }
- async loadData() {
- this.isLoading = true;
- const loading = await this.loadingController.create({
- message: '加载中...',
- });
- await loading.present();
- try {
- let user = new CloudUser();
- console.log("objectId", this.objectId);
- let query = new CloudQuery('Consultation');
- query.include("doctor", "depart");
- query.equalTo("user", { "__type": "Pointer", "className": "_User", "objectId": this.objectId });
- const messages = await query.find();
- console.log("allMessage", messages);
- this.allMessage = messages;
- } catch (error) {
- console.error("加载数据失败:", error);
- this.errorMessage = "数据加载失败,请稍后再试。";
- } finally {
- this.isLoading = false;
- await loading.dismiss();
- }
- }
- handleRefresh(event: any) {
- setTimeout(() => {
- this.allMessage = [];
- this.loadData().then(() => {
- event.target.complete();
- });
- }, 2000);
- }
- backHome() {
- this.router.navigate(['/tabs/tab1']);
- }
- gotouser() {
- // 用户相关逻辑
- }
- // 处理图片加载错误,设置备用图片
- handleImageError() {
- this.avatar = this.fallbackAvatarUrl;
- }
- }
|