1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* eslint-disable no-undef */
import React from 'react';
import { Spin, Tree } from 'antd';
import { connect } from 'dva';
import { Route, Switch, routerRedux } from 'dva/router';
import { makeAsync } from 'react-async-wrapper';
import 'github-markdown-css';
import { withSize } from '../../../../components/hoc/size';
import { userApi } from '../../../../services/interfaces';
import { processError } from '../../../../utils/error';
import styles from './index.less';
import mdIndex from './index.md';
import mdAuth from './auth.md';
import mdDomain from './domain.md';
import mdFile from './file.md';
import mdDyInt from './dynamic-interface/index.md';
import mdError from './error.md';
import createPages from './dynamic-interface';
import md from './markdown';
const TreeNode = Tree.TreeNode;
class DocMainPage extends React.PureComponent {
onSelect = match => (ignored, e) => {
const key = e.node.props.eventKey;
this.props.dispatch(routerRedux.push(`${match.url}/${key}`));
};
render() {
const { match, size, infoes, loading } = this.props;
const pages = loading ? [] : createPages(match, infoes, size);
return (
<Spin spinning={loading} style={{ height: size.height, maxHeight: size.height }}>
<div className={styles.main} style={{ height: size.height }}>
<div className={styles.leftMenu}>
<Tree defaultExpandAll onSelect={this.onSelect(match)}>
<TreeNode title="前置说明" key="index" />
<TreeNode title="登录与认证" key="auth" />
<TreeNode title="作用域" key="domain" />
<TreeNode title="文件管理" key="file" />
<TreeNode title="动态接口" key="interface">
{
pages.map(page => (
<TreeNode title={page.showName} key={page.key} />
))
}
</TreeNode>
<TreeNode title="错误码" key="error" />
</Tree>
</div>
<div className={styles.contents}>
<Switch>
<Route path={`${match.path}/index`} component={md(mdIndex)} />
<Route path={`${match.path}/auth`} component={md(mdAuth)} />
<Route path={`${match.path}/domain`} component={md(mdDomain)} />
<Route path={`${match.path}/file`} component={md(mdFile)} />
<Route path={`${match.path}/interface`} exact component={md(mdDyInt)} />
{
pages.map(page => (
<Route key={page.name} path={page.path} render={page.render} />
))
}
<Route path={`${match.path}/error`} component={md(mdError)} />
</Switch>
</div>
</div>
</Spin>
);
}
}
export default makeAsync({
batch: true,
onError: processError,
asyncProps: {
infoes: async () => userApi.getAllInterfaceInfoes(),
},
})(withSize(connect()(DocMainPage)));