|
@@ -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: '如何应对焦虑?',
|