import * as React from 'react' ; import { TITLE_CONFIG } from 'config' ; import * as PropTypes from 'prop-types' ; import { Layout } from 'antd' ; import Header from './header' ; import Nav from './nav' ; import commonStore from '@/store/common' ; import './index.less' ; export default class LayoutIndex extends React . Component { public static contextTypes = { router : PropTypes . shape ( { history : PropTypes . object . isRequired } ) . isRequired } ; public componentDidMount ( ) { const titles = TITLE_CONFIG ; const titlesKey = Object . keys ( titles ) ; this . onMappingTitles ( titlesKey , titles ) ; this . context . router . history . listen ( ( ) => { this . onMappingTitles ( titlesKey , titles ) ; } ) ; } public onMappingTitles = ( titlesKey , titles ) => { const arr = titlesKey . filter ( v => new RegExp ( v ) . test ( this . context . router . history . location . pathname ) ) ; document . title = titles [ arr [ arr . length - 1 ] ] ; if ( ! commonStore . currentCenterConfig ) { commonStore . currentCenterConfig = commonStore . swaggerApiConfig . filter ( ( v ) => new RegExp ( v . name ) . test ( this . context . router . history . location . pathname ) ) [ 0 ] ; } } ; public render ( ) { return ( < div className = "layout-container" > < Layout > < Nav common = { commonStore } /> < Layout > < Header common = { commonStore } history = { this . context . router . history } / > < div className = "layout-content-wrapper" > < Layout . Content style = { { margin : '24px 16px' , padding : 24 , background : '#fff' , minHeight : 280 } } > { this . props . children } < /Layout.Content> < /div> < /Layout> < /Layout> < /div>); } }