You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.2 KiB
125 lines
3.2 KiB
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import PropTypes from 'prop-types';
|
|
import { enquireScreen } from 'enquire-js';
|
|
import { addLocaleData, IntlProvider } from 'react-intl';
|
|
import 'moment/locale/zh-cn';
|
|
import { LocaleProvider } from 'antd';
|
|
import LogRocket from 'logrocket';
|
|
import setupLogRocketReact from 'logrocket-react';
|
|
import zhCN from 'antd/lib/locale-provider/zh_CN';
|
|
import Header from './Header';
|
|
import enLocale from '../../en-US';
|
|
import cnLocale from '../../zh-CN';
|
|
import * as utils from '../utils';
|
|
|
|
if (typeof window !== 'undefined' && navigator.serviceWorker) {
|
|
navigator.serviceWorker.getRegistrations().then(registrations => {
|
|
registrations.forEach(registration => registration.unregister());
|
|
});
|
|
}
|
|
|
|
if (typeof window !== 'undefined') {
|
|
/* eslint-disable global-require */
|
|
require('../../static/style');
|
|
|
|
// Expose to iframe
|
|
window.react = React;
|
|
window['react-dom'] = ReactDOM;
|
|
window.antd = require('antd');
|
|
/* eslint-enable global-require */
|
|
|
|
// Error log statistic
|
|
window.addEventListener('error', function onError(e) {
|
|
// Ignore ResizeObserver error
|
|
if (e.message === 'ResizeObserver loop limit exceeded') {
|
|
e.stopPropagation();
|
|
e.stopImmediatePropagation();
|
|
}
|
|
});
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
LogRocket.init('kpuw4z/ant-design');
|
|
setupLogRocketReact(LogRocket);
|
|
}
|
|
}
|
|
|
|
let isMobile = false;
|
|
enquireScreen(b => {
|
|
isMobile = b;
|
|
});
|
|
|
|
export default class Layout extends React.Component {
|
|
static contextTypes = {
|
|
router: PropTypes.object.isRequired,
|
|
};
|
|
|
|
static childContextTypes = {
|
|
isMobile: PropTypes.bool,
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
const { pathname } = props.location;
|
|
const appLocale = utils.isZhCN(pathname) ? cnLocale : enLocale;
|
|
addLocaleData(appLocale.data);
|
|
|
|
this.state = {
|
|
appLocale,
|
|
isMobile,
|
|
};
|
|
}
|
|
|
|
getChildContext() {
|
|
const { isMobile: mobile } = this.state;
|
|
return { isMobile: mobile };
|
|
}
|
|
|
|
componentDidMount() {
|
|
const { router } = this.context;
|
|
router.listen(loc => {
|
|
if (typeof window.ga !== 'undefined') {
|
|
window.ga('send', 'pageview', loc.pathname + loc.search);
|
|
}
|
|
// eslint-disable-next-line
|
|
if (typeof window._hmt !== 'undefined') {
|
|
// eslint-disable-next-line
|
|
window._hmt.push(['_trackPageview', loc.pathname + loc.search]);
|
|
}
|
|
});
|
|
|
|
const nprogressHiddenStyle = document.getElementById('nprogress-style');
|
|
if (nprogressHiddenStyle) {
|
|
this.timer = setTimeout(() => {
|
|
nprogressHiddenStyle.parentNode.removeChild(nprogressHiddenStyle);
|
|
}, 0);
|
|
}
|
|
|
|
enquireScreen(b => {
|
|
this.setState({
|
|
isMobile: !!b,
|
|
});
|
|
});
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
clearTimeout(this.timer);
|
|
}
|
|
|
|
render() {
|
|
const { children, ...restProps } = this.props;
|
|
const { appLocale } = this.state;
|
|
|
|
// Temp remove SentryBoundary
|
|
return (
|
|
<IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
|
|
<LocaleProvider locale={appLocale.locale === 'zh-CN' ? zhCN : null}>
|
|
<div className="page-wrapper">
|
|
<Header {...restProps} />
|
|
{children}
|
|
</div>
|
|
</LocaleProvider>
|
|
</IntlProvider>
|
|
);
|
|
}
|
|
}
|
|
|