BasicLayout.js 3.82 KB
Newer Older
1 2
import React from 'react';
import PropTypes from 'prop-types';
偏右's avatar
偏右 committed
3
import { Layout, Icon } from 'antd';
4 5
import DocumentTitle from 'react-document-title';
import { connect } from 'dva';
偏右's avatar
偏右 committed
6
import { Route, Redirect, Switch } from 'dva/router';
afc163's avatar
afc163 committed
7 8
import { ContainerQuery } from 'react-container-query';
import classNames from 'classnames';
偏右's avatar
偏右 committed
9
import GlobalHeader from '../components/GlobalHeader';
10
import GlobalFooter from '../components/GlobalFooter';
偏右's avatar
偏右 committed
11
import SiderMenu from '../components/SiderMenu';
afc163's avatar
afc163 committed
12
import NotFound from '../routes/Exception/404';
ddcat1115's avatar
ddcat1115 committed
13
import { getRoutes } from '../utils/utils';
14

偏右's avatar
偏右 committed
15
const { Content } = Layout;
16

afc163's avatar
afc163 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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,
  },
};

38 39
class BasicLayout extends React.PureComponent {
  static childContextTypes = {
ddcat1115's avatar
ddcat1115 committed
40 41
    location: PropTypes.object,
    breadcrumbNameMap: PropTypes.object,
42 43
  }
  getChildContext() {
ddcat1115's avatar
ddcat1115 committed
44 45 46 47 48
    const { location, routerData } = this.props;
    return {
      location,
      breadcrumbNameMap: routerData,
    };
49 50
  }
  getPageTitle() {
ddcat1115's avatar
ddcat1115 committed
51
    const { routerData, location } = this.props;
ddcat1115's avatar
ddcat1115 committed
52 53
    const { pathname } = location;
    let title = 'Ant Design Pro';
ddcat1115's avatar
ddcat1115 committed
54 55 56
    if (routerData[pathname] && routerData[pathname].name) {
      title = `${routerData[pathname].name} - Ant Design Pro`;
    }
ddcat1115's avatar
ddcat1115 committed
57
    return title;
58 59
  }
  render() {
偏右's avatar
偏右 committed
60
    const {
ddcat1115's avatar
ddcat1115 committed
61
      currentUser, collapsed, fetchingNotices, notices, routerData, match, location, dispatch,
偏右's avatar
偏右 committed
62
    } = this.props;
afc163's avatar
afc163 committed
63 64
    const layout = (
      <Layout>
偏右's avatar
偏右 committed
65
        <SiderMenu
afc163's avatar
afc163 committed
66
          collapsed={collapsed}
偏右's avatar
偏右 committed
67 68 69
          location={location}
          dispatch={dispatch}
        />
afc163's avatar
afc163 committed
70
        <Layout>
偏右's avatar
偏右 committed
71 72 73 74 75 76 77
          <GlobalHeader
            currentUser={currentUser}
            fetchingNotices={fetchingNotices}
            notices={notices}
            collapsed={collapsed}
            dispatch={dispatch}
          />
afc163's avatar
afc163 committed
78
          <Content style={{ margin: '24px 24px 0', height: '100%' }}>
afc163's avatar
afc163 committed
79 80 81
            <div style={{ minHeight: 'calc(100vh - 260px)' }}>
              <Switch>
                {
ddcat1115's avatar
ddcat1115 committed
82
                  getRoutes(match.path, routerData).map(item =>
afc163's avatar
afc163 committed
83 84
                    (
                      <Route
ddcat1115's avatar
ddcat1115 committed
85
                        key={item.key}
afc163's avatar
afc163 committed
86 87
                        path={item.path}
                        component={item.component}
ddcat1115's avatar
ddcat1115 committed
88
                        exact={item.exact}
afc163's avatar
afc163 committed
89 90
                      />
                    )
ddcat1115's avatar
ddcat1115 committed
91
                  )
afc163's avatar
afc163 committed
92 93
                }
                <Redirect exact from="/" to="/dashboard/analysis" />
ddcat1115's avatar
ddcat1115 committed
94
                <Route render={NotFound} />
afc163's avatar
afc163 committed
95 96
              </Switch>
            </div>
afc163's avatar
afc163 committed
97 98
            <GlobalFooter
              links={[{
afc163's avatar
afc163 committed
99
                title: 'Pro 首页',
afc163's avatar
afc163 committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
                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>
118
        </Layout>
afc163's avatar
afc163 committed
119 120 121 122 123 124 125 126
      </Layout>
    );

    return (
      <DocumentTitle title={this.getPageTitle()}>
        <ContainerQuery query={query}>
          {params => <div className={classNames(params)}>{layout}</div>}
        </ContainerQuery>
127 128 129 130 131 132 133 134 135 136 137
      </DocumentTitle>
    );
  }
}

export default connect(state => ({
  currentUser: state.user.currentUser,
  collapsed: state.global.collapsed,
  fetchingNotices: state.global.fetchingNotices,
  notices: state.global.notices,
}))(BasicLayout);