import React, { useEffect, useState } from 'react' import logoImg from '../assets/logo.png' import { Menu, Dropdown, message } from 'antd'; import { CaretDownOutlined } from '@ant-design/icons'; import { useNavigate } from 'react-router-dom' function Header(props) { const navigate = useNavigate() // const [avatar, setAvatar] = useState(defaultAvatar) const [username, setUsername] = useState("游客") // 退出登录 const logout = () => { message.success('退出成功,即将返回登录页') localStorage.clear(); // 清除localStorage中的数据 setTimeout(() => navigate('/login'), 1500) } const menu = ( <Menu> <Menu.Item key={1}>修改资料</Menu.Item> <Menu.Divider /> <Menu.Item key={2} onClick={logout}>退出登录</Menu.Item> </Menu> ); return ( <header> <img src={logoImg} alt="" style={{width:"100px",height:"20px"}} className="logo" /> <div className="right"> <Dropdown overlay={menu}> <a className="ant-dropdown-link" onClick={e => e.preventDefault()}> <img className="avatar" alt="" /> <span>{username}</span> <CaretDownOutlined /> </a> </Dropdown> </div> </header> ) } export default Header