From caf14e8e522345786c382530029a398acac69e54 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Tue, 14 Jul 2026 11:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DDashboard=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=97=AE=E9=A2=98=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97=E3=80=81=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?strict=20mode=E9=87=8D=E5=A4=8D=E6=B8=B2=E6=9F=93=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84selectedId=E9=97=AD=E5=8C=85=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/agent/Dashboard.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/web/src/pages/agent/Dashboard.tsx b/web/src/pages/agent/Dashboard.tsx index a3a7266..e9a26d4 100644 --- a/web/src/pages/agent/Dashboard.tsx +++ b/web/src/pages/agent/Dashboard.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react' +import { useState, useEffect, useRef } from 'react' import { Input, Spin, message } from 'antd' import { SearchOutlined, UserOutlined, StarFilled } from '@ant-design/icons' import { useAuth } from '@/stores/auth' @@ -29,21 +29,25 @@ const Dashboard = () => { const [detail, setDetail] = useState(null) const [detailLoading, setDetailLoading] = useState(false) const [messageInput, setMessageInput] = useState('') + const initialLoad = useRef(true) useEffect(() => { loadSessions() }, []) const loadSessions = async () => { + setLoading(true) try { - setLoading(true) const res = await getSessions() + console.log('Sessions loaded:', res) setSessions(res.list) - if (res.list.length > 0 && !selectedId) { + if (res.list.length > 0 && initialLoad.current) { setSelectedId(res.list[0].id) + initialLoad.current = false } - } catch { - // fallback to empty + } catch (err) { + console.error('Failed to load sessions:', err) + message.error('加载会话失败,请重新登录') } finally { setLoading(false) }