mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 13:08:41 +08:00
site: refactor, simplify code
This commit is contained in:
parent
b79fd5a540
commit
54ad570475
@ -25,25 +25,25 @@ module.exports = {
|
|||||||
component: './template/Layout/index',
|
component: './template/Layout/index',
|
||||||
indexRoute: { component: './template/Home/index' },
|
indexRoute: { component: './template/Home/index' },
|
||||||
childRoutes: [{
|
childRoutes: [{
|
||||||
path: '/docs/practice/:children',
|
path: 'docs/practice/:children',
|
||||||
component: contentTmpl,
|
component: contentTmpl,
|
||||||
}, {
|
}, {
|
||||||
path: '/docs/pattern/:children',
|
path: 'docs/pattern/:children',
|
||||||
component: contentTmpl,
|
component: contentTmpl,
|
||||||
}, {
|
}, {
|
||||||
path: '/docs/react/:children',
|
path: 'docs/react/:children',
|
||||||
component: contentTmpl,
|
component: contentTmpl,
|
||||||
}, {
|
}, {
|
||||||
path: '/changelog',
|
path: 'changelog',
|
||||||
component: contentTmpl,
|
component: contentTmpl,
|
||||||
}, {
|
}, {
|
||||||
path: '/components/:children',
|
path: 'components/:children',
|
||||||
component: contentTmpl,
|
component: contentTmpl,
|
||||||
}, {
|
}, {
|
||||||
path: '/docs/spec/:children',
|
path: 'docs/spec/:children',
|
||||||
component: contentTmpl,
|
component: contentTmpl,
|
||||||
}, {
|
}, {
|
||||||
path: '/docs/resource/:children',
|
path: 'docs/resource/:children',
|
||||||
component: contentTmpl,
|
component: contentTmpl,
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
@ -6,7 +6,6 @@ import ComponentDoc from './ComponentDoc';
|
|||||||
import * as utils from '../utils';
|
import * as utils from '../utils';
|
||||||
import config from '../../';
|
import config from '../../';
|
||||||
const SubMenu = Menu.SubMenu;
|
const SubMenu = Menu.SubMenu;
|
||||||
let firstMounted = false;
|
|
||||||
|
|
||||||
export default class MainContent extends React.Component {
|
export default class MainContent extends React.Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
@ -14,15 +13,17 @@ export default class MainContent extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (!location.hash) {
|
this.componentDidUpdate();
|
||||||
document.body.scrollTop = 0;
|
|
||||||
document.documentElement.scrollTop = 0;
|
|
||||||
} else if (!firstMounted) {
|
|
||||||
this.timer = setTimeout(() => {
|
this.timer = setTimeout(() => {
|
||||||
document.getElementById(decodeURI(location.hash.replace('#', ''))).scrollIntoView();
|
document.getElementById(decodeURI(location.hash.replace('#', ''))).scrollIntoView();
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
firstMounted = true;
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
if (!location.hash) {
|
||||||
|
document.body.scrollTop = 0;
|
||||||
|
document.documentElement.scrollTop = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -17,7 +17,6 @@ window.antd = require('antd');
|
|||||||
// Polyfill
|
// Polyfill
|
||||||
const areIntlLocalesSupported = require('intl-locales-supported');
|
const areIntlLocalesSupported = require('intl-locales-supported');
|
||||||
const localesMyAppSupports = ['zh-CN', 'en-US'];
|
const localesMyAppSupports = ['zh-CN', 'en-US'];
|
||||||
|
|
||||||
if (global.Intl) {
|
if (global.Intl) {
|
||||||
// Determine if the built-in `Intl` has the locale data we need.
|
// Determine if the built-in `Intl` has the locale data we need.
|
||||||
if (!areIntlLocalesSupported(localesMyAppSupports)) {
|
if (!areIntlLocalesSupported(localesMyAppSupports)) {
|
||||||
@ -49,39 +48,37 @@ export function collect(nextProps, callback) {
|
|||||||
.then((list) => callback(null, { ...nextProps, components: list }));
|
.then((list) => callback(null, { ...nextProps, components: list }));
|
||||||
}
|
}
|
||||||
|
|
||||||
let gaListenerSetted = false;
|
|
||||||
export default class Layout extends React.Component {
|
export default class Layout extends React.Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
router: React.PropTypes.object.isRequired,
|
router: React.PropTypes.object.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (typeof ga !== 'undefined' && !gaListenerSetted) {
|
if (typeof ga !== 'undefined') {
|
||||||
this.context.router.listen((loc) => {
|
this.context.router.listen((loc) => {
|
||||||
window.ga('send', 'pageview', loc.pathname + loc.search);
|
window.ga('send', 'pageview', loc.pathname + loc.search);
|
||||||
});
|
});
|
||||||
gaListenerSetted = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadingNode = document.getElementById('ant-site-loading');
|
const loadingNode = document.getElementById('ant-site-loading');
|
||||||
if (!loadingNode) {
|
if (loadingNode) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.timer = setTimeout(() => {
|
this.timer = setTimeout(() => {
|
||||||
loadingNode.parentNode.removeChild(loadingNode);
|
loadingNode.parentNode.removeChild(loadingNode);
|
||||||
}, 450);
|
}, 450);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const props = this.props;
|
const { children, ...restProps } = this.props;
|
||||||
return (
|
return (
|
||||||
<IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
|
<IntlProvider locale={appLocale.locale} messages={appLocale.messages}>
|
||||||
<div className="page-wrapper">
|
<div className="page-wrapper">
|
||||||
<Header {...props} />
|
<Header {...restProps} />
|
||||||
{props.children}
|
{children}
|
||||||
<Footer />
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
</IntlProvider>
|
</IntlProvider>
|
||||||
|
Loading…
Reference in New Issue
Block a user