mock平台

Interface.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import React, { PureComponent as Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Tabs, Layout } from 'antd';
  4. import { Route, Switch, matchPath } from 'react-router-dom';
  5. import { connect } from 'react-redux';
  6. const { Content, Sider } = Layout;
  7. import './interface.scss';
  8. import InterfaceMenu from './InterfaceList/InterfaceMenu.js';
  9. import InterfaceList from './InterfaceList/InterfaceList.js';
  10. import InterfaceContent from './InterfaceList/InterfaceContent.js';
  11. import InterfaceColMenu from './InterfaceCol/InterfaceColMenu.js';
  12. import InterfaceColContent from './InterfaceCol/InterfaceColContent.js';
  13. import InterfaceCaseContent from './InterfaceCol/InterfaceCaseContent.js';
  14. import { getProject } from '../../../reducer/modules/project';
  15. import { setColData } from '../../../reducer/modules/interfaceCol.js';
  16. const contentRouter = {
  17. path: '/project/:id/interface/:action/:actionId',
  18. exact: true
  19. };
  20. const InterfaceRoute = props => {
  21. let C;
  22. if (props.match.params.action === 'api') {
  23. if (!props.match.params.actionId) {
  24. C = InterfaceList;
  25. } else if (!isNaN(props.match.params.actionId)) {
  26. C = InterfaceContent;
  27. } else if (props.match.params.actionId.indexOf('cat_') === 0) {
  28. C = InterfaceList;
  29. }
  30. } else if (props.match.params.action === 'col') {
  31. C = InterfaceColContent;
  32. } else if (props.match.params.action === 'case') {
  33. C = InterfaceCaseContent;
  34. } else {
  35. const params = props.match.params;
  36. props.history.replace('/project/' + params.id + '/interface/api');
  37. return null;
  38. }
  39. return <C {...props} />;
  40. };
  41. InterfaceRoute.propTypes = {
  42. match: PropTypes.object,
  43. history: PropTypes.object
  44. };
  45. @connect(
  46. state => {
  47. return {
  48. isShowCol: state.interfaceCol.isShowCol
  49. };
  50. },
  51. {
  52. setColData,
  53. getProject
  54. }
  55. )
  56. class Interface extends Component {
  57. static propTypes = {
  58. match: PropTypes.object,
  59. history: PropTypes.object,
  60. location: PropTypes.object,
  61. isShowCol: PropTypes.bool,
  62. getProject: PropTypes.func,
  63. setColData: PropTypes.func
  64. // fetchInterfaceColList: PropTypes.func
  65. };
  66. constructor(props) {
  67. super(props);
  68. // this.state = {
  69. // curkey: this.props.match.params.action === 'api' ? 'api' : 'colOrCase'
  70. // }
  71. }
  72. onChange = action => {
  73. let params = this.props.match.params;
  74. if (action === 'colOrCase') {
  75. action = this.props.isShowCol ? 'col' : 'case';
  76. }
  77. this.props.history.push('/project/' + params.id + '/interface/' + action);
  78. };
  79. async componentWillMount() {
  80. this.props.setColData({
  81. isShowCol: true
  82. });
  83. // await this.props.fetchInterfaceColList(this.props.match.params.id)
  84. }
  85. render() {
  86. const { action } = this.props.match.params;
  87. // const activeKey = this.state.curkey;
  88. const activeKey = action === 'api' ? 'api' : 'colOrCase';
  89. return (
  90. <Layout style={{ minHeight: 'calc(100vh - 156px)', marginLeft: '24px', marginTop: '24px' }}>
  91. <Sider style={{ height: '100%' }} width={300}>
  92. <div className="left-menu">
  93. <Tabs type="card" className="tabs-large" activeKey={activeKey} onChange={this.onChange}>
  94. <Tabs.TabPane tab="接口列表" key="api" />
  95. <Tabs.TabPane tab="测试集合" key="colOrCase" />
  96. </Tabs>
  97. {activeKey === 'api' ? (
  98. <InterfaceMenu
  99. router={matchPath(this.props.location.pathname, contentRouter)}
  100. projectId={this.props.match.params.id}
  101. />
  102. ) : (
  103. <InterfaceColMenu
  104. router={matchPath(this.props.location.pathname, contentRouter)}
  105. projectId={this.props.match.params.id}
  106. />
  107. )}
  108. </div>
  109. </Sider>
  110. <Layout>
  111. <Content
  112. style={{
  113. height: '100%',
  114. margin: '0 24px 0 16px',
  115. overflow: 'initial',
  116. backgroundColor: '#fff'
  117. }}
  118. >
  119. <div className="right-content">
  120. <Switch>
  121. <Route exact path="/project/:id/interface/:action" component={InterfaceRoute} />
  122. <Route {...contentRouter} component={InterfaceRoute} />
  123. </Switch>
  124. </div>
  125. </Content>
  126. </Layout>
  127. </Layout>
  128. );
  129. }
  130. }
  131. export default Interface;