Header.jsx 2 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
import React, { useState, useEffect } from "react";
import {
  LockOutlined,
  UserOutlined,
  LogoutOutlined,
  SearchOutlined,
} from "@ant-design/icons";
import { Layout, Menu, theme, Dropdown, Tooltip, Avatar, Button } from "antd";
import { Outlet, useLocation, history, useOutletContext } from "umi";
import { doFetch } from "@/utils/doFetch";
import Fade from "react-reveal/Fade";
const { Header, Content, Footer, Sider } = Layout;

function Headers({ currentUser, children, broken }) {
  const {
    token: { colorBgContainer, colorTextBase },
  } = theme.useToken();

  const items = [
    {
      key: "1",
      label: (
        <span target="_blank" rel="noopener noreferrer">
          个人中心
        </span>
      ),
      icon: <UserOutlined />,
    },
    {
      key: "2",
      label: (
        <span target="_blank" rel="noopener noreferrer">
          修改密码
        </span>
      ),
      icon: <LockOutlined />,
    },
    {
      key: "4",
      danger: true,
      label: "退出登录",
      icon: <LogoutOutlined />,
    },
  ];

  return (
    <Header
      style={{
        padding: 0,
        background: colorBgContainer,
        display: "flex",
        justifyContent: "space-between",
        alignItems: "center",
        marginTop: 10,
      }}
    >
      <div style={{ marginLeft: 24 }} className="centerl">
        {broken && children}
        <Button
          icon={<SearchOutlined></SearchOutlined>}
          type="text"
          shape="circle"
        ></Button>
      </div>
      <div style={{ marginRight: 112, gap: 12 }} className="centerl">
        <Dropdown
          menu={{
            items,
            onClick:(e)=>{
                if(e.key === "1"){
                    history.push("/mycenter")
                }

            }
          }}
          placement="bottom"
        >
          <Avatar size={"large"} src={currentUser?.head_url}></Avatar>
        </Dropdown>

        <b>{currentUser?.name ?? "-"}</b>
      </div>
    </Header>
  );
}

export default Headers;