|  | @@ -3,7 +3,7 @@ import { Component, OnInit } from '@angular/core';
 | 
	
		
			
				|  |  |  import { Router } from '@angular/router';
 | 
	
		
			
				|  |  |  import { IonCard, IonItem, IonLabel, IonList } from '@ionic/angular/standalone';
 | 
	
		
			
				|  |  |  import { IonButton, IonButtons, IonContent, IonHeader, IonTitle, IonToolbar, ModalController } from '@ionic/angular/standalone';
 | 
	
		
			
				|  |  | -import { CloudObject, CloudQuery } from 'src/lib/ncloud';
 | 
	
		
			
				|  |  | +import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // 定义 ContentItem 接口
 | 
	
		
			
				|  |  |  interface ContentItem {
 | 
	
	
		
			
				|  | @@ -31,26 +31,35 @@ export class ReportModalComponent  implements OnInit {
 | 
	
		
			
				|  |  |      this.router.navigate(['tabs/tab3']);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    chatrecordList:Array<CloudObject>=[]
 | 
	
		
			
				|  |  | -  async loadChatRecordList(){
 | 
	
		
			
				|  |  | +  async loadChatRecordList() {
 | 
	
		
			
				|  |  | +    // 获取当前用户的 ObjectId
 | 
	
		
			
				|  |  | +    const currentUser = new CloudUser();
 | 
	
		
			
				|  |  | +    await currentUser.current(); // 确保用户信息已加载
 | 
	
		
			
				|  |  | +    const userId = currentUser.id; // 获取当前用户的 ObjectId
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 创建查询并添加过滤条件
 | 
	
		
			
				|  |  |      let query = new CloudQuery("ChatRecord");
 | 
	
		
			
				|  |  | -    this.chatrecordList = await query.find()
 | 
	
		
			
				|  |  | +    query.equalTo("user", currentUser.toPointer()); // 过滤条件,确保只获取当前用户的记录
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    this.chatrecordList = await query.find();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      // 遍历 chatrecordList,去除每个记录中 user 的第一条 content
 | 
	
		
			
				|  |  |      this.chatrecordList.forEach(chatrecord => {
 | 
	
		
			
				|  |  | -      const contentArray = chatrecord.get('content');
 | 
	
		
			
				|  |  | -      if (contentArray && contentArray.length > 0) {
 | 
	
		
			
				|  |  | -        // 找到第一条 role 为 user 的内容并移除
 | 
	
		
			
				|  |  | -        const userIndex = contentArray.findIndex((item: ContentItem) => item.role === 'user');
 | 
	
		
			
				|  |  | -        if (userIndex !== -1) {
 | 
	
		
			
				|  |  | -          contentArray.splice(userIndex, 1); // 移除第一条 user 内容
 | 
	
		
			
				|  |  | +        const contentArray = chatrecord.get('content');
 | 
	
		
			
				|  |  | +        if (contentArray && contentArray.length > 0) {
 | 
	
		
			
				|  |  | +            // 找到第一条 role 为 user 的内容并移除
 | 
	
		
			
				|  |  | +            const userIndex = contentArray.findIndex((item: ContentItem) => item.role === 'user');
 | 
	
		
			
				|  |  | +            if (userIndex !== -1) {
 | 
	
		
			
				|  |  | +                contentArray.splice(userIndex, 1); // 移除第一条 user 内容
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -      }
 | 
	
		
			
				|  |  | -    })
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |    analyzeUserFeeling(content: string): { score: number; label: string } {
 | 
	
		
			
				|  |  |      const moodScores = {
 | 
	
		
			
				|  |  |        positive: {
 | 
	
		
			
				|  |  | -        words: ['开心', '高兴', '喜欢', '快乐', '棒', '兴奋', '满足', '美好'],
 | 
	
		
			
				|  |  | -        score: 2
 | 
	
		
			
				|  |  | +        words: ['开心', '高兴', '喜欢', '快乐', '棒', '兴奋', '满足', '美好','喜悦'],
 | 
	
		
			
				|  |  | +        score: 1
 | 
	
		
			
				|  |  |        },
 | 
	
		
			
				|  |  |        neutral: {
 | 
	
		
			
				|  |  |          words: ['一般', '还好', '可以', '无所谓', '正常'],
 | 
	
	
		
			
				|  | @@ -58,7 +67,7 @@ export class ReportModalComponent  implements OnInit {
 | 
	
		
			
				|  |  |        },
 | 
	
		
			
				|  |  |        negative: {
 | 
	
		
			
				|  |  |          words: ['难过', '生气', '失望', '讨厌', '悲伤', '烦恼', '痛苦', '沮丧'],
 | 
	
		
			
				|  |  | -        score: -2
 | 
	
		
			
				|  |  | +        score: -1
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      };
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -90,13 +99,13 @@ export class ReportModalComponent  implements OnInit {
 | 
	
		
			
				|  |  |      await this.loadChatRecordList();
 | 
	
		
			
				|  |  |      // 在这里可以遍历 chatrecordList 中的用户内容并进行情感分析
 | 
	
		
			
				|  |  |      this.chatrecordList.forEach(chatrecord => {
 | 
	
		
			
				|  |  | -      const contentArray = chatrecord.get('content');
 | 
	
		
			
				|  |  | -      contentArray.forEach((contentItem: ContentItem) => {
 | 
	
		
			
				|  |  | -        if (contentItem.role === 'user') {
 | 
	
		
			
				|  |  | -          const analysis = this.analyzeUserFeeling(contentItem.content);
 | 
	
		
			
				|  |  | -          this.userFeelings.push({ content: contentItem.content, score: analysis.score, label: analysis.label });
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -      });
 | 
	
		
			
				|  |  | +        const contentArray = chatrecord.get('content');
 | 
	
		
			
				|  |  | +        contentArray.forEach((contentItem: ContentItem) => {
 | 
	
		
			
				|  |  | +            if (contentItem.role === 'user') {
 | 
	
		
			
				|  |  | +                const analysis = this.analyzeUserFeeling(contentItem.content);
 | 
	
		
			
				|  |  | +                this.userFeelings.push({ content: contentItem.content, score: analysis.score, label: analysis.label });
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  } 
 | 
	
		
			
				|  |  |  }
 |