import React, { Component } from 'react'; import { FormattedMessage, formatMessage } from 'umi-plugin-locale'; import { Spin, Tag, Menu, Icon, Avatar, Tooltip, message } from 'antd'; import { ClickParam } from 'antd/es/menu'; import moment from 'moment'; import groupBy from 'lodash/groupBy'; import { NoticeIcon } from 'ant-design-pro'; import HeaderSearch from '../HeaderSearch'; import HeaderDropdown from '../HeaderDropdown'; import SelectLang from '../SelectLang'; import styles from './index.less'; export declare type SiderTheme = 'light' | 'dark'; interface GlobalHeaderRightProps { notices?: any[]; dispatch?: (args: any) => void; // wait for https://github.com/umijs/umi/pull/2036 currentUser?: { avatar?: string; name?: string; title?: string; group?: string; signature?: string; geographic?: any; tags?: any[]; unreadCount: number; }; fetchingNotices?: boolean; onNoticeVisibleChange?: (visible: boolean) => void; onMenuClick?: (param: ClickParam) => void; onNoticeClear?: (tabName: string) => void; theme?: SiderTheme; } export default class GlobalHeaderRight extends Component { getNoticeData() { const { notices = [] } = this.props; if (notices.length === 0) { return {}; } const newNotices = notices.map(notice => { const newNotice = { ...notice }; if (newNotice.datetime) { newNotice.datetime = moment(notice.datetime).fromNow(); } 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 = ( {newNotice.extra} ); } return newNotice; }); return groupBy(newNotices, 'type'); } getUnreadData: (noticeData: object) => any = noticeData => { const unreadMsg = {}; Object.entries(noticeData).forEach(([key, value]) => { if (!unreadMsg[key]) { unreadMsg[key] = 0; } if (Array.isArray(value)) { unreadMsg[key] = value.filter(item => !item.read).length; } }); return unreadMsg; }; changeReadState = clickedItem => { const { id } = clickedItem; const { dispatch } = this.props; dispatch({ type: 'global/changeNoticeReadState', payload: id, }); }; render() { const { currentUser, fetchingNotices, onNoticeVisibleChange, onMenuClick, onNoticeClear, theme, } = this.props; const menu = ( ); const noticeData = this.getNoticeData(); const unreadMsg = this.getUnreadData(noticeData); let className = styles.right; if (theme === 'dark') { className = `${styles.right} ${styles.dark}`; } return (
{ console.log('input', value); // eslint-disable-line }} onPressEnter={value => { console.log('enter', value); // eslint-disable-line }} /> { console.log(item, tabProps); // eslint-disable-line this.changeReadState(item); }} loading={fetchingNotices} locale={{ emptyText: formatMessage({ id: 'component.noticeIcon.empty' }), clear: formatMessage({ id: 'component.noticeIcon.clear' }), viewMore: formatMessage({ id: 'component.noticeIcon.view-more' }), // todo:node_modules/ant-design-pro/lib/NoticeIcon/index.d.ts 21 [key: string]: string; notification: formatMessage({ id: 'component.globalHeader.notification' }), message: formatMessage({ id: 'component.globalHeader.message' }), event: formatMessage({ id: 'component.globalHeader.event' }), }} onClear={onNoticeClear} onPopupVisibleChange={onNoticeVisibleChange} onViewMore={() => message.info('Click on view more')} // todo:onViewMore?: (tabProps: INoticeIconProps) => void; clearClose > {currentUser.name ? ( {currentUser.name} ) : ( )}
); } }