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.

148 lines
4.3 KiB

import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import { enquireScreen } from 'enquire-js';
import { IntlProvider } from 'react-intl';
import { Helmet } from 'react-helmet';
import 'moment/locale/zh-cn';
import { ConfigProvider } from 'antd';
import LogRocket from 'logrocket';
import setupLogRocketReact from 'logrocket-react';
// eslint-disable-next-line import/no-unresolved
import zhCN from 'antd/es/locale/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) {
6 years ago
navigator.serviceWorker.getRegistrations().then(registrations => {
registrations.forEach(registration => registration.unregister());
});
}
if (typeof window !== 'undefined') {
// eslint-disable-next-line global-require
require('../../static/style');
// Expose to iframe
window.react = React;
window['react-dom'] = ReactDOM;
// eslint-disable-next-line global-require
window.antd = require('antd');
6 years ago
// Error log statistic
window.addEventListener('error', function onError(e) {
6 years ago
// 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;
6 years ago
enquireScreen(b => {
isMobile = b;
});
9 years ago
export default class Layout extends React.Component {
static contextTypes = {
router: PropTypes.object.isRequired,
6 years ago
};
static childContextTypes = {
7 years ago
isMobile: PropTypes.bool,
};
constructor(props) {
super(props);
const { pathname } = props.location;
const appLocale = utils.isZhCN(pathname) ? cnLocale : enLocale;
this.state = {
appLocale,
isMobile,
};
}
getChildContext() {
const { isMobile: mobile } = this.state;
return { isMobile: mobile };
}
9 years ago
componentDidMount() {
const { router } = this.context;
6 years ago
router.listen(loc => {
if (typeof window.ga !== 'undefined') {
9 years ago
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);
}
6 years ago
enquireScreen(b => {
this.setState({
isMobile: !!b,
});
});
}
componentWillUnmount() {
clearTimeout(this.timer);
9 years ago
}
render() {
const { children, ...restProps } = this.props;
const { appLocale } = this.state;
const title =
appLocale.locale === 'zh-CN'
? 'Ant Design - 一套企业级的 UI 设计语言和 React 组件'
: 'Ant Design - A UI Design Language';
const description =
appLocale.locale === 'zh-CN'
? '一套企业级的 UI 设计语言和 React 组件。'
: 'An enterprise-class UI design language and React implementation with a set of high-quality React components, one of best React UI library for enterprises';
9 years ago
return (
<>
<Helmet>
<html lang={appLocale.locale === 'zh-CN' ? 'zh' : 'en'} />
5 years ago
{/* lack CN title */}
<title>{title}</title>
5 years ago
{/* lack CN desc */}
<meta name="description" content={description} />
<meta property="og:title" content={title} />
5 years ago
<meta property="og:type" content="website" />
<meta
property="og:image"
content="https://gw.alipayobjects.com/zos/rmsportal/rlpTLlbMzTNYuZGGCVYM.png"
/>
</Helmet>
<IntlProvider locale={appLocale.locale} messages={appLocale.messages} defaultLocale="en-US">
<ConfigProvider locale={appLocale.locale === 'zh-CN' ? zhCN : null}>
<div className="page-wrapper">
<Header {...restProps} />
{children}
</div>
</ConfigProvider>
</IntlProvider>
</>
9 years ago
);
}
}