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