From 7cf5e1406fb65bc275630b7961a0000034472dcd Mon Sep 17 00:00:00 2001 From: sp mac bookpro 2605 Date: Fri, 31 Jul 2026 16:37:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=AF=E4=BC=9A=E8=AF=9D=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ChatHeader 新增可选 onLogout 回调,传入时在更多菜单中显示退出登录项 - ChatPagePure 中集成 useAuth 的 logout 方法,点击后确认并跳转登录页 - 不影响原有聊天页(未传 onLogout 时不显示) --- src/pages/chat/ChatPagePure.tsx | 16 +++++++++++++++- src/pages/chat/components/ChatHeader.tsx | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/pages/chat/ChatPagePure.tsx b/src/pages/chat/ChatPagePure.tsx index af58cee..f4a6ad2 100644 --- a/src/pages/chat/ChatPagePure.tsx +++ b/src/pages/chat/ChatPagePure.tsx @@ -1,5 +1,5 @@ import { useEffect, useState, useCallback, useRef } from 'react'; -import { App as AntApp, Empty } from 'antd'; +import { App as AntApp, Empty, Modal } from 'antd'; import type { ChatPageLogicOutput } from './ChatPageLogic'; import { markdownToPlainText } from './utils/copy'; import { useChatPageLogic } from './ChatPageLogic'; @@ -9,6 +9,7 @@ import ChatHeader from './components/ChatHeader'; import ChatInput from './components/ChatInput'; import ChatOutline from './components/ChatOutline'; import type { ModelOverrides } from '../../api'; +import { useAuth } from '../../store/auth'; import './styles/chat-page-pure.css'; /** @@ -19,6 +20,7 @@ import './styles/chat-page-pure.css'; export default function ChatPagePure() { const logic = useChatPageLogic(); const { message } = AntApp.useApp(); + const { logout } = useAuth(); const [outlineCollapsed, setOutlineCollapsed] = useState(true); const isAutoScrolling = useRef(false); @@ -70,6 +72,17 @@ export default function ChatPagePure() { } }, [setHighlightId]); + // 退出登录 + const handleLogout = () => { + Modal.confirm({ + title: '确定要退出登录吗?', + onOk: async () => { + await logout(); + window.location.href = '/login'; + }, + }); + }; + return (
@@ -89,6 +102,7 @@ export default function ChatPagePure() { onOpenMcp={() => setMcpDrawerOpen(true)} onManageAgent={() => navigate(`/agents/${id}`)} onClear={sender.handleClear} + onLogout={handleLogout} /> void; onManageAgent: () => void; onClear: () => void; + onLogout?: () => void; }) { - const { agent, useStream, setUseStream, onOpenHistory, onOpenParams, onOpenMcp, onManageAgent, onClear } = props; + const { agent, useStream, setUseStream, onOpenHistory, onOpenParams, onOpenMcp, onManageAgent, onClear, onLogout } = props; const modelText = formatAgentModel(agent.model); return ( @@ -86,7 +87,18 @@ export default function ChatHeader(props: { onClick: () => { Modal.confirm({ title: '清空当前会话所有消息?', onOk: onClear }); } - } + }, + ...(onLogout + ? [ + { type: 'divider' as const }, + { + key: 'logout', + label: '退出登录', + icon: , + onClick: onLogout, + } + ] + : []) ] }} placement="bottomRight"