AvatarDropdown.jsx 2.36 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
      },
    } = this.props;
邓超's avatar
邓超 committed
38
    const userName = sessionStorage.getItem('userName');
dengxiaofeng's avatar
dengxiaofeng committed
39
    const menuHeaderDropdown = (
邓超's avatar
邓超 committed
40
      <Menu className={styles.menu} selectedKeys={[]} onClick={this.onMenuClick}>
张烨's avatar
张烨 committed
41
        {/* {
dengxiaofeng's avatar
dengxiaofeng committed
42 43 44 45 46 47 48 49 50 51 52
          <Menu.Item key="center">
            <UserOutlined />
            个人中心
          </Menu.Item>
        }
        {
          <Menu.Item key="settings">
            <SettingOutlined />
            个人设置
          </Menu.Item>
        }
张烨's avatar
张烨 committed
53
        {<Menu.Divider />} */}
dengxiaofeng's avatar
dengxiaofeng committed
54 55 56 57 58 59 60

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

85
export default connectHistoryHoc(appConnector(AvatarDropdown));