index.js 2.87 KB
Newer Older
1
import React from 'react';
陈小聪's avatar
陈小聪 committed
2
import { FormattedMessage } from 'umi-plugin-react/locale';
zinkey's avatar
zinkey committed
3
import Link from 'umi/link';
陈帅's avatar
陈帅 committed
4
import { PageHeader, Tabs, Typography } from 'antd';
5
import { connect } from 'dva';
陈帅's avatar
陈帅 committed
6
import classNames from 'classnames';
jim's avatar
jim committed
7
import GridContent from './GridContent';
8 9
import styles from './index.less';
import MenuContext from '@/layouts/MenuContext';
陈帅's avatar
陈帅 committed
10
import { conversionBreadcrumbList } from './breadcrumb';
11

陈帅's avatar
陈帅 committed
12 13 14 15 16 17 18
const { Title } = Typography;

/**
 * render Footer tabList
 * In order to be compatible with the old version of the PageHeader
 * basically all the functions are implemented.
 */
拷钉's avatar
拷钉 committed
19
const renderFooter = ({ tabList, tabActiveKey, onTabChange, tabBarExtraContent }) => {
陈帅's avatar
陈帅 committed
20 21 22
  return tabList && tabList.length ? (
    <Tabs
      className={styles.tabs}
拷钉's avatar
拷钉 committed
23
      activeKey={tabActiveKey}
陈帅's avatar
陈帅 committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
      onChange={key => {
        if (onTabChange) {
          onTabChange(key);
        }
      }}
      tabBarExtraContent={tabBarExtraContent}
    >
      {tabList.map(item => (
        <Tabs.TabPane tab={item.tab} key={item.key} />
      ))}
    </Tabs>
  ) : null;
};

const PageHeaderWrapper = ({
  children,
  contentWidth,
  wrapperClassName,
  top,
  title,
  content,
  logo,
  extraContent,
  ...restProps
}) => {
  return (
    <div style={{ margin: '-24px -24px 0' }} className={classNames(classNames, styles.main)}>
      {top}
TnWah's avatar
TnWah committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
      <MenuContext.Consumer>
        {value => {
          return (
            <PageHeader
              wide={contentWidth === 'Fixed'}
              title={
                <Title
                  level={4}
                  style={{
                    marginBottom: 0,
                  }}
                >
                  {title}
                </Title>
              }
              key="pageheader"
              {...restProps}
              breadcrumb={conversionBreadcrumbList({
                ...value,
                ...restProps,
                home: <FormattedMessage id="menu.home" defaultMessage="Home" />,
              })}
              className={styles.pageHeader}
              linkElement={Link}
              footer={renderFooter(restProps)}
            >
              <div className={styles.detail}>
                {logo && <div className={styles.logo}>{logo}</div>}
                <div className={styles.main}>
                  <div className={styles.row}>
                    {content && <div className={styles.content}>{content}</div>}
                    {extraContent && <div className={styles.extraContent}>{extraContent}</div>}
陈帅's avatar
陈帅 committed
84 85
                  </div>
                </div>
TnWah's avatar
TnWah committed
86 87 88 89 90
              </div>
            </PageHeader>
          );
        }}
      </MenuContext.Consumer>
陈帅's avatar
陈帅 committed
91 92 93 94 95 96 97 98
      {children ? (
        <div className={styles['children-content']}>
          <GridContent>{children}</GridContent>
        </div>
      ) : null}
    </div>
  );
};
Erwin Zhang's avatar
Erwin Zhang committed
99

陈帅's avatar
陈帅 committed
100
export default connect(({ setting }) => ({
afc163's avatar
afc163 committed
101
  contentWidth: setting.contentWidth,
102
}))(PageHeaderWrapper);