202226701046 7 months ago
parent
commit
3ee1c3765c

+ 2 - 1
smarteat-app/src/app/image-popup/image1-popup/image1-popup.component.ts

@@ -1,7 +1,8 @@
 import { HttpClient } from '@angular/common/http';
 import { Component, Input } from '@angular/core';
 import { IonButton, IonButtons, IonContent, IonHeader, IonIcon, IonTitle, IonToolbar, ModalController } from '@ionic/angular/standalone';
-import mammoth from 'mammoth';  // 引入 mammoth 库
+import * as mammoth from 'mammoth';
+
 @Component({
   selector: 'app-image1-popup',
   templateUrl: './image1-popup.component.html',

+ 3 - 3
smarteat-app/src/app/tab1/tab1.page.html

@@ -75,14 +75,14 @@
     <ion-card-header>
       <ion-card-title>
         <ion-icon slot="start" name="albums-outline"></ion-icon>
-        今日推荐食谱
+        今日推荐食谱:
+        <div [innerHTML]="dishName"></div>
       </ion-card-title>
     </ion-card-header>
     <ion-card-content>
-      <ion-button (click)="viewRecommendedRecipes()">
+      <ion-button >
         查看推荐食谱
       </ion-button>
-      <p>{{ recipeMsg }}</p> <!-- 显示 AI 生成的推荐食谱 -->
     </ion-card-content>
   </ion-card>
 </ion-content>

+ 3 - 26
smarteat-app/src/app/tab1/tab1.page.ts

@@ -32,6 +32,8 @@ export class Tab1Page implements OnInit {
   userInfo: any = null; // 用户信息
   responseMsg: string = ""; // 用于存储 AI 生成的饮食建议
   recipeMsg: string = ""; // 用于存储 AI 生成的推荐食谱
+  dishName:string="";//用于存储菜品名
+  dishPhoto:string="";
 
   // 存储图片的数组
   images = [
@@ -117,30 +119,6 @@ export class Tab1Page implements OnInit {
     });
   }
 
-  // 查看推荐食谱
-  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; // 更新推荐食谱
-    });
-  }
 
   // 打开弹窗
   async openImagePopup(imageUrl: string, description: string) {
@@ -215,5 +193,4 @@ export class Tab1Page implements OnInit {
         await this.loadUserData();// 登录后加载用户信息
       }
     }
-  }
-  
+  }

+ 133 - 0
smarteat-app/src/lib/cloudshipu.ts

