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

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

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