From 3417709a79bdd3d4053428f5efd485bd219d17ac Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sat, 25 Apr 2026 23:05:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=9A=E5=AF=B9=E8=AF=9D=E7=AE=A1?= =?UTF-8?q?=E7=90=86=20+=20=E5=8E=86=E5=8F=B2=E5=AF=B9=E8=AF=9D=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增对话列表页面(首页) - 每个对话显示标题、消息数、更新时间 - 对话列表支持删除对话 - 新建对话按钮 - 对话标题自动生成(第一条消息摘要) - 点击对话进入具体对话页面 - 返回按钮回到对话列表 - 数据结构改为 conversations 多对话存储 - 兼容旧数据格式自动转换 --- works/ai-chat-app/www/app.js | 369 +++++++++++++++++++++--------- works/ai-chat-app/www/index.html | 47 +--- works/ai-chat-app/www/style.css | 375 ++++++++++++++++++++----------- 3 files changed, 512 insertions(+), 279 deletions(-) diff --git a/works/ai-chat-app/www/app.js b/works/ai-chat-app/www/app.js index e6921ab..41af9a6 100644 --- a/works/ai-chat-app/www/app.js +++ b/works/ai-chat-app/www/app.js @@ -1,5 +1,5 @@ // AI助手 - 前端应用 -// 使用智谱 GLM-4.5-Air 模型(流式输出) +// 使用智谱 GLM-4.5-Air 模型(流式输出 + 多对话管理) const CONFIG = { apiUrl: 'https://open.bigmodel.cn/api/paas/v4/chat/completions', @@ -8,11 +8,13 @@ const CONFIG = { maxTokens: 2048 }; -// 对话历史 -let messages = []; +// 数据结构 +let conversations = []; // 对话列表 +let currentConversation = null; // 当前对话 let isLoading = false; // DOM 元素 +const appContainer = document.getElementById('app'); const messagesContainer = document.getElementById('messagesContainer'); const messagesDiv = document.getElementById('messages'); const userInput = document.getElementById('userInput'); @@ -21,20 +23,151 @@ const welcome = document.getElementById('welcome'); // 初始化 document.addEventListener('DOMContentLoaded', () => { - // 从本地存储恢复对话 - const saved = localStorage.getItem('chat_history'); + // 从本地存储加载对话列表 + const saved = localStorage.getItem('conversations'); if (saved) { - messages = JSON.parse(saved); - renderMessages(); - if (messages.length > 0) { - welcome.style.display = 'none'; - } + conversations = JSON.parse(saved); } - // 聚焦输入框 - userInput.focus(); + // 显示对话列表页面 + showConversationList(); }); +// ==================== 对话列表页面 ==================== + +function showConversationList() { + currentConversation = null; + + // 渲染对话列表 + const listHtml = ` +