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); +};