index.tsx 1.9 KB
Newer Older
何乐's avatar
何乐 committed
1
import { SiderMenuProps } from '@/components/SiderMenu';
陈小聪's avatar
陈小聪 committed
2
import React, { Component } from 'react';
zinkey's avatar
zinkey committed
3
import Link from 'umi/link';
何乐's avatar
何乐 committed
4
import RightContent, { GlobalHeaderRightProps } from '../GlobalHeader/RightContent';
Erwin Zhang's avatar
Erwin Zhang committed
5
import BaseMenu from '../SiderMenu/BaseMenu';
陈帅's avatar
陈帅 committed
6
import { getFlatMenuKeys } from '../SiderMenu/SiderMenuUtils';
jim's avatar
jim committed
7
import styles from './index.less';
何乐's avatar
何乐 committed
8
import defaultSettings, { ContentWidth } from '../../../config/defaultSettings';
jim's avatar
jim committed
9

何乐's avatar
何乐 committed
10 11
export interface TopNavHeaderProps extends SiderMenuProps, GlobalHeaderRightProps {
  contentWidth?: ContentWidth;
陈小聪's avatar
陈小聪 committed
12 13 14
}

interface TopNavHeaderState {
何乐's avatar
何乐 committed
15
  maxWidth?: number;
陈小聪's avatar
陈小聪 committed
16 17 18
}

export default class TopNavHeader extends Component<TopNavHeaderProps, TopNavHeaderState> {
何乐's avatar
何乐 committed
19
  static getDerivedStateFromProps(props: TopNavHeaderProps) {
20
    return {
yaphet's avatar
yaphet committed
21 22 23 24 25
      maxWidth:
        (props.contentWidth === 'Fixed' && window.innerWidth > 1200 ? 1200 : window.innerWidth) -
        280 -
        120 -
        40,
26 27 28
    };
  }

何乐's avatar
何乐 committed
29 30 31 32
  state: TopNavHeaderState = {};

  maim: HTMLDivElement | null = null;

jim's avatar
jim committed
33
  render() {
陈帅's avatar
陈帅 committed
34
    const { theme, contentWidth, menuData, logo } = this.props;
35
    const { maxWidth } = this.state;
陈帅's avatar
陈帅 committed
36
    const flatMenuKeys = getFlatMenuKeys(menuData);
jim's avatar
jim committed
37
    return (
陈帅's avatar
陈帅 committed
38
      <div className={`${styles.head} ${theme === 'light' ? styles.light : ''}`}>
39
        <div
何乐's avatar
何乐 committed
40
          ref={ref => (this.maim = ref)}
afc163's avatar
afc163 committed
41
          className={`${styles.main} ${contentWidth === 'Fixed' ? styles.wide : ''}`}
42
        >
jim's avatar
jim committed
43
          <div className={styles.left}>
44
            <div className={styles.logo} key="logo" id="logo">
jim's avatar
jim committed
45
              <Link to="/">
陈帅's avatar
陈帅 committed
46
                <img src={logo} alt="logo" />
何乐's avatar
何乐 committed
47
                <h1>{defaultSettings.title}</h1>
jim's avatar
jim committed
48 49
              </Link>
            </div>
何乐's avatar
何乐 committed
50
            <div style={{ maxWidth }}>
51
              <BaseMenu {...this.props} flatMenuKeys={flatMenuKeys} className={styles.menu} />
52
            </div>
jim's avatar
jim committed
53
          </div>
54
          <RightContent {...this.props} />
jim's avatar
jim committed
55 56 57 58 59
        </div>
      </div>
    );
  }
}