AvatarDropdown.js 2.21 KB
Newer Older
张烨's avatar
张烨 committed
1
import { LogoutOutlined } from '@ant-design/icons';
dengxiaofeng's avatar
dengxiaofeng committed
2 3 4 5
import { Avatar, Menu, Spin } from 'antd';
import React from 'react';
import HeaderDropdown from '../HeaderDropdown';
import styles from './index.less';
张烨's avatar
张烨 committed
6
import { setAuthority } from '@/utils/authority';
7
import { appConnector } from '@/containers/App/store';
8
import logo from '@/assets/images/logo/panda-logo2.png';
9
import connectHistoryHoc from '@/containers/connectHistoryHoc';
dengxiaofeng's avatar
dengxiaofeng committed
10 11
class AvatarDropdown extends React.Component {
  /* eslint-disable no-unused-vars */
张烨's avatar
张烨 committed
12
  onMenuClick = event => {
张烨's avatar
张烨 committed
13
    const { logout, history, loginName } = this.props;
张烨's avatar
张烨 committed
14 15 16
    switch (event.key) {
      case 'logout':
        setAuthority([]);
17 18
        logout();
        history.push(`/user/login`);
张烨's avatar
张烨 committed
19 20 21 22 23
        break;
      default:
        break;
    }
  };
dengxiaofeng's avatar
dengxiaofeng committed
24 25 26

  render() {
    const {
张烨's avatar
张烨 committed
27
      loginName,
dengxiaofeng's avatar
dengxiaofeng committed
28
      currentUser = {
29
        avatar: logo,
张烨's avatar
张烨 committed
30
        name: '',
dengxiaofeng's avatar
dengxiaofeng committed
31 32 33 34 35 36 37 38
      },
    } = this.props;
    const menuHeaderDropdown = (
      <Menu
        className={styles.menu}
        selectedKeys={[]}
        onClick={this.onMenuClick}
      >
张烨's avatar
张烨 committed
39
        {/* {
dengxiaofeng's avatar
dengxiaofeng committed
40 41 42 43 44 45 46 47 48 49 50
          <Menu.Item key="center">
            <UserOutlined />
            个人中心
          </Menu.Item>
        }
        {
          <Menu.Item key="settings">
            <SettingOutlined />
            个人设置
          </Menu.Item>
        }
张烨's avatar
张烨 committed
51
        {<Menu.Divider />} */}
dengxiaofeng's avatar
dengxiaofeng committed
52 53 54 55 56 57 58

        <Menu.Item key="logout">
          <LogoutOutlined />
          退出登录
        </Menu.Item>
      </Menu>
    );
张烨's avatar
张烨 committed
59
    return currentUser ? (
dengxiaofeng's avatar
dengxiaofeng committed
60 61 62 63 64 65 66 67
      <HeaderDropdown overlay={menuHeaderDropdown}>
        <span className={`${styles.action} ${styles.account}`}>
          <Avatar
            size="small"
            className={styles.avatar}
            src={currentUser.avatar}
            alt="avatar"
          />
张烨's avatar
张烨 committed
68 69 70
          <span className={`${styles.name} anticon`}>
            {currentUser.name || loginName || '管理员'}
          </span>
dengxiaofeng's avatar
dengxiaofeng committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        </span>
      </HeaderDropdown>
    ) : (
      <span className={`${styles.action} ${styles.account}`}>
        <Spin
          size="small"
          style={{
            marginLeft: 8,
            marginRight: 8,
          }}
        />
      </span>
    );
  }
}

87
export default connectHistoryHoc(appConnector(AvatarDropdown));