@@ -0,0 +1,133 @@
+import { CloudObject } from "./ncloud";
+
+export class CloudShipu extends CloudObject {
+    constructor() {
+        super("seshipu"); // 假设 seshipu 类在 Parse 中是 "seshipu"
+    }
+
+    /** 获取所有 `seshipu` 信息 */
+    async getAllShipu() {
+        const url = "http://dev.fmode.cn:1337/parse/classes/seshipu";
+
+        const response = await fetch(url, {
+            headers: {
+                "accept": "*/*",
+                "accept-language": "zh-CN,zh;q=0.9",
+                "x-parse-application-id": "dev"
+            },
+            method: "GET",
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const result = await response?.json();
+        if (result?.error) {
+            console.error(result?.error);
+            return null;
+        }
+
+        return result.results.map((item: any) => this.dataToObj(item)); // 假设返回的数据在 `results` 字段中
+    }
+
+    /** 获取单个 `seshipu` 信息 */
+    async getShipu(id: string) {
+        const url = `http://dev.fmode.cn:1337/parse/classes/seshipu/${id}?`;
+
+        const response = await fetch(url, {
+            headers: {
+                "x-parse-application-id": "dev"
+            },
+            method: "GET",
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const result = await response?.json();
+        if (result?.error) {
+            console.error(result?.error);
+            return null;
+        }
+
+        return this.dataToObj(result);
+    }
+
+    /** 创建 `seshipu` 信息 */
+    async saveShipuInfo(shipuData: Record<string, any>) {
+        const url = `http://dev.fmode.cn:1337/parse/classes/seshipu`;
+
+        const response = await fetch(url, {
+            headers: {
+                "Content-Type": "application/json",
+                "x-parse-application-id": "dev"
+            },
+            method: "POST",
+            body: JSON.stringify(shipuData),
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const result = await response?.json();
+        if (result?.error) {
+            console.error(result?.error);
+            return null;
+        }
+
+        return this.dataToObj(result);
+    }
+
+    /** 更新 `seshipu` 信息 */
+    async updateShipuInfo(id: string, updatedData: Record<string, any>) {
+        const url = `http://dev.fmode.cn:1337/parse/classes/seshipu/${id}`;
+
+        const response = await fetch(url, {
+            headers: {
+                "Content-Type": "application/json",
+                "x-parse-application-id": "dev"
+            },
+            method: "PUT",
+            body: JSON.stringify(updatedData),
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const result = await response?.json();
+        if (result?.error) {
+            console.error(result?.error);
+            return null;
+        }
+
+        return this.dataToObj(result);
+    }
+
+    /** 删除 `seshipu` 信息 */
+    async deleteShipuInfo(id: string) {
+        const url = `http://dev.fmode.cn:1337/parse/classes/seshipu/${id}`;
+
+        const response = await fetch(url, {
+            headers: {
+                "x-parse-application-id": "dev"
+            },
+            method: "DELETE",
+            mode: "cors",
+            credentials: "omit"
+        });
+
+        const result = await response?.json();
+        if (result?.error) {
+            console.error(result?.error);
+            return false;
+        }
+
+        return true;
+    }
+
+    /** 将查询结果转换为 CloudObject */
+    private dataToObj(result: any): CloudObject {
+        let shipuObject = new CloudObject(this.className);
+        shipuObject.set(result);
+        shipuObject.id = result.objectId;
+        shipuObject.createdAt = result.createdAt;
+        shipuObject.updatedAt = result.updatedAt;
+        return shipuObject;
+    }
+}

+ 63 - 0
smarteat-app/src/lib/import-data.js

@@ -72,4 +72,67 @@ fetch("http://dev.fmode.cn:1337/parse/classes/seUser?", {
     "method": "DELETE",
     "mode": "cors",
     "credentials": "omit"
+  });
+
+
+
+
+  fetch("http://dev.fmode.cn:1337/parse/classes/seshipu?", {
+    "headers": {
+      "accept": "*/*",
+      "accept-language": "zh-CN,zh;q=0.9",
+      "x-parse-application-id": "dev"
+    },
+    "referrer": "http://127.0.0.1:4040/",
+    "referrerPolicy": "strict-origin-when-cross-origin",
+    "body": null,
+    "method": "GET",
+    "mode": "cors",
+    "credentials": "omit"
+  });
+
+  fetch("http://dev.fmode.cn:1337/parse/classes/seshipu", {
+    "headers": {
+      "accept": "*/*",
+      "accept-language": "zh-CN,zh;q=0.9",
+      "content-type": "text/plain;charset=UTF-8",
+      "x-parse-application-id": "dev"
+    },
+    "referrer": "http://127.0.0.1:4040/",
+    "referrerPolicy": "strict-origin-when-cross-origin",
+    "body": "",
+    "method": "POST",
+    "mode": "cors",
+    "credentials": "omit"
+  });
+
+
+  fetch("http://dev.fmode.cn:1337/parse/classes/seshipu", {
+    "headers": {
+      "accept": "*/*",
+      "accept-language": "zh-CN,zh;q=0.9",
+      "content-type": "text/plain;charset=UTF-8",
+      "x-parse-application-id": "dev"
+    },
+    "referrer": "http://127.0.0.1:4040/",
+    "referrerPolicy": "strict-origin-when-cross-origin",
+    "body": "",
+    "method": "PUT",
+    "mode": "cors",
+    "credentials": "omit"
+  });
+
+
+  fetch("http://dev.fmode.cn:1337/parse/classes/seshipu", {
+    "headers": {
+      "accept": "*/*",
+      "accept-language": "zh-CN,zh;q=0.9",
+      "x-parse-application-id": "dev"
+    },
+    "referrer": "http://127.0.0.1:4040/",
+    "referrerPolicy": "strict-origin-when-cross-origin",
+    "body": null,
+    "method": "DELETE",
+    "mode": "cors",
+    "credentials": "omit"
   });