1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import { Component } from '@angular/core';
- import {IonItem,IonInput, IonCardTitle, IonAvatar, IonCardContent, IonIcon, IonButtons, IonFooter, IonButton, IonCard, IonHeader, IonToolbar, IonTitle, IonContent, IonCardHeader, IonLabel} from '@ionic/angular/standalone';
- import { ExploreContainerComponent } from '../explore-container/explore-container.component';
- import { CommonModule } from '@angular/common';
- @Component({
- selector: 'app-tab3',
- templateUrl: 'tab3.page.html',
- styleUrls: ['tab3.page.scss'],
- standalone: true,
- imports: [CommonModule,IonInput,IonItem,IonLabel,IonCardContent,IonHeader,IonAvatar,IonCardContent,IonCardHeader,IonCardTitle,IonFooter,IonButtons, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,IonHeader,IonCard,IonButton,IonIcon]
- })
- export class Tab3Page {
- height: number | null = null;
- weight: number | null = null;
- bmi: number | null = null;
- healthStatus: string = '';
- // 更新身高
- onHeightInput(event: any) {
- this.height = parseFloat(event.target.value);
- }
- // 更新体重
- onWeightInput(event: any) {
- this.weight = parseFloat(event.target.value);
- }
- // 计算BMI
- calculateBMI() {
- if (this.height !== null && this.weight !== null && this.height > 0 && this.weight > 0) {
- this.bmi = this.weight / ((this.height / 100) ** 2);
- if (this.bmi < 18.5) {
- this.healthStatus = '偏瘦';
- } else if (this.bmi >= 18.5 && this.bmi < 24.9) {
- this.healthStatus = '正常';
- } else if (this.bmi >= 25 && this.bmi < 29.9) {
- this.healthStatus = '偏重';
- } else {
- this.healthStatus = '超重';
- }
- } else {
- this.bmi = null;
- this.healthStatus = '请输入有效的身高和体重。';
- }
- }
- }
|