index.tsx 1.43 KB
Newer Older
1
import React, { Component } from 'react';
2
import { Icon } from 'antd';
zinkey's avatar
zinkey committed
3
import Link from 'umi/link';
4
import debounce from 'lodash/debounce';
偏右's avatar
偏右 committed
5
import styles from './index.less';
jim's avatar
jim committed
6
import RightContent from './RightContent';
偏右's avatar
偏右 committed
7

8 9 10 11 12 13 14 15 16 17 18
interface GlobalHeaderProps {
  collapsed?: boolean;
  onCollapse?: (collapsed: boolean) => void;
  isMobile?: boolean;
  logo?: string;
  onNoticeClear?: (type: string) => void;
  onMenuClick?: ({ key: string }) => void;
  onNoticeVisibleChange?: (b: boolean) => void;
}

export default class GlobalHeader extends Component<GlobalHeaderProps> {
偏右's avatar
偏右 committed
19 20 21
  componentWillUnmount() {
    this.triggerResizeEvent.cancel();
  }
22
  triggerResizeEvent = debounce(() => {
jim's avatar
jim committed
23
    // eslint-disable-line
偏右's avatar
偏右 committed
24 25 26
    const event = document.createEvent('HTMLEvents');
    event.initEvent('resize', true, false);
    window.dispatchEvent(event);
27
  });
jim's avatar
jim committed
28 29 30 31 32
  toggle = () => {
    const { collapsed, onCollapse } = this.props;
    onCollapse(!collapsed);
    this.triggerResizeEvent();
  };
偏右's avatar
偏右 committed
33
  render() {
jim's avatar
jim committed
34
    const { collapsed, isMobile, logo } = this.props;
偏右's avatar
偏右 committed
35
    return (
36
      <div className={styles.header}>
37
        {isMobile && (
jim's avatar
jim committed
38 39
          <Link to="/" className={styles.logo} key="logo">
            <img src={logo} alt="logo" width="32" />
40 41
          </Link>
        )}
42 43 44
        <span className={styles.trigger} onClick={this.toggle}>
          <Icon type={collapsed ? 'menu-unfold' : 'menu-fold'} />
        </span>
jim's avatar
jim committed
45
        <RightContent {...this.props} />
46
      </div>
偏右's avatar
偏右 committed
47 48 49
    );
  }
}