AvatarDropdown.jsx 2.35 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';
10 11 12 13 14

const roleName = {
  admin: '管理员',
  super: '超级管理员',
};
dengxiaofeng's avatar
dengxiaofeng committed
15 16
class AvatarDropdown extends React.Component {
  /* eslint-disable no-unused-vars */
张烨's avatar
张烨 committed
17
  onMenuClick = event => {
张烨's avatar
张烨 committed
18
    const { logout, history, loginName } = this.props;
张烨's avatar
张烨 committed
19 20 21
    switch (event.key) {
      case 'logout':
        setAuthority([]);
22 23
        logout();
        history.push(`/user/login`);
张烨's avatar
张烨 committed
24 25 26 27 28
        break;
      default:
        break;
    }
  };
dengxiaofeng's avatar
dengxiaofeng committed
29 30 31

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

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

94
export default connectHistoryHoc(appConnector(AvatarDropdown));