|
@@ -0,0 +1,68 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { IonicModule } from '@ionic/angular';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { ActivatedRoute, Router } from '@angular/router';
|
|
|
+
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-chat-panel',
|
|
|
+ templateUrl: './chat-panel.component.html',
|
|
|
+ styleUrls: ['./chat-panel.component.scss'],
|
|
|
+ standalone: true,
|
|
|
+ imports: [IonicModule, FormsModule, CommonModule],
|
|
|
+})
|
|
|
+export class ChatPanelComponent implements OnInit {
|
|
|
+ constructor(private route: ActivatedRoute) { }
|
|
|
+ userPrompt = ""
|
|
|
+ ngOnInit() {
|
|
|
+ this.route.queryParams.subscribe(params => {
|
|
|
+ this.userPrompt = params['userPrompt'] || '';
|
|
|
+ this.initializeMessages();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ initializeMessages() {
|
|
|
+ this.messages = [
|
|
|
+ { text: 'Hello, how are you?', isMyMessage: false },
|
|
|
+ { text: this.userPrompt + 'test', isMyMessage: true },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ // 模拟聊天消息数据
|
|
|
+ messages = [
|
|
|
+ { text: 'Hello, how are you?', isMyMessage: false },
|
|
|
+ { text: this.userPrompt + 'test', isMyMessage: true },
|
|
|
+ ];
|
|
|
+
|
|
|
+ inputText = ''; // 输入框的内容
|
|
|
+
|
|
|
+ // 处理输入框内容变化
|
|
|
+ onInputChange() {
|
|
|
+ if (this.inputText.trim()) {
|
|
|
+ // Input box resizes automatically based on content
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送消息
|
|
|
+ sendMessage() {
|
|
|
+ if (this.inputText.trim()) {
|
|
|
+ const newMessage = {
|
|
|
+ text: this.inputText,
|
|
|
+ isMyMessage: true
|
|
|
+ };
|
|
|
+ this.messages.push(newMessage); // 添加消息到聊天记录
|
|
|
+
|
|
|
+ // 清空输入框
|
|
|
+ this.inputText = '';
|
|
|
+
|
|
|
+ // 模拟对方回复
|
|
|
+ setTimeout(() => {
|
|
|
+ const replyMessage = {
|
|
|
+ text: 'Got it! I will check that.',
|
|
|
+ isMyMessage: false
|
|
|
+ };
|
|
|
+ this.messages.push(replyMessage);
|
|
|
+ }, 1000); // 模拟1秒后收到对方消息
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|