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