import React, { useCallback } from 'react'; import { LogoutOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons'; import { Avatar, Menu, Spin } from 'antd'; import { useModel, useHistory } from 'umi'; import { stringify } from 'querystring'; import HeaderDropdown from './HeaderDropdown'; import { clearToken } from '@/utils/authority'; import styles from './index.less'; export interface GlobalHeaderRightProps { menu?: boolean; } const AvatarDropdown: React.FC = ({ menu }) => { const { initialState, setInitialState } = useModel('@@initialState'); const history = useHistory(); const loginOut = async () => { clearToken(); if (history.location.pathname !== '/membership/login') { history.replace({ pathname: '/membership/login', search: stringify({ redirect: history.location.pathname, }), }); } }; const onMenuClick = useCallback((event) => { const { key } = event; if (key === 'logout') { setInitialState({ ...initialState, currentUser: undefined }); loginOut(); return; } history.push(`/membership/${key}`); }, []); const loading = ( ); if (!initialState) { return loading; } const { currentUser } = initialState; if (!currentUser || !currentUser.name) { return loading; } const menuHeaderDropdown = ( {menu && ( 个人中心 )} {menu && ( 个人设置 )} {menu && } 退出登录 ); return ( } alt="avatar" /> {currentUser.name} ); }; export default AvatarDropdown;