From 610ee8f409327309e1c2584b7780a4569ece4fa1 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sun, 26 Apr 2026 22:33:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=87=E9=A2=98=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=A6=E7=BB=86=E6=97=A5=E5=BF=97=E5=92=8C?= =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/app.js | 41 ++++++++++++++++++++++++++++++++--------- www/index.html | 6 +++--- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/www/app.js b/www/app.js index 3f834ff..dccc478 100644 --- a/www/app.js +++ b/www/app.js @@ -1003,6 +1003,8 @@ function hideStopGenerateBtn() { async function generateConversationTitle() { if (!currentConversation) return; + console.log('开始生成标题,当前消息数:', currentConversation.messages.length); + // 构建对话摘要 const conversationText = currentConversation.messages.map(m => `${m.role === 'user' ? '用户' : 'AI'}: ${m.content.slice(0, 200)}` @@ -1025,20 +1027,41 @@ ${conversationText}`; }) }); + console.log('标题API响应状态:', response.status); + if (response.ok) { const data = await response.json(); + console.log('标题API响应数据:', data); const newTitle = data.choices?.[0]?.message?.content?.trim(); - if (newTitle && newTitle.length > 0 && newTitle.length <= 15) { - currentConversation.title = newTitle; - currentConversation.updatedAt = Date.now(); - saveConversations(); - - // 更新页面标题显示 - const titleEl = document.querySelector('.header h1'); - if (titleEl) { - titleEl.textContent = newTitle; + console.log('生成的标题:', newTitle); + + if (newTitle && newTitle.length > 0) { + // 去掉可能的引号和多余符号 + const cleanTitle = newTitle.replace(/^["'"']+|["'"']+$/g, '').trim(); + if (cleanTitle.length > 0 && cleanTitle.length <= 20) { + currentConversation.title = cleanTitle; + currentConversation.updatedAt = Date.now(); + saveConversations(); + console.log('标题已保存:', cleanTitle); + + // 更新页面标题显示 + const titleEl = document.querySelector('.header h1'); + if (titleEl) { + titleEl.textContent = cleanTitle; + } + + // 更新侧边栏标题(如果在对话列表页面) + const convItem = document.querySelector(`.conversation-item[data-id="${currentConversation.id}"] .conv-title`); + if (convItem) { + convItem.textContent = cleanTitle; + } + + showToast('标题已更新'); } } + } else { + const errorText = await response.text(); + console.error('标题API错误:', errorText); } } catch (error) { console.error('生成标题失败:', error); diff --git a/www/index.html b/www/index.html index 2c12361..81238e4 100644 --- a/www/index.html +++ b/www/index.html @@ -8,12 +8,12 @@ AI助手 - +
- - + + \ No newline at end of file