import React, { PureComponent } from 'react'; import { Layout, Menu, Icon, Spin, Tag, Dropdown, Avatar, message, Divider } from 'antd'; import moment from 'moment'; import groupBy from 'lodash/groupBy'; import Debounce from 'lodash-decorators/debounce'; import { Link } from 'dva/router'; import NoticeIcon from '../../components/NoticeIcon'; import HeaderSearch from '../../components/HeaderSearch'; import logo from '../../assets/logo.svg'; import styles from './index.less'; const { Header } = Layout; export default class GlobalHeader extends PureComponent { componentDidMount() { this.props.dispatch({ type: 'user/fetchCurrent', }); } componentWillUnmount() { this.triggerResizeEvent.cancel(); } 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(); } // 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 = {newNotice.extra}; } return newNotice; }); return groupBy(newNotices, 'type'); } handleNoticeClear = (type) => { message.success(`清空了${type}`); this.props.dispatch({ type: 'global/clearNotices', payload: type, }); } handleNoticeVisibleChange = (visible) => { if (visible) { this.props.dispatch({ type: 'global/fetchNotices', }); } } handleMenuClick = ({ key }) => { if (key === 'logout') { this.props.dispatch({ type: 'login/logout', }); } } toggle = () => { const { collapsed } = this.props; this.props.dispatch({ type: 'global/changeLayoutCollapsed', payload: !collapsed, }); this.triggerResizeEvent(); } @Debounce(600) triggerResizeEvent() { // eslint-disable-line const event = document.createEvent('HTMLEvents'); event.initEvent('resize', true, false); window.dispatchEvent(event); } render() { const { currentUser, collapsed, fetchingNotices, isMobile, } = this.props; const menu = ( 个人中心 设置 退出登录 ); const noticeData = this.getNoticeData(); return (
{isMobile && ( [( logo ), , ] )}
{ console.log('input', value); // eslint-disable-line }} onPressEnter={(value) => { console.log('enter', value); // eslint-disable-line }} /> { console.log(item, tabProps); // eslint-disable-line }} onClear={this.handleNoticeClear} onPopupVisibleChange={this.handleNoticeVisibleChange} loading={fetchingNotices} popupAlign={{ offset: [20, -16] }} > {currentUser.name ? ( {currentUser.name} ) : }
); } }