ant-design/site/theme/template/Layout/index.jsx

59 lines
1.5 KiB
React
Raw Normal View History

import React from 'react';
import ReactDOM from 'react-dom';
import { addLocaleData, IntlProvider } from 'react-intl';
import Header from './Header';
import Footer from './Footer';
import enLocale from '../../en-US';
import cnLocale from '../../zh-CN';
import '../../static/style';
// Expose to iframe
window.react = React;
window['react-dom'] = ReactDOM;
2016-07-26 15:24:48 +08:00
window.antd = require('antd');
2016-09-10 11:19:03 +08:00
const language = (typeof localStorage === 'undefined' || !localStorage.getItem('locale')) ?
navigator.language : localStorage.getItem('locale');
const isZhCN = language === 'zh-CN';
const appLocale = isZhCN ? cnLocale : enLocale;
addLocaleData(appLocale.data);
2016-06-03 15:26:25 +08:00
export default class Layout extends React.Component {
static contextTypes = {
router: React.PropTypes.object.isRequired,
}
componentDidMount() {
2016-07-26 17:40:08 +08:00
if (typeof ga !== 'undefined') {
2016-06-03 15:26:25 +08:00
this.context.router.listen((loc) => {
window.ga('send', 'pageview', loc.pathname + loc.search);
});
}
2016-07-26 17:40:08 +08:00
2016-06-23 21:10:02 +08:00
const loadingNode = document.getElementById('ant-site-loading');
2016-07-26 17:40:08 +08:00
if (loadingNode) {
this.timer = setTimeout(() => {
loadingNode.parentNode.removeChild(loadingNode);
}, 450);
2016-06-23 21:10:02 +08:00
}
}
componentWillUnmount() {
clearTimeout(this.timer);
2016-06-03 15:26:25 +08:00
}
render() {
2016-07-26 17:40:08 +08:00
const { children, ...restProps } = this.props;
2016-06-03 15:26:25 +08:00
return (
<IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
<div className="page-wrapper">
2016-07-26 17:40:08 +08:00
<Header {...restProps} />
{children}
2016-06-03 15:26:25 +08:00
<Footer />
</div>
</IntlProvider>
);
}
}