index.tsx 1.84 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 {
afc163's avatar
afc163 committed
21
      maxWidth: (props.contentWidth === 'Fixed' ? 1200 : window.innerWidth) - 280 - 165 - 40,
22 23 24
    };
  }

何乐's avatar
何乐 committed
25 26 27 28
  state: TopNavHeaderState = {};

  maim: HTMLDivElement | null = null;

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