AvatarDropdown.js 2.16 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 => {
13
    const { logout, history } = 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 27

  render() {
    const {
      currentUser = {
28 29
        avatar: logo,
        name: '测试人员',
dengxiaofeng's avatar
dengxiaofeng committed
30 31 32 33 34 35 36 37
      },
    } = this.props;
    const menuHeaderDropdown = (
      <Menu
        className={styles.menu}
        selectedKeys={[]}
        onClick={this.onMenuClick}
      >
张烨's avatar
张烨 committed
38
        {/* {
dengxiaofeng's avatar
dengxiaofeng committed
39 40 41 42 43 44 45 46 47 48 49
          <Menu.Item key="center">
            <UserOutlined />
            个人中心
          </Menu.Item>
        }
        {
          <Menu.Item key="settings">
            <SettingOutlined />
            个人设置
          </Menu.Item>
        }
张烨's avatar
张烨 committed
50
        {<Menu.Divider />} */}
dengxiaofeng's avatar
dengxiaofeng committed
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

        <Menu.Item key="logout">
          <LogoutOutlined />
          退出登录
        </Menu.Item>
      </Menu>
    );
    return currentUser && currentUser.name ? (
      <HeaderDropdown overlay={menuHeaderDropdown}>
        <span className={`${styles.action} ${styles.account}`}>
          <Avatar
            size="small"
            className={styles.avatar}
            src={currentUser.avatar}
            alt="avatar"
          />
          <span className={`${styles.name} anticon`}>{currentUser.name}</span>
        </span>
      </HeaderDropdown>
    ) : (
      <span className={`${styles.action} ${styles.account}`}>
        <Spin
          size="small"
          style={{
            marginLeft: 8,
            marginRight: 8,
          }}
        />
      </span>
    );
  }
}

84
export default connectHistoryHoc(appConnector(AvatarDropdown));