diff --git a/src/components/layout/TopBar.tsx b/src/components/layout/TopBar.tsx index d752960..98f6662 100644 --- a/src/components/layout/TopBar.tsx +++ b/src/components/layout/TopBar.tsx @@ -1,37 +1,72 @@ +import { useEffect, useState } from 'react'; + interface TopBarProps { search: string; onSearch: (value: string) => void; enableSearch?: boolean; operatorName?: string; onLoginClick?: () => void; + onLogout?: () => void; } -export const TopBar = ({ enableSearch = true, operatorName, onLoginClick }: TopBarProps) => ( - - - {enableSearch ? ( - - {/* onSearch(e.target.value)} - className='text-sm' - /> */} - - ) : ( - 圆和医疗 · 体检驾驶舱 - )} - - - - 操作员 · {operatorName || '未登录'} - - - -); +export const TopBar = ({ enableSearch = true, operatorName, onLoginClick, onLogout }: TopBarProps) => { + const [showMenu, setShowMenu] = useState(false); + const [displayName, setDisplayName] = useState(operatorName || ''); + + useEffect(() => { + setDisplayName(operatorName || ''); + }, [operatorName]); + + const handleLogout = () => { + localStorage.clear(); + setDisplayName(''); + setShowMenu(false); + onLogout?.(); + }; + + return ( + + + {enableSearch ? ( + + {/* onSearch(e.target.value)} + className='text-sm' + /> */} + + ) : ( + 圆和医疗 · 体检驾驶舱 + )} + + + { + if (!operatorName) { + onLoginClick?.(); + return; + } + setShowMenu((v) => !v); + }} + className='px-3 py-1 rounded-2xl border bg-gray-50 hover:bg-gray-100 transition-colors cursor-pointer' + > + 操作员 · {displayName || '未登录'} + + {displayName && showMenu && ( + + + 退出登录 + + + )} + + + ); +};