12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { CommonModule } from '@angular/common';
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- import { IonButton, IonButtons, IonCard, IonCardContent, IonCardHeader, IonCardTitle, IonContent, IonFooter, IonHeader, IonIcon, IonInput, IonItem, IonLabel, IonList, IonTitle, IonToolbar, NavController } from '@ionic/angular/standalone';
- import { addIcons } from 'ionicons';
- import { chevronBackSharp, closeCircleOutline, ellipsisHorizontal, happyOutline, micCircleOutline, paperPlane, sendOutline } from 'ionicons/icons';
- import { CloudQuery, CloudUser } from 'src/lib/ncloud';
- addIcons({ chevronBackSharp,ellipsisHorizontal,micCircleOutline,happyOutline,paperPlane,closeCircleOutline,sendOutline });
- @Component({
- selector: 'app-chat-history',
- templateUrl: './chat-history.component.html',
- styleUrls: ['./chat-history.component.scss'],
- standalone: true,
- imports: [IonHeader,IonToolbar,IonTitle,IonContent,IonList,IonItem,IonLabel,CommonModule,IonCard,IonCardHeader,IonCardTitle,
- IonButton,IonCardContent,IonIcon,IonButtons,IonInput,IonFooter,IonInput,CommonModule],
- })
- export class ChatHistoryComponent implements OnInit {
- chatHistories: any[] = []; // 存储聊天记录
- selectedChat: any; // 存储当前选择的聊天记录,json字符串
- constructor(private router: Router,private navCtrl: NavController) {}
- async ngOnInit() {
- await this.loadChatHistories(); // 加载聊天记录
- }
- async loadChatHistories() {
- const user = new CloudUser();
- const currentUser = await user.current(); // 获取当前用户信息
- if (currentUser) {
- const query = new CloudQuery("ChatHistory");
- query.equalTo("user", currentUser.toPointer()); // 查询当前用户的聊天记录
- this.chatHistories = await query.find(); // 获取聊天记录
- console.log("聊天记录已加载", this.chatHistories);
- } else {
- console.error("用户未登录,无法加载聊天记录");
- }
- }
- // 选择聊天记录
- selectChatHistory(chat: any) {
- this.selectedChat = chat.data.content; // 更新当前选择的聊天记录
- console.log("选择聊天记录", this.selectedChat);
- // 解析 JSON 字符串为对象数组
- this.selectedChat = JSON.parse(this.selectedChat);
- }
- // 清除选择
- clearSelection() {
- this.selectedChat = null; // 清除选择
- }
- goBack() {
- this.navCtrl.back(); // 返回上一页
- }
-
- }
|