|
@@ -1,29 +1,30 @@
|
|
|
-import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
|
+import { Component, OnInit,CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
|
|
+import { Router } from '@angular/router';
|
|
|
+import { CloudSeUser } from 'src/lib/cloudSeuser'; // 引入 CloudSeUser 类
|
|
|
+import { FmodeChatCompletion } from 'fmode-ng'; // 引入 FmodeChatCompletion
|
|
|
import { addIcons } from 'ionicons';
|
|
|
import { albumsOutline, documentOutline, leafOutline, scanOutline, storefrontOutline } from 'ionicons/icons';
|
|
|
-import { IonButton, IonCard, IonCardContent, IonCardHeader, IonCol, IonContent, IonGrid, IonHeader, IonIcon, IonInput, IonRow, IonTextarea, IonTitle, IonToolbar } from '@ionic/angular/standalone';
|
|
|
-import { Router } from '@angular/router';
|
|
|
-import { CommonModule } from '@angular/common'; // 导入 CommonModule
|
|
|
-
|
|
|
+import { IonButton, IonCard, IonCardContent, IonCardHeader, IonCol, IonContent, IonHeader, IonIcon, IonInput, IonRow, IonTextarea, IonTitle, IonToolbar, IonGrid, IonCardTitle, IonSearchbar,} from '@ionic/angular/standalone'; // 导入 Ionic 组件
|
|
|
+import { CommonModule } from '@angular/common'; // 导入 CommonModule
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tab1',
|
|
|
templateUrl: 'tab1.page.html',
|
|
|
styleUrls: ['tab1.page.scss'],
|
|
|
- standalone: true, // 使用 standalone 组件
|
|
|
- imports: [
|
|
|
- CommonModule,IonContent, IonHeader, IonTitle, IonToolbar,
|
|
|
- IonButton,IonTextarea,IonInput,IonCard,IonCardContent,IonGrid,IonRow,IonCol,IonIcon,
|
|
|
- IonCardHeader,
|
|
|
- ], // 通过 IonicModule 导入所有 Ionic 组件
|
|
|
- schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
|
+ standalone: true, // 使用 standalone 组件
|
|
|
+ imports: [
|
|
|
+ CommonModule, IonContent, IonHeader, IonTitle, IonToolbar,
|
|
|
+ IonButton, IonTextarea, IonInput, IonCard, IonCardContent, IonGrid, IonRow, IonCol, IonIcon,
|
|
|
+ IonCardHeader,IonCardTitle,IonSearchbar
|
|
|
+ ],
|
|
|
})
|
|
|
-export class Tab1Page {
|
|
|
+export class Tab1Page implements OnInit {
|
|
|
+ private cloudSeUser: CloudSeUser; // 引入 CloudSeUser 实例
|
|
|
+
|
|
|
+ userInfo: any = null; // 用户信息
|
|
|
+ responseMsg: string = ""; // 用于存储 AI 生成的饮食建议
|
|
|
+ recipeMsg: string = ""; // 用于存储 AI 生成的推荐食谱
|
|
|
|
|
|
- constructor(private router: Router) {
|
|
|
- addIcons({scanOutline, documentOutline, storefrontOutline,albumsOutline,leafOutline});
|
|
|
- }
|
|
|
-
|
|
|
// 存储图片的数组
|
|
|
images = [
|
|
|
'https://example.com/image1.jpg',
|
|
@@ -35,6 +36,91 @@ export class Tab1Page {
|
|
|
// 当前显示的幻灯片索引
|
|
|
currentSlide: number = 0;
|
|
|
|
|
|
+ constructor(private router: Router) {
|
|
|
+ addIcons({ scanOutline, documentOutline, storefrontOutline, albumsOutline, leafOutline });
|
|
|
+ this.cloudSeUser = new CloudSeUser();
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit(): void {
|
|
|
+ this.loadUserData(); // 页面初始化时加载用户数据
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从 seUser 表加载当前用户数据
|
|
|
+ async loadUserData() {
|
|
|
+ try {
|
|
|
+ const userData = await this.cloudSeUser.getCurrentUserInfo();
|
|
|
+ if (userData) {
|
|
|
+ // 使用 get 方法逐个提取字段
|
|
|
+ this.userInfo = {
|
|
|
+ name: userData.get('name') || '',
|
|
|
+ email: userData.get('email') || '',
|
|
|
+ phone: userData.get('phone') || '',
|
|
|
+ age: userData.get('age') || null,
|
|
|
+ gender: userData.get('gender') || '',
|
|
|
+ height: userData.get('height') || null,
|
|
|
+ weight: userData.get('weight') || null,
|
|
|
+ activityLevel: userData.get('activityLevel') || '',
|
|
|
+ dietPreference: userData.get('dietPreference') || '',
|
|
|
+ dietGroup: userData.get('dietGroup') || '',
|
|
|
+ avatar: userData.get('avatar') || null,
|
|
|
+ allergies: userData.get('allergies') || '',
|
|
|
+ };
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载用户数据失败', error);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+ // 获取健康建议
|
|
|
+ async goHealthTips() {
|
|
|
+ if (!this.userInfo) return;
|
|
|
+
|
|
|
+ const { height, weight, activityLevel, dietPreference, dietGroup } = this.userInfo;
|
|
|
+ const newPrompt = `
|
|
|
+ 你是一名专业的饮食营养规划师。根据以下用户信息,请提供今日的饮食建议:
|
|
|
+ 身高:${height} cm
|
|
|
+ 体重:${weight} kg
|
|
|
+ 活动水平:${activityLevel}
|
|
|
+ 饮食偏好:${dietPreference}
|
|
|
+ 饮食类型:${dietGroup}
|
|
|
+ `;
|
|
|
+
|
|
|
+ const completion = new FmodeChatCompletion([
|
|
|
+ { role: "system", content: "" },
|
|
|
+ { role: "user", content: newPrompt }
|
|
|
+ ]);
|
|
|
+
|
|
|
+ completion.sendCompletion().subscribe((message: any) => {
|
|
|
+ console.log(message.content);
|
|
|
+ this.responseMsg = message.content; // 更新健康建议
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查看推荐食谱
|
|
|
+ async viewRecommendedRecipes() {
|
|
|
+ if (!this.userInfo) return;
|
|
|
+
|
|
|
+ const { height, weight, activityLevel, dietPreference, dietGroup } = this.userInfo;
|
|
|
+ const newPrompt = `
|
|
|
+ 你是一名专业的饮食营养规划师。根据以下用户信息,请推荐今日的食谱:
|
|
|
+ 身高:${height} cm
|
|
|
+ 体重:${weight} kg
|
|
|
+ 活动水平:${activityLevel}
|
|
|
+ 饮食偏好:${dietPreference}
|
|
|
+ 饮食类型:${dietGroup}
|
|
|
+ `;
|
|
|
+
|
|
|
+ const completion = new FmodeChatCompletion([
|
|
|
+ { role: "system", content: "" },
|
|
|
+ { role: "user", content: newPrompt }
|
|
|
+ ]);
|
|
|
+
|
|
|
+ completion.sendCompletion().subscribe((message: any) => {
|
|
|
+ console.log(message.content);
|
|
|
+ this.recipeMsg = message.content; // 更新推荐食谱
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
// 前一个幻灯片
|
|
|
prevSlide() {
|
|
|
if (this.currentSlide > 0) {
|
|
@@ -58,7 +144,8 @@ export class Tab1Page {
|
|
|
this.currentSlide = index;
|
|
|
}
|
|
|
|
|
|
- goHealthTips(){
|
|
|
- this.router.navigate([`/tabs/tips`])
|
|
|
+ // 跳转到饮食建议页面
|
|
|
+ goHealthTipsPage() {
|
|
|
+ this.router.navigate([`/tabs/tips`]);
|
|
|
}
|
|
|
}
|