index.js 1.19 KB
Newer Older
偏右's avatar
偏右 committed
1
import React, { PureComponent } from 'react';
2
import { Icon } from 'antd';
zinkey's avatar
zinkey committed
3
import Link from 'umi/link';
jim's avatar
jim committed
4
import Debounce from 'lodash-decorators/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

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