Header.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as React from 'react';
  2. import { Layout, MenuProps, Modal, Dropdown } from 'antd';
  3. import { CaretDownOutlined, PoweroffOutlined } from '@ant-design/icons';
  4. import logoSrc from '@/assets/public/logo.png';
  5. import router from '@/router';
  6. const { Header: AntdHeader } = Layout;
  7. interface Props {
  8. userName: string,
  9. onClickLogout: () => Promise<any>,
  10. };
  11. const Header: React.FC<Props> = (props: Props) => {
  12. const {
  13. userName,
  14. onClickLogout
  15. } = props;
  16. const items: MenuProps['items'] = [
  17. {
  18. key: 'logout',
  19. label: (
  20. <a onClick={() => {
  21. Modal.confirm({
  22. title: '提示',
  23. content: '确定退出平台吗?',
  24. async onOk() {
  25. await onClickLogout();
  26. }
  27. });
  28. }}>
  29. <PoweroffOutlined style={{ marginRight: 5 }} />
  30. 退出登录
  31. </a>
  32. ),
  33. }
  34. ];
  35. return (
  36. <AntdHeader className='header'>
  37. <div className='header-logo' onClick={() => {
  38. router.navigate({ pathname: '/' });
  39. }}>
  40. <img className='header-logo-picture' src={logoSrc} />
  41. <div className='header-logo-text'>
  42. 建科•小智后台管理系统
  43. </div>
  44. </div>
  45. <Dropdown menu={{ items }}>
  46. <div className='header-operation'>
  47. <div className='header-operation-picture'>
  48. {userName.slice(0, 1)}
  49. </div>
  50. <div className='header-operation-name'>
  51. {userName}
  52. </div>
  53. <CaretDownOutlined className='header-operation-down' />
  54. </div>
  55. </Dropdown>
  56. </AntdHeader>
  57. );
  58. };
  59. export default Header;