index.js 2.98 KB
Newer Older
1
import React from 'react';
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 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 84 85 86 87 88 89
      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}
      {title && content && (
        <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>}
                    </div>
                  </div>
                </div>
              </PageHeader>
            );
90
          }}
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
91
        </MenuContext.Consumer>
92
      )}
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
93 94 95 96 97 98 99 100
      {children ? (
        <div className={styles['children-content']}>
          <GridContent>{children}</GridContent>
        </div>
      ) : null}
    </div>
  );
};
Erwin Zhang's avatar
Erwin Zhang committed
101

ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
102
export default connect(({ setting }) => ({
afc163's avatar
afc163 committed
103
  contentWidth: setting.contentWidth,
104
}))(PageHeaderWrapper);