Forráskód Böngészése

update:page 3 and report

cainiao-hue 4 hónapja
szülő
commit
c02c3d235c

+ 3 - 4
docs-prod/schema.md

@@ -13,7 +13,6 @@ class _User {
     + age: Number //年龄
     + email: String //用户邮箱
     + avatar: String //用户头像
-    + bio: String //用户个人简介
     + startChat(): void 
     + chooseChatPartner(): String
     + summarizeChatHistory(): void
@@ -45,9 +44,9 @@ class ChatRecord {
     + getChatHistory(): List
 }
 
-class Report {
+class ChatReport {
     + objectId: String //报告唯一标识符
-    - analysisResult: String //分析结果
+    - report: String //分析结果
     + generateReport(): String //生成报告的方法
 }
 class ChatEvaluate{
@@ -62,7 +61,7 @@ _User "*" --> "*" ChatEvaluate
 _User "1" --> "*" ChatRecord     
 ChatPartner "1" --> "*" ChatRecord 
 ChatCompanion "1" --> "*" ChatRecord 
-ChatRecord "1" -- "1" Report      
+ChatRecord "1" --> "1" ChatReport      
 @enduml
 ```
 # 时序图

+ 5 - 1
soul-app/src/app/report-modal/report-modal.component.scss

@@ -5,4 +5,8 @@ ion-content {
   pre {
     white-space: pre-wrap; // 允许换行
     word-wrap: break-word; // 处理长单词
-  }
+  }
+  ion-header {
+    background-color: #f8f9fa;
+  }
+  

+ 41 - 2
soul-app/src/app/report-modal/report-modal.component.ts

@@ -12,12 +12,51 @@ import { IonButton, IonButtons, IonContent, IonHeader, IonTitle, IonToolbar, Mod
 })
 export class ReportModalComponent  implements OnInit {
 
-  @Input() report!: string; // 从父组件接收报告内容
+  @Input() report: string=''; // 接收报告内容
+  @Input() consult: any; // 接收 Consult 对象
 
   constructor(private modalCtrl: ModalController) {}
 
+  async generateReport() {
+    if (!this.consult) {
+      console.error('Consult对象未定义');
+      return;
+    }
+    let chatContent = this.consult.get('content') || [];
+    let report = "聊天记录报告\n\n";
+    
+    if (chatContent.length === 0) {
+      report += "没有聊天记录。\n\n";
+    } else {
+      chatContent.forEach((message: any, index: number) => {
+        report += `消息 ${index + 1}:\n\n`;
+        report += `内容: ${message.content}\n\n`;
+        
+        const sentiment = this.analyzeSentiment(message.content);
+        report += `心晴分析: ${sentiment}\n\n`;
+      });
+    }
+    
+    this.report = report; // 更新报告内容
+  }
+
+  analyzeSentiment(text: string): string {
+    if (text.includes("好") || text.includes("喜欢")) {
+      return "积极";
+    } else if (text.includes("坏") || text.includes("不喜欢")) {
+      return "消极";
+    } else {
+      return "中性";
+    }
+  }
+
   closeModal() {
-    this.modalCtrl.dismiss(); // 关闭弹窗
+    //this.modalCtrl.dismiss(); // 关闭模态框
+    this.modalCtrl.dismiss({ report: this.report }); // 关闭模态框并返回报告内容
+  }
+
+  ionViewWillEnter() {
+    this.generateReport(); // 页面进入时生成报告
   }
 
   ngOnInit() {}

+ 47 - 49
soul-app/src/app/tab2/tab2.page.ts

@@ -85,7 +85,7 @@ export class Tab2Page {
     // 弹窗形式聊天:开始聊天
     localStorage.setItem("company", "E4KpGvTEto");
     // 创建聊天记录对象
-    this.consult = new CloudObject("ChatRecord");
+    let consult = new CloudObject("ChatRecord");
     // 设置聊天记录的基本信息
     let now = new Date();
     let dateStr = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`;
@@ -124,14 +124,11 @@ export class Tab2Page {
             console.log("onMessage", message);
             let content: any = message?.content;
             // 更新 consult 对象的内容
-            this.consult.set({
+            consult.set({
                 content: chat.messageList, // 直接存储数组
             });
             // 仅在内容发生变化时保存
-            this.consult.save().then(() => {
-                // 生成聊天记录报告
-                this.generateReport(); // 确保此处 consult 已定义
-            });
+            consult.save();
         },
         onChatSaved: (chat: FmodeChat) => {
             console.log("onChatSaved", chat, chat?.chatSession, chat?.chatSession?.id);
@@ -140,50 +137,51 @@ export class Tab2Page {
     openChatPanelModal(this.modalCtrl, options);
 }
 
-async generateReport() {
-  if (!this.consult) {
-    console.error('Consult对象未定义');
-    return;
-  }
-  let chatContent = this.consult.get('content') || [];
-  // 检查 chatContent 是否有效
-  let report = "聊天记录报告\n\n";
-  if (chatContent.length === 0) {
-      report += "没有聊天记录。\n\n";
-  } else {
-      chatContent.forEach((message: any, index: number) => {
-          report += `消息 ${index + 1}:\n\n`;
-          report += `内容: ${message.content}\n\n`;
+// async generateReport() {
+//   if (!this.consult) {
+//     console.error('Consult对象未定义');
+//     return;
+//   }
+//   let chatContent = this.consult.get('content') || [];
+//   // 检查 chatContent 是否有效
+//   let report = "聊天记录报告\n\n";
+//   if (chatContent.length === 0) {
+//       report += "没有聊天记录。\n\n";
+//   } else {
+//       chatContent.forEach((message: any, index: number) => {
+//           report += `消息 ${index + 1}:\n\n`;
+//           report += `内容: ${message.content}\n\n`;
           
-          // 假设有一个情感分析函数 analyzeSentiment
-          const sentiment = this.analyzeSentiment(message.content);
-          report += `心晴分析: ${sentiment}\n\n`;
-      });
-  }
-  // 显示报告
-  await this.showReportModal(report);
-  }
-  analyzeSentiment(text:String) {
-    // 这里可以使用简单的关键词匹配或更复杂的模型来分析情感
-    if (text.includes("好") || text.includes("喜欢")) {
-        return "积极";
-    } else if (text.includes("坏") || text.includes("不喜欢")) {
-        return "消极";
-    } else {
-        return "中性";
-    }
-  }
-  extractKeywords(text:String): string[] {
-    // 这里可以实现简单的关键词提取逻辑
-    return text.split(/\s+/).filter(word => word.length > 0); // 示例:提取长度大于0的单词
-  }
-  async showReportModal(report: string) {
-    const modal = await this.modalCtrl.create({
-      component: ReportModalComponent, // 你需要创建这个组件来显示报告
-      componentProps: { report }
-    });
-    return await modal.present();
-  }
+//           // 假设有一个情感分析函数 analyzeSentiment
+//           const sentiment = this.analyzeSentiment(message.content);
+//           report += `心晴分析: ${sentiment}\n\n`;
+//       });
+//   }
+//   // 显示报告
+//   await this.showReportModal(report);
+//   }
+//   analyzeSentiment(text:String) {
+//     // 这里可以使用简单的关键词匹配或更复杂的模型来分析情感
+//     if (text.includes("好") || text.includes("喜欢")) {
+//         return "积极";
+//     } else if (text.includes("坏") || text.includes("不喜欢")) {
+//         return "消极";
+//     } else {
+//         return "中性";
+//     }
+//   }
+//   extractKeywords(text:String): string[] {
+//     // 这里可以实现简单的关键词提取逻辑
+//     return text.split(/\s+/).filter(word => word.length > 0); // 示例:提取长度大于0的单词
+//   }
+//   async showReportModal(report: string) {
+//     const modal = await this.modalCtrl.create({
+//       component: ReportModalComponent, // 你需要创建这个组件来显示报告
+//       componentProps: { report }
+//     });
+//     return await modal.present();
+//   }
+
   questions = [
     {
       title: '如何应对焦虑?',

+ 7 - 0
soul-app/src/app/tab3/tab3.page.html

@@ -62,6 +62,13 @@
       <ion-icon name="chevron-forward-outline" slot="end"></ion-icon>
     </ion-item>
 
+    <!-- 我的报告 -->
+    <ion-item (click)="openReportModal()">
+      <ion-icon name="heart-outline" slot="start"></ion-icon>
+      <ion-label>我的报告</ion-label>
+      <ion-icon name="chevron-forward-outline" slot="end"></ion-icon>
+    </ion-item>
+
     <!-- 消息通知 -->
     <ion-item>
       <ion-icon name="notifications-outline" slot="start"></ion-icon>

+ 33 - 0
soul-app/src/app/tab3/tab3.page.ts

@@ -8,6 +8,7 @@ import { ModalController } from '@ionic/angular/standalone';
 import { openUserEditModal } from 'src/lib/user/modal-user-edit/modal-user-edit.component';
 import { openInfoModal } from '../info-modal/info-modal.component';
 import { openIdentityVerificationModal } from 'src/lib/user/modal-identity-verification/modal-identity-verification.component';
+import { ReportModalComponent } from '../report-modal/report-modal.component';
 
 @Component({
   selector: 'app-tab3',
@@ -52,4 +53,36 @@ export class Tab3Page {
   identityVerificationModal(){
     openIdentityVerificationModal(this.modalCtrl)
   }
+
+  async openReportModal() {
+    const modal = await this.modalCtrl.create({
+      component: ReportModalComponent,
+      componentProps: {
+        consult: this.getConsultData() // 传递 Consult 对象
+      }
+    });
+    
+    await modal.present();
+    const { data } = await modal.onWillDismiss();
+    if (data) {
+      console.log('生成的报告:', data.report);
+    }
+  }
+
+  getConsultData() {
+    // 这里返回 Consult 对象的逻辑
+    return {
+      get: (key: string) => {
+        // 模拟返回聊天记录
+        if (key === 'content') {
+          return [
+            { content: '我喜欢这项服务!' },
+            { content: '这真是太棒了!' },
+            { content: '我不喜欢这个选项。' }
+          ];
+        }
+        return null;
+      }
+    };
+  }
 }