import React from 'react'; import { Avatar, Menu, Spin, Icon } from 'antd'; import { FormattedMessage } from 'umi-plugin-react/locale'; import { ClickParam } from 'antd/lib/menu'; import { ConnectProps, ConnectState } from '@/models/connect'; import { CurrentUser } from '@/models/user'; import { connect } from 'dva'; import router from 'umi/router'; import HeaderDropdown from '../HeaderDropdown'; import styles from './index.less'; export interface GlobalHeaderRightProps extends ConnectProps { currentUser?: CurrentUser; menu?: boolean; } class AvatarDropdown extends React.Component { onMenuClick = (event: ClickParam) => { const { key } = event; if (key === 'logout') { const { dispatch } = this.props; dispatch!({ type: 'login/logout', }); return; } router.push(`/account/${key}`); }; render() { const { currentUser = {}, menu } = this.props; if (!menu) { return ( {currentUser.name} ); } const menuHeaderDropdown = ( ); return currentUser && currentUser.name ? ( {currentUser.name} ) : ( ); } } export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser, }))(AvatarDropdown);