| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import React from 'react';
- import PropTypes from 'prop-types';
- import { Layout, Icon } from 'antd';
- import DocumentTitle from 'react-document-title';
- import { connect } from 'dva';
- import { Route, Redirect, Switch } from 'dva/router';
- import { ContainerQuery } from 'react-container-query';
- import classNames from 'classnames';
- import GlobalHeader from '../components/GlobalHeader';
- import GlobalFooter from '../components/GlobalFooter';
- import SiderMenu from '../components/SiderMenu';
- import NotFound from '../routes/Exception/404';
- const { Content } = Layout;
- const query = {
- 'screen-xs': {
- maxWidth: 575,
- },
- 'screen-sm': {
- minWidth: 576,
- maxWidth: 767,
- },
- 'screen-md': {
- minWidth: 768,
- maxWidth: 991,
- },
- 'screen-lg': {
- minWidth: 992,
- maxWidth: 1199,
- },
- 'screen-xl': {
- minWidth: 1200,
- },
- };
- class BasicLayout extends React.PureComponent {
- static childContextTypes = {
- location: PropTypes.object,
- breadcrumbNameMap: PropTypes.object,
- routeData: PropTypes.array,
- }
- getChildContext() {
- const { location, navData, getRouteData } = this.props;
- const routeData = getRouteData('BasicLayout');
- const firstMenuData = navData.reduce((arr, current) => arr.concat(current.children), []);
- const menuData = this.getMenuData(firstMenuData, '');
- const breadcrumbNameMap = {};
- routeData.concat(menuData).forEach((item) => {
- breadcrumbNameMap[item.path] = {
- name: item.name,
- component: item.component,
- };
- });
- return { location, breadcrumbNameMap, routeData };
- }
- getPageTitle() {
- const { location, getRouteData } = this.props;
- const { pathname } = location;
- let title = 'Ant Design Pro';
- getRouteData('BasicLayout').forEach((item) => {
- if (item.path === pathname) {
- title = `${item.name} - Ant Design Pro`;
- }
- });
- return title;
- }
- getMenuData = (data, parentPath) => {
- let arr = [];
- data.forEach((item) => {
- if (item.name) {
- arr.push({ path: `${parentPath}/${item.path}`, name: item.name });
- }
- if (item.children) {
- arr = arr.concat(this.getMenuData(item.children, `${parentPath}/${item.path}`));
- }
- });
- return arr;
- }
- render() {
- const {
- currentUser, collapsed, fetchingNotices, notices, getRouteData, navData, location, dispatch,
- } = this.props;
- const layout = (
- <Layout>
- <SiderMenu
- collapsed={collapsed}
- navData={navData}
- location={location}
- dispatch={dispatch}
- />
- <Layout>
- <GlobalHeader
- currentUser={currentUser}
- fetchingNotices={fetchingNotices}
- notices={notices}
- collapsed={collapsed}
- dispatch={dispatch}
- />
- <Content style={{ margin: '24px 24px 0', height: '100%' }}>
- <div style={{ minHeight: 'calc(100vh - 260px)' }}>
- <Switch>
- {
- getRouteData('BasicLayout').map(item =>
- (
- <Route
- exact={item.exact}
- key={item.path}
- path={item.path}
- component={item.component}
- />
- )
- )
- }
- <Redirect exact from="/" to="/dashboard/analysis" />
- <Route component={NotFound} />
- </Switch>
- </div>
- <GlobalFooter
- links={[{
- title: 'Pro 首页',
- href: 'http://pro.ant.design',
- blankTarget: true,
- }, {
- title: 'GitHub',
- href: 'https://github.com/ant-design/ant-design-pro',
- blankTarget: true,
- }, {
- title: 'Ant Design',
- href: 'http://ant.design',
- blankTarget: true,
- }]}
- copyright={
- <div>
- Copyright <Icon type="copyright" /> 2017 蚂蚁金服体验技术部出品
- </div>
- }
- />
- </Content>
- </Layout>
- </Layout>
- );
- return (
- <DocumentTitle title={this.getPageTitle()}>
- <ContainerQuery query={query}>
- {params => <div className={classNames(params)}>{layout}</div>}
- </ContainerQuery>
- </DocumentTitle>
- );
- }
- }
- export default connect(state => ({
- currentUser: state.user.currentUser,
- collapsed: state.global.collapsed,
- fetchingNotices: state.global.fetchingNotices,
- notices: state.global.notices,
- }))(BasicLayout);
|