Commit bf73643b authored by jim's avatar jim Committed by ι™ˆεΈ…

change to new context api

parent 072e30b2
import React, { PureComponent, createElement } from 'react'; import React, { PureComponent, createElement } from 'react';
import PropTypes from 'prop-types';
import pathToRegexp from 'path-to-regexp'; import pathToRegexp from 'path-to-regexp';
import { Breadcrumb, Tabs } from 'antd'; import { Breadcrumb, Tabs } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
...@@ -20,12 +19,6 @@ export function getBreadcrumb(breadcrumbNameMap, url) { ...@@ -20,12 +19,6 @@ export function getBreadcrumb(breadcrumbNameMap, url) {
} }
export default class PageHeader extends PureComponent { export default class PageHeader extends PureComponent {
static contextTypes = {
routes: PropTypes.array,
params: PropTypes.object,
location: PropTypes.object,
breadcrumbNameMap: PropTypes.object,
};
onChange = key => { onChange = key => {
if (this.props.onTabChange) { if (this.props.onTabChange) {
this.props.onTabChange(key); this.props.onTabChange(key);
...@@ -33,10 +26,10 @@ export default class PageHeader extends PureComponent { ...@@ -33,10 +26,10 @@ export default class PageHeader extends PureComponent {
}; };
getBreadcrumbProps = () => { getBreadcrumbProps = () => {
return { return {
routes: this.props.routes || this.context.routes, routes: this.props.routes,
params: this.props.params || this.context.params, params: this.props.params,
routerLocation: this.props.location || this.context.location, routerLocation: this.props.location,
breadcrumbNameMap: this.props.breadcrumbNameMap || this.context.breadcrumbNameMap, breadcrumbNameMap: this.props.breadcrumbNameMap,
}; };
}; };
// Generated according to props // Generated according to props
......
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import { Layout } from 'antd'; import { Layout } from 'antd';
import DocumentTitle from 'react-document-title'; import DocumentTitle from 'react-document-title';
import { connect } from 'dva'; import { connect } from 'dva';
...@@ -14,6 +13,7 @@ import Sidebar from '../components/Sidebar'; ...@@ -14,6 +13,7 @@ import Sidebar from '../components/Sidebar';
import logo from '../assets/logo.svg'; import logo from '../assets/logo.svg';
import Footer from './Footer'; import Footer from './Footer';
import Header from './Header'; import Header from './Header';
import Context from './MeunContext';
const { Content } = Layout; const { Content } = Layout;
const { AuthorizedRoute, check } = Authorized; const { AuthorizedRoute, check } = Authorized;
...@@ -61,11 +61,7 @@ const query = { ...@@ -61,11 +61,7 @@ const query = {
}; };
class BasicLayout extends React.PureComponent { class BasicLayout extends React.PureComponent {
static childContextTypes = { getContext() {
location: PropTypes.object,
breadcrumbNameMap: PropTypes.object,
};
getChildContext() {
const { location, routerData, menuData } = this.props; const { location, routerData, menuData } = this.props;
return { return {
location, location,
...@@ -165,10 +161,12 @@ class BasicLayout extends React.PureComponent { ...@@ -165,10 +161,12 @@ class BasicLayout extends React.PureComponent {
<DocumentTitle title={this.getPageTitle()}> <DocumentTitle title={this.getPageTitle()}>
<ContainerQuery query={query}> <ContainerQuery query={query}>
{params => ( {params => (
<Context.Provider value={this.getContext()}>
<div className={classNames(params)}> <div className={classNames(params)}>
{layout} {layout}
<RightSidebar onChange={this.changeSetting} /> <RightSidebar onChange={this.changeSetting} />
</div> </div>
</Context.Provider>
)} )}
</ContainerQuery> </ContainerQuery>
</DocumentTitle> </DocumentTitle>
......
import { createContext } from 'react';
export default createContext();
...@@ -3,11 +3,16 @@ import { Link } from 'dva/router'; ...@@ -3,11 +3,16 @@ import { Link } from 'dva/router';
import PageHeader from '../components/PageHeader'; import PageHeader from '../components/PageHeader';
import GridContent from './GridContent'; import GridContent from './GridContent';
import styles from './PageHeaderLayout.less'; import styles from './PageHeaderLayout.less';
import MeunContext from './MeunContext';
export default ({ children, wrapperClassName, top, ...restProps }) => ( export default ({ children, wrapperClassName, top, ...restProps }) => (
<div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}> <div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}>
{top} {top}
<PageHeader key="pageheader" {...restProps} linkElement={Link} /> <MeunContext.Consumer>
{value => {
return <PageHeader {...value} key="pageheader" {...restProps} linkElement={Link} />;
}}
</MeunContext.Consumer>
{children ? ( {children ? (
<div className={styles.content}> <div className={styles.content}>
<GridContent>{children}</GridContent> <GridContent>{children}</GridContent>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment