index.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Avatar, Menu, Dropdown } from 'antd'
  2. import { DownOutlined } from '@ant-design/icons'
  3. import style from './style.module.scss'
  4. import { title } from 'constant'
  5. import { useSelector, useDispatch, postLogout } from 'store'
  6. import { useNavigate, RoutePath } from 'router'
  7. export const HeaderContent = () => {
  8. const user = useSelector(store => store.user.value)
  9. const dispatch = useDispatch()
  10. const navigate = useNavigate()
  11. const logout = async () => {
  12. await dispatch(postLogout()).unwrap()
  13. navigate(RoutePath.login, { replace: true })
  14. }
  15. const items = [
  16. {
  17. key: '1',
  18. label: <div onClick={logout} style={{textAlign: 'center'}}>退出</div>,
  19. }
  20. ]
  21. return (
  22. <>
  23. <h2 className={style.title}>{title}</h2>
  24. <div className={style.avatar}>
  25. <Dropdown
  26. overlay={<Menu style={{width: '100px'}} items={items} />}
  27. className={style['logout-drop']}
  28. placement="bottomRight">
  29. <div>
  30. <Avatar src={user.head} />
  31. <span className={style.username}>{user.nickName}</span>
  32. <DownOutlined />
  33. </div>
  34. </Dropdown>
  35. </div>
  36. </>
  37. )
  38. }