index.js 1.26 KB
Newer Older
偏右's avatar
偏右 committed
1
import React, { PureComponent } from 'react';
jim's avatar
jim committed
2
import { Icon, Divider } from 'antd';
jiang's avatar
jiang committed
3
import { Link } from 'dva/router';
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}>
jim's avatar
jim committed
29 30 31 32 33 34
        {isMobile && [
          <Link to="/" className={styles.logo} key="logo">
            <img src={logo} alt="logo" width="32" />
          </Link>,
          <Divider type="vertical" key="line" />,
        ]}
偏右's avatar
偏右 committed
35 36 37 38 39
        <Icon
          className={styles.trigger}
          type={collapsed ? 'menu-unfold' : 'menu-fold'}
          onClick={this.toggle}
        />
jim's avatar
jim committed
40 41

        <RightContent {...this.props} />
42
      </div>
偏右's avatar
偏右 committed
43 44 45
    );
  }
}