From 849fe063eb495e9c0a0ea804af429b4b3bdfb713 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sat, 25 Apr 2026 23:06:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=E6=97=A7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=A0=BC=E5=BC=8F=E8=87=AA=E5=8A=A8=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 检测旧 chat_history 数据 - 自动转换为新的 conversations 格式 - 清理旧数据避免重复 --- works/ai-chat-app/www/app.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/works/ai-chat-app/www/app.js b/works/ai-chat-app/www/app.js index 41af9a6..2e6a9b2 100644 --- a/works/ai-chat-app/www/app.js +++ b/works/ai-chat-app/www/app.js @@ -29,6 +29,25 @@ document.addEventListener('DOMContentLoaded', () => { conversations = JSON.parse(saved); } + // 兼容旧数据格式(chat_history) + const oldHistory = localStorage.getItem('chat_history'); + if (oldHistory && conversations.length === 0) { + const oldMessages = JSON.parse(oldHistory); + if (oldMessages.length > 0) { + // 转换旧数据为新格式 + const convertedConv = { + id: Date.now().toString(), + title: oldMessages[0].content.slice(0, 30) + (oldMessages[0].content.length > 30 ? '...' : ''), + messages: oldMessages, + createdAt: Date.now(), + updatedAt: Date.now() + }; + conversations.push(convertedConv); + saveConversations(); + localStorage.removeItem('chat_history'); // 清理旧数据 + } + } + // 显示对话列表页面 showConversationList(); });