|
@@ -1,16 +1,66 @@
|
|
|
import { Component } from '@angular/core';
|
|
|
-import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
|
|
|
-import { ExploreContainerComponent } from '../explore-container/explore-container.component';
|
|
|
+import { IonicModule } from '@ionic/angular';
|
|
|
+import { FormsModule } from '@angular/forms'; // 导入 FormsModule
|
|
|
+import { CommonModule } from '@angular/common'; // 导入 CommonModule
|
|
|
+import { FmodeChatCompletion,MarkdownPreviewModule } from 'fmode-ng'; // 你的外部 API 相关导入
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tab2',
|
|
|
templateUrl: 'tab2.page.html',
|
|
|
styleUrls: ['tab2.page.scss'],
|
|
|
standalone: true,
|
|
|
- imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent]
|
|
|
+ imports: [
|
|
|
+ IonicModule,
|
|
|
+ FormsModule,
|
|
|
+ CommonModule,
|
|
|
+ MarkdownPreviewModule
|
|
|
+ ]
|
|
|
})
|
|
|
export class Tab2Page {
|
|
|
+ // 用户输入的变量
|
|
|
+ userWeight: number = 70; // 默认体重
|
|
|
+ userHeight: number = 175; // 默认身高
|
|
|
+ userPreference: string = "跑步"; // 默认运动偏好
|
|
|
+ userGoal: string = "减脂"; // 默认目标
|
|
|
|
|
|
+ // 用于显示生成的运动计划
|
|
|
+ responsePlan: string = "";
|
|
|
+isComplete:boolean = false;
|
|
|
constructor() {}
|
|
|
|
|
|
+ ngOnInit() {}
|
|
|
+
|
|
|
+ // 当用户输入信息后,点击按钮生成运动计划
|
|
|
+ generatePlan() {
|
|
|
+ // 打印输入的信息,便于调试
|
|
|
+ console.log("用户体重:", this.userWeight);
|
|
|
+ console.log("用户身高:", this.userHeight);
|
|
|
+ console.log("用户运动偏好:", this.userPreference);
|
|
|
+ console.log("用户目标:", this.userGoal);
|
|
|
+
|
|
|
+ // 创建一个包含用户输入的消息数组
|
|
|
+ let promptMessage = `根据以下信息,生成一个适合的运动计划:
|
|
|
+ 体重: ${this.userWeight}kg
|
|
|
+ 身高: ${this.userHeight}cm
|
|
|
+ 运动偏好: ${this.userPreference}
|
|
|
+ 目标: ${this.userGoal}`;
|
|
|
+
|
|
|
+ // 调用 AI 接口生成运动计划
|
|
|
+ let completion = new FmodeChatCompletion([
|
|
|
+ { role: "system", content: "你是一个运动专家,能够根据用户的体重、身高、运动偏好和目标,生成个性化的运动计划。" },
|
|
|
+ { role: "user", content: promptMessage }
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 发送请求并订阅生成的计划
|
|
|
+ completion.sendCompletion().subscribe((message: any) => {
|
|
|
+ // 打印生成的计划内容,便于调试
|
|
|
+ console.log("生成的运动计划:", message.content);
|
|
|
+
|
|
|
+ // 将生成的计划赋值给组件变量,用于展示
|
|
|
+ this.responsePlan = message.content;
|
|
|
+ if(message?.complete){
|
|
|
+ this.isComplete = true
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|