tab3.page.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { Component } from '@angular/core';
  2. import {IonItem,IonInput, IonCardTitle, IonAvatar, IonCardContent, IonIcon, IonButtons, IonFooter, IonButton, IonCard, IonHeader, IonToolbar, IonTitle, IonContent, IonCardHeader, IonLabel} from '@ionic/angular/standalone';
  3. import { ExploreContainerComponent } from '../explore-container/explore-container.component';
  4. import { CommonModule } from '@angular/common';
  5. @Component({
  6. selector: 'app-tab3',
  7. templateUrl: 'tab3.page.html',
  8. styleUrls: ['tab3.page.scss'],
  9. standalone: true,
  10. imports: [CommonModule,IonInput,IonItem,IonLabel,IonCardContent,IonHeader,IonAvatar,IonCardContent,IonCardHeader,IonCardTitle,IonFooter,IonButtons, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,IonHeader,IonCard,IonButton,IonIcon]
  11. })
  12. export class Tab3Page {
  13. height: number | null = null;
  14. weight: number | null = null;
  15. bmi: number | null = null;
  16. healthStatus: string = '';
  17. // 更新身高
  18. onHeightInput(event: any) {
  19. this.height = parseFloat(event.target.value);
  20. }
  21. // 更新体重
  22. onWeightInput(event: any) {
  23. this.weight = parseFloat(event.target.value);
  24. }
  25. // 计算BMI
  26. calculateBMI() {
  27. if (this.height !== null && this.weight !== null && this.height > 0 && this.weight > 0) {
  28. this.bmi = this.weight / ((this.height / 100) ** 2);
  29. if (this.bmi < 18.5) {
  30. this.healthStatus = '偏瘦';
  31. } else if (this.bmi >= 18.5 && this.bmi < 24.9) {
  32. this.healthStatus = '正常';
  33. } else if (this.bmi >= 25 && this.bmi < 29.9) {
  34. this.healthStatus = '偏重';
  35. } else {
  36. this.healthStatus = '超重';
  37. }
  38. } else {
  39. this.bmi = null;
  40. this.healthStatus = '请输入有效的身高和体重。';
  41. }
  42. }
  43. }