import { Avatar, Icon, Menu, Spin } from 'antd'; import { ClickParam } from 'antd/es/menu'; import { FormattedMessage } from 'umi-plugin-react/locale'; import React from 'react'; import { connect } from 'dva'; import router from 'umi/router'; import { ConnectProps, ConnectState } from '@/models/connect'; import { CurrentUser } from '@/models/user'; 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; if (dispatch) { dispatch({ type: 'login/logout', }); } return; } router.push(`/account/${key}`); }; getUserName = (userName: string) => { return userName.length > 10 ? `${userName.substr(0, 10)}...` : userName; }; render(): React.ReactNode { const { currentUser = {}, menu } = this.props; if (!menu) { return ( {this.getUserName(currentUser.userName || '')} ); } const menuHeaderDropdown = ( ); console.log(currentUser.avatar); return currentUser && currentUser.userName ? ( {this.getUserName(currentUser.userName || '')} ) : ( ); } } export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser, }))(AvatarDropdown);