import React from 'react'; import PropTypes from 'prop-types'; import { Layout, Icon, message } 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 { enquireScreen } from 'enquire-js'; import GlobalHeader from '../components/GlobalHeader'; import GlobalFooter from '../components/GlobalFooter'; import SiderMenu from '../components/SiderMenu'; import NotFound from '../routes/Exception/404'; import { getRoutes } from '../utils/utils'; import Authorized from '../utils/Authorized'; import { getMenuData } from '../common/menu'; import logo from '../assets/logo.svg'; const { Content } = Layout; const { AuthorizedRoute } = Authorized; /** * 根据菜单取得重定向地址. */ const redirectData = []; const getRedirect = (item) => { if (item && item.children) { if (item.children[0] && item.children[0].path) { redirectData.push({ from: `/${item.path}`, to: `/${item.children[0].path}`, }); item.children.forEach((children) => { getRedirect(children); }); } } }; getMenuData().forEach(getRedirect); 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, }, }; let isMobile; enquireScreen((b) => { isMobile = b; }); class BasicLayout extends React.PureComponent { static childContextTypes = { location: PropTypes.object, breadcrumbNameMap: PropTypes.object, } state = { isMobile, }; getChildContext() { const { location, routerData } = this.props; return { location, breadcrumbNameMap: routerData, }; } componentDidMount() { enquireScreen((mobile) => { this.setState({ isMobile: mobile, }); }); this.props.dispatch({ type: 'user/fetchCurrent', }); } getPageTitle() { const { routerData, location } = this.props; const { pathname } = location; let title = 'Ant Design Pro'; if (routerData[pathname] && routerData[pathname].name) { title = `${routerData[pathname].name} - Ant Design Pro`; } return title; } handleMenuCollapse = (collapsed) => { this.props.dispatch({ type: 'global/changeLayoutCollapsed', payload: collapsed, }); } handleNoticeClear = (type) => { message.success(`清空了${type}`); this.props.dispatch({ type: 'global/clearNotices', payload: type, }); } handleMenuClick = ({ key }) => { if (key === 'logout') { this.props.dispatch({ type: 'login/logout', }); } } handleNoticeVisibleChange = (visible) => { if (visible) { this.props.dispatch({ type: 'global/fetchNotices', }); } } render() { const { currentUser, collapsed, fetchingNotices, notices, routerData, match, location, } = this.props; const layout = (
{ getRoutes(match.path, routerData).map(item => ( ) ) } { redirectData.map(item => ) }
, href: 'https://github.com/ant-design/ant-design-pro', blankTarget: true, }, { key: 'Ant Design', title: 'Ant Design', href: 'http://ant.design', blankTarget: true, }]} copyright={
Copyright 2017 蚂蚁金服体验技术部出品
} />
); return ( {params =>
{layout}
}
); } } export default connect(state => ({ currentUser: state.user.currentUser, collapsed: state.global.collapsed, fetchingNotices: state.global.fetchingNotices, notices: state.global.notices, }))(BasicLayout);