From 336e3cd12f6d92f390dbb77806c042624f16bf1d Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Tue, 28 Apr 2026 13:05:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8D=A2=E8=AE=BE=E5=A4=87=E5=90=8E=E5=A4=B4=E5=83=8F=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=EF=BC=8C=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BB=8E=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E8=8E=B7=E5=8F=96=E6=9C=80=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/app.js | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/www/app.js b/www/app.js index 6440363..c8874fe 100644 --- a/www/app.js +++ b/www/app.js @@ -321,15 +321,41 @@ document.addEventListener('DOMContentLoaded', async () => { // 初始化 appContainer appContainer = document.getElementById('app'); + // 加载后台配置(包含 LLM、智能体等) + await loadBackendConfig(); + // 加载用户登录状态(优先检查) const savedUser = localStorage.getItem('currentUser'); if (savedUser) { currentUser = JSON.parse(savedUser); } - // 如果用户已登录且有ID,从 backend 加载对话数据 + // 如果用户已登录且有ID,从 backend 加载最新用户信息和对话数据 if (currentUser && currentUser.id) { try { + // 从后台获取最新用户信息(包括头像) + const userRes = await fetch(`/api/user/${currentUser.id}`); + if (userRes.ok) { + const userData = await userRes.json(); + if (userData && userData.id) { + // 更新 currentUser 为后台最新数据 + currentUser = { + id: userData.id, + username: userData.username, + phone: userData.phone || '', + email: userData.email || '', + avatar: userData.avatar || '👤', + signature: userData.signature || '', + gender: userData.gender || '', + age: userData.age || '', + region: userData.region || '', + registeredAt: Date.now() + }; + saveCurrentUser(); + } + } + + // 从 backend 加载对话数据 const res = await fetch(`/api/user/${currentUser.id}/conversations`); const data = await res.json(); if (Array.isArray(data) && data.length > 0) { @@ -437,13 +463,8 @@ document.addEventListener('DOMContentLoaded', async () => { currentPage = savedPage; } - // 加载后台配置并显示主页 - loadBackendConfig().then(() => { - showMainPage(); - }).catch(() => { - // 即使加载失败也显示主页 - showMainPage(); - }); + // 显示主页 + showMainPage(); }); // 根据用户配置更新显示的智能体