RightContent.js 4.79 KB
Newer Older
jim's avatar
jim committed
1
import React, { PureComponent } from 'react';
陈帅's avatar
陈帅 committed
2
import { FormattedMessage } from 'react-intl';
jim's avatar
jim committed
3 4 5 6 7 8 9 10 11 12 13 14 15
import { Spin, Tag, Menu, Icon, Dropdown, Avatar, Tooltip } from 'antd';
import moment from 'moment';
import groupBy from 'lodash/groupBy';
import NoticeIcon from '../NoticeIcon';
import HeaderSearch from '../HeaderSearch';
import styles from './index.less';

export default class GlobalHeaderRight extends PureComponent {
  getNoticeData() {
    const { notices = [] } = this.props;
    if (notices.length === 0) {
      return {};
    }
jim's avatar
jim committed
16
    const newNotices = notices.map(notice => {
jim's avatar
jim committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
      const newNotice = { ...notice };
      if (newNotice.datetime) {
        newNotice.datetime = moment(notice.datetime).fromNow();
      }
      // transform id to item key
      if (newNotice.id) {
        newNotice.key = newNotice.id;
      }
      if (newNotice.extra && newNotice.status) {
        const color = {
          todo: '',
          processing: 'blue',
          urgent: 'red',
          doing: 'gold',
        }[newNotice.status];
        newNotice.extra = (
          <Tag color={color} style={{ marginRight: 0 }}>
            {newNotice.extra}
          </Tag>
        );
      }
      return newNotice;
    });
    return groupBy(newNotices, 'type');
  }
陈帅's avatar
陈帅 committed
42

jim's avatar
jim committed
43 44 45 46 47 48 49
  render() {
    const {
      currentUser,
      fetchingNotices,
      onNoticeVisibleChange,
      onMenuClick,
      onNoticeClear,
陈帅's avatar
陈帅 committed
50
      theme,
jim's avatar
jim committed
51 52 53 54
    } = this.props;
    const menu = (
      <Menu className={styles.menu} selectedKeys={[]} onClick={onMenuClick}>
        <Menu.Item key="userCenter">
陈帅's avatar
陈帅 committed
55 56
          <Icon type="user" />
          <FormattedMessage id="menu.account.center" defaultMessage="account center" />
jim's avatar
jim committed
57 58
        </Menu.Item>
        <Menu.Item key="userinfo">
陈帅's avatar
陈帅 committed
59 60
          <Icon type="setting" />
          <FormattedMessage id="menu.account.settings" defaultMessage="account settings" />
jim's avatar
jim committed
61 62
        </Menu.Item>
        <Menu.Item key="triggerError">
陈帅's avatar
陈帅 committed
63 64
          <Icon type="close-circle" />
          <FormattedMessage id="menu.account.trigger" defaultMessage="Trigger Error" />
jim's avatar
jim committed
65 66 67 68 69 70 71 72 73
        </Menu.Item>
        <Menu.Divider />
        <Menu.Item key="logout">
          <Icon type="logout" />退出登录
        </Menu.Item>
      </Menu>
    );
    const noticeData = this.getNoticeData();
    let className = styles.right;
陈帅's avatar
陈帅 committed
74
    if (theme === 'dark') {
jim's avatar
jim committed
75
      className = `${styles.right}  ${styles.dark}`;
jim's avatar
jim committed
76 77
    }
    return (
jim's avatar
jim committed
78
      <div className={className}>
jim's avatar
jim committed
79 80 81 82
        <HeaderSearch
          className={`${styles.action} ${styles.search}`}
          placeholder="站内搜索"
          dataSource={['搜索提示一', '搜索提示二', '搜索提示三']}
jim's avatar
jim committed
83
          onSearch={value => {
jim's avatar
jim committed
84 85
            console.log('input', value); // eslint-disable-line
          }}
jim's avatar
jim committed
86
          onPressEnter={value => {
jim's avatar
jim committed
87 88 89 90 91 92 93 94 95
            console.log('enter', value); // eslint-disable-line
          }}
        />
        <Tooltip title="使用文档">
          <a
            target="_blank"
            href="http://pro.ant.design/docs/getting-started"
            rel="noopener noreferrer"
            className={styles.action}
jim's avatar
jim committed
96
            title="使用文档"
jim's avatar
jim committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
          >
            <Icon type="question-circle-o" />
          </a>
        </Tooltip>
        <NoticeIcon
          className={styles.action}
          count={currentUser.notifyCount}
          onItemClick={(item, tabProps) => {
            console.log(item, tabProps); // eslint-disable-line
          }}
          onClear={onNoticeClear}
          onPopupVisibleChange={onNoticeVisibleChange}
          loading={fetchingNotices}
          popupAlign={{ offset: [20, -16] }}
        >
          <NoticeIcon.Tab
            list={noticeData['通知']}
            title="通知"
            emptyText="你已查看所有通知"
            emptyImage="https://gw.alipayobjects.com/zos/rmsportal/wAhyIChODzsoKIOBHcBk.svg"
          />
          <NoticeIcon.Tab
            list={noticeData['消息']}
            title="消息"
            emptyText="您已读完所有消息"
            emptyImage="https://gw.alipayobjects.com/zos/rmsportal/sAuJeJzSKbUmHfBQRzmZ.svg"
          />
          <NoticeIcon.Tab
            list={noticeData['待办']}
            title="待办"
            emptyText="你已完成所有待办"
            emptyImage="https://gw.alipayobjects.com/zos/rmsportal/HsIsxMZiWKrNUavQUXqx.svg"
          />
        </NoticeIcon>
        {currentUser.name ? (
          <Dropdown overlay={menu}>
            <span className={`${styles.action} ${styles.account}`}>
jim's avatar
jim committed
134 135 136 137 138 139
              <Avatar
                size="small"
                className={styles.avatar}
                src={currentUser.avatar}
                alt="avatar"
              />
jim's avatar
jim committed
140 141 142 143 144 145 146 147 148 149
              <span className={styles.name}>{currentUser.name}</span>
            </span>
          </Dropdown>
        ) : (
          <Spin size="small" style={{ marginLeft: 8 }} />
        )}
      </div>
    );
  }
}