import React from 'react';
import PropTypes from 'prop-types';
import { Layout } 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 SiderMenu from '../components/SiderMenu';
import NotFound from '../routes/Exception/404';
import { getRoutes } from '../utils/utils';
import Authorized from '../utils/Authorized';
import Sidebar from '../components/Sidebar';
import logo from '../assets/logo.svg';
import Footer from './Footer';
import Header from './Header';
const { Content } = Layout;
const { AuthorizedRoute } = Authorized;
const RightSidebar = connect(({ setting }) => ({ ...setting }))(Sidebar);
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,
};
getChildContext() {
const { location, routerData } = this.props;
return {
location,
breadcrumbNameMap: routerData,
};
}
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;
}
getBashRedirect = () => {
// According to the url parameter to redirect
// 这里是重定向的,重定向到 url 的 redirect 参数所示地址
const urlParams = new URL(window.location.href);
const redirect = urlParams.searchParams.get('redirect');
// Remove the parameters in the url
if (redirect) {
urlParams.searchParams.delete('redirect');
window.history.replaceState(null, 'redirect', urlParams.href);
} else {
return '/dashboard/analysis';
}
return redirect;
};
handleMenuCollapse = (collapsed) => {
this.props.dispatch({
type: 'global/changeLayoutCollapsed',
payload: collapsed,
});
};
changeSetting = (setting) => {
this.props.dispatch({
type: 'setting/changeSetting',
payload: setting,
});
}
render() {
const {
isMobile,
redirectData,
routerData,
fixedHeader,
match,
} = this.props;
const isTop = this.props.layout === 'topmenu';
const bashRedirect = this.getBashRedirect();
const myRedirectData = redirectData || [];
const layout = (
{isTop && !isMobile ? null : (
)}
{myRedirectData.map(item => (
))}
{getRoutes(match.path, routerData).map(item => (
))}
);
return (
{params => (
{layout}
)}
);
}
}
export default connect(({ global, setting }) => ({
collapsed: global.collapsed,
layout: setting.layout,
...setting,
}))(BasicLayout);