|
|
|
@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; |
|
|
|
import { Layout, Menu, Icon, Avatar, Dropdown, Tag, message, Spin } from 'antd'; |
|
|
|
import DocumentTitle from 'react-document-title'; |
|
|
|
import { connect } from 'dva'; |
|
|
|
import { Link, routerRedux } from 'dva/router'; |
|
|
|
import { Link, routerRedux, Route, Redirect, Switch } from 'dva/router'; |
|
|
|
import moment from 'moment'; |
|
|
|
import groupBy from 'lodash/groupBy'; |
|
|
|
import styles from './BasicLayout.less'; |
|
|
|
@ -11,14 +11,15 @@ import HeaderSearch from '../components/HeaderSearch'; |
|
|
|
import NoticeIcon from '../components/NoticeIcon'; |
|
|
|
import GlobalFooter from '../components/GlobalFooter'; |
|
|
|
import { getNavData } from '../common/nav'; |
|
|
|
import { getRouteData } from '../utils/utils'; |
|
|
|
|
|
|
|
const { Header, Sider, Content } = Layout; |
|
|
|
const { SubMenu } = Menu; |
|
|
|
|
|
|
|
class BasicLayout extends React.PureComponent { |
|
|
|
static childContextTypes = { |
|
|
|
routes: PropTypes.array, |
|
|
|
params: PropTypes.object, |
|
|
|
location: PropTypes.object, |
|
|
|
breadcrumbNameMap: PropTypes.object, |
|
|
|
} |
|
|
|
constructor(props) { |
|
|
|
super(props); |
|
|
|
@ -29,8 +30,14 @@ class BasicLayout extends React.PureComponent { |
|
|
|
}; |
|
|
|
} |
|
|
|
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() { |
|
|
|
this.props.dispatch({ |
|
|
|
@ -98,13 +105,15 @@ class BasicLayout extends React.PureComponent { |
|
|
|
}); |
|
|
|
} |
|
|
|
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() { |
|
|
|
const { notices = [] } = this.props; |
|
|
|
@ -161,7 +170,7 @@ class BasicLayout extends React.PureComponent { |
|
|
|
} |
|
|
|
} |
|
|
|
render() { |
|
|
|
const { children, currentUser, collapsed, fetchingNotices } = this.props; |
|
|
|
const { currentUser, collapsed, fetchingNotices } = this.props; |
|
|
|
|
|
|
|
const menu = ( |
|
|
|
<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> |
|
|
|
); |
|
|
|
|
|
|
|
const noticeData = this.getNoticeData(); |
|
|
|
|
|
|
|
// Don't show popup menu when it is been collapsed
|
|
|
|
@ -270,7 +278,21 @@ class BasicLayout extends React.PureComponent { |
|
|
|
</div> |
|
|
|
</Header> |
|
|
|
<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 |
|
|
|
links={[{ |
|
|
|
title: '帮助', |
|
|
|
|