|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
import { Layout, Menu, Icon, Avatar, Dropdown, Tag, message, Spin } from 'antd';
|
|
import { Layout, Menu, Icon, Avatar, Dropdown, Tag, message, Spin } from 'antd';
|
|
|
import DocumentTitle from 'react-document-title';
|
|
import DocumentTitle from 'react-document-title';
|
|
|
import { connect } from 'dva';
|
|
import { connect } from 'dva';
|
|
|
-import { Link, routerRedux } from 'dva/router';
|
|
|
|
|
|
|
+import { Link, routerRedux, Route, Redirect, Switch } from 'dva/router';
|
|
|
import moment from 'moment';
|
|
import moment from 'moment';
|
|
|
import groupBy from 'lodash/groupBy';
|
|
import groupBy from 'lodash/groupBy';
|
|
|
import styles from './BasicLayout.less';
|
|
import styles from './BasicLayout.less';
|
|
@@ -11,14 +11,15 @@ import HeaderSearch from '../components/HeaderSearch';
|
|
|
import NoticeIcon from '../components/NoticeIcon';
|
|
import NoticeIcon from '../components/NoticeIcon';
|
|
|
import GlobalFooter from '../components/GlobalFooter';
|
|
import GlobalFooter from '../components/GlobalFooter';
|
|
|
import { getNavData } from '../common/nav';
|
|
import { getNavData } from '../common/nav';
|
|
|
|
|
+import { getRouteData } from '../utils/utils';
|
|
|
|
|
|
|
|
const { Header, Sider, Content } = Layout;
|
|
const { Header, Sider, Content } = Layout;
|
|
|
const { SubMenu } = Menu;
|
|
const { SubMenu } = Menu;
|
|
|
|
|
|
|
|
class BasicLayout extends React.PureComponent {
|
|
class BasicLayout extends React.PureComponent {
|
|
|
static childContextTypes = {
|
|
static childContextTypes = {
|
|
|
- routes: PropTypes.array,
|
|
|
|
|
- params: PropTypes.object,
|
|
|
|
|
|
|
+ location: PropTypes.object,
|
|
|
|
|
+ breadcrumbNameMap: PropTypes.object,
|
|
|
}
|
|
}
|
|
|
constructor(props) {
|
|
constructor(props) {
|
|
|
super(props);
|
|
super(props);
|
|
@@ -29,8 +30,14 @@ class BasicLayout extends React.PureComponent {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
getChildContext() {
|
|
getChildContext() {
|
|
|
- const { routes, params } = this.props;
|
|
|
|
|
- return { routes, params };
|
|
|
|
|
|
|
+ const { location } = this.props;
|
|
|
|
|
+ const routeData = getRouteData('BasicLayout');
|
|
|
|
|
+ const menuData = getNavData().reduce((arr, current) => arr.concat(current.children), []);
|
|
|
|
|
+ const breadcrumbNameMap = {};
|
|
|
|
|
+ routeData.concat(menuData).forEach((item) => {
|
|
|
|
|
+ breadcrumbNameMap[item.path] = item.name;
|
|
|
|
|
+ });
|
|
|
|
|
+ return { location, breadcrumbNameMap };
|
|
|
}
|
|
}
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
this.props.dispatch({
|
|
this.props.dispatch({
|
|
@@ -98,13 +105,15 @@ class BasicLayout extends React.PureComponent {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
getPageTitle() {
|
|
getPageTitle() {
|
|
|
- const { routes } = this.props;
|
|
|
|
|
- for (let i = routes.length - 1; i >= 0; i -= 1) {
|
|
|
|
|
- if (routes[i].breadcrumbName) {
|
|
|
|
|
- return `${routes[i].breadcrumbName} - Ant Design Pro`;
|
|
|
|
|
|
|
+ const { location } = this.props;
|
|
|
|
|
+ const { pathname } = location;
|
|
|
|
|
+ let title = 'Ant Design Pro';
|
|
|
|
|
+ getRouteData('UserLayout').forEach((item) => {
|
|
|
|
|
+ if (item.path === pathname) {
|
|
|
|
|
+ title = `${item.name} - Ant Design Pro`;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- return 'Ant Design Pro';
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ return title;
|
|
|
}
|
|
}
|
|
|
getNoticeData() {
|
|
getNoticeData() {
|
|
|
const { notices = [] } = this.props;
|
|
const { notices = [] } = this.props;
|
|
@@ -161,7 +170,7 @@ class BasicLayout extends React.PureComponent {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
render() {
|
|
render() {
|
|
|
- const { children, currentUser, collapsed, fetchingNotices } = this.props;
|
|
|
|
|
|
|
+ const { currentUser, collapsed, fetchingNotices } = this.props;
|
|
|
|
|
|
|
|
const menu = (
|
|
const menu = (
|
|
|
<Menu className={styles.menu} selectedKeys={[]} onClick={this.onMenuClick}>
|
|
<Menu className={styles.menu} selectedKeys={[]} onClick={this.onMenuClick}>
|
|
@@ -171,7 +180,6 @@ class BasicLayout extends React.PureComponent {
|
|
|
<Menu.Item key="logout"><Icon type="logout" />退出登录</Menu.Item>
|
|
<Menu.Item key="logout"><Icon type="logout" />退出登录</Menu.Item>
|
|
|
</Menu>
|
|
</Menu>
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
const noticeData = this.getNoticeData();
|
|
const noticeData = this.getNoticeData();
|
|
|
|
|
|
|
|
// Don't show popup menu when it is been collapsed
|
|
// Don't show popup menu when it is been collapsed
|
|
@@ -270,7 +278,21 @@ class BasicLayout extends React.PureComponent {
|
|
|
</div>
|
|
</div>
|
|
|
</Header>
|
|
</Header>
|
|
|
<Content style={{ margin: '24px 24px 0', height: '100%' }}>
|
|
<Content style={{ margin: '24px 24px 0', height: '100%' }}>
|
|
|
- {children}
|
|
|
|
|
|
|
+ <Switch>
|
|
|
|
|
+ {
|
|
|
|
|
+ getRouteData('BasicLayout').map(item =>
|
|
|
|
|
+ (
|
|
|
|
|
+ <Route
|
|
|
|
|
+ exact={item.exact}
|
|
|
|
|
+ key={item.path}
|
|
|
|
|
+ path={item.path}
|
|
|
|
|
+ component={item.component}
|
|
|
|
|
+ />
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ <Redirect to="/dashboard/analysis" />
|
|
|
|
|
+ </Switch>
|
|
|
<GlobalFooter
|
|
<GlobalFooter
|
|
|
links={[{
|
|
links={[{
|
|
|
title: '帮助',
|
|
title: '帮助',
|