From 33f89729e78a8a05b5c5bc2883a0674392c52d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8B=BF=E5=A6=84?= <3124832605@qq.com> Date: Wed, 28 May 2025 18:01:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E7=9C=8B=E4=B8=8D=E4=B8=AD=E7=94=A8?= =?UTF-8?q?=E7=9A=84ai=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/vue-unilife/src/views/AiManager.vue | 120 +++++++++++++--------- 1 file changed, 73 insertions(+), 47 deletions(-) diff --git a/Front/vue-unilife/src/views/AiManager.vue b/Front/vue-unilife/src/views/AiManager.vue index d22d7b3..96979da 100644 --- a/Front/vue-unilife/src/views/AiManager.vue +++ b/Front/vue-unilife/src/views/AiManager.vue @@ -55,33 +55,44 @@ // 定义 HistoryItem 接口 interface HistoryItem { - text: string; - } - - const message = ref(''); - const historyItems = ref([ - { text: '这是一个历史对话' }, - { text: '这是一个历史对话' }, - ]); - - const sendMessage = () => { - const msg = message.value.trim(); - if (msg) { - console.log('发送消息:', msg); - // 这里可以添加实际的发送逻辑 - message.value = ''; - } - }; + id: number; // 唯一标识符 + text: string; // 对话内容 +} +// 历史对话列表 +const historyItems = ref([ + { id: 1, text: '这是一个历史对话' }, + { id: 2, text: '这是另一个历史对话' }, +]); + +// 当前输入的消息 +const message = ref(''); + +// 发送消息 +const sendMessage = () => { + const msg = message.value.trim(); + if (msg) { + const newItem: HistoryItem = { + id: Date.now(), // 使用时间戳作为唯一标识符 + text: msg, + }; + historyItems.value.push(newItem); // 添加到历史对话列表 + message.value = ''; // 清空输入框 + } +}; + + // 编辑历史对话 const editItem = (item: HistoryItem) => { - console.log('编辑历史对话:', item.text); - // 这里可以添加编辑逻辑 - }; - - const deleteItem = (item: HistoryItem) => { - console.log('删除历史对话:', item.text); - // 这里可以添加删除逻辑 - }; + const newText = prompt('编辑对话内容:', item.text); + if (newText !== null) { + item.text = newText.trim(); + } +}; + +// 删除历史对话 +const deleteItem = (item: HistoryItem) => { + historyItems.value = historyItems.value.filter((history) => history.id !== item.id); +};