yapi/client/containers/Project/Interface/Interface.js

115 lines
3.5 KiB
JavaScript
Raw Normal View History

2017-08-11 17:24:50 +08:00
import React, { Component } from 'react'
2017-08-11 18:57:58 +08:00
import PropTypes from 'prop-types'
2017-09-19 20:04:18 +08:00
import { Tabs, Layout } from 'antd';
2017-08-19 19:06:09 +08:00
import { Route, Switch, matchPath } from 'react-router-dom';
2017-08-21 10:38:16 +08:00
import { connect } from 'react-redux';
2017-09-21 14:15:42 +08:00
const { Content, Sider } = Layout;
2017-08-16 18:04:16 +08:00
2017-08-11 17:24:50 +08:00
import './interface.scss'
import InterfaceMenu from './InterfaceList/InterfaceMenu.js'
2017-08-18 20:35:31 +08:00
import InterfaceList from './InterfaceList/InterfaceList.js'
2017-08-11 17:24:50 +08:00
import InterfaceContent from './InterfaceList/InterfaceContent.js'
import InterfaceColMenu from './InterfaceCol/InterfaceColMenu.js'
import InterfaceColContent from './InterfaceCol/InterfaceColContent.js'
2017-08-17 16:10:34 +08:00
import InterfaceCaseContent from './InterfaceCol/InterfaceCaseContent.js'
import { getProject } from '../../../reducer/modules/project';
2017-08-19 19:06:09 +08:00
const contentRouter = {
path: '/project/:id/interface/:action/:actionId',
exact: true
}
const InterfaceRoute = (props) => {
let C;
if (props.match.params.action === 'api') {
2017-08-19 19:06:09 +08:00
if (!props.match.params.actionId) {
2017-08-18 20:35:31 +08:00
C = InterfaceList
2017-08-19 19:06:09 +08:00
} else if (!isNaN(props.match.params.actionId)) {
2017-08-18 20:35:31 +08:00
C = InterfaceContent;
2017-08-19 19:06:09 +08:00
} else if (props.match.params.actionId.indexOf('cat_') === 0) {
2017-08-18 20:35:31 +08:00
C = InterfaceList
}
} else if (props.match.params.action === 'col') {
C = InterfaceColContent;
2017-08-17 16:10:34 +08:00
} else if (props.match.params.action === 'case') {
C = InterfaceCaseContent;
2017-08-16 18:04:16 +08:00
}
2017-08-18 20:35:31 +08:00
return <C {...props} />
}
InterfaceRoute.propTypes = {
match: PropTypes.object
2017-08-16 18:04:16 +08:00
}
2017-08-21 10:38:16 +08:00
@connect(
state => {
return {
isShowCol: state.interfaceCol.isShowCol
}
},{
getProject
2017-08-21 10:38:16 +08:00
}
)
2017-08-11 17:24:50 +08:00
class Interface extends Component {
2017-08-11 18:57:58 +08:00
static propTypes = {
2017-08-17 16:10:34 +08:00
match: PropTypes.object,
2017-08-19 19:06:09 +08:00
history: PropTypes.object,
2017-08-21 10:38:16 +08:00
location: PropTypes.object,
isShowCol: PropTypes.bool,
getProject: PropTypes.func
2017-08-11 18:57:58 +08:00
}
2017-08-11 17:24:50 +08:00
constructor(props) {
2017-08-16 18:04:16 +08:00
super(props)
2017-08-11 17:24:50 +08:00
this.state = {
2017-08-16 18:04:16 +08:00
curkey: this.props.match.params.action
2017-08-11 17:24:50 +08:00
}
}
2017-08-17 16:10:34 +08:00
onChange = (action) => {
let params = this.props.match.params;
2017-08-21 10:38:16 +08:00
if(action === 'colOrCase') {
action = this.props.isShowCol ? 'col' : 'case';
}
2017-08-19 19:06:09 +08:00
this.props.history.push('/project/' + params.id + '/interface/' + action)
2017-08-11 17:24:50 +08:00
}
componentWillMount(){
this.props.getProject(this.props.match.params.id)
}
2017-08-11 17:24:50 +08:00
render() {
2017-08-17 20:58:43 +08:00
const { action } = this.props.match.params;
2017-08-18 17:31:48 +08:00
const activeKey = action === 'api' ? 'api' : 'colOrCase';
// console.log(matchPath(this.props.location.pathname, contentRouter));
2017-09-19 20:04:18 +08:00
return (
2017-09-22 19:40:51 +08:00
<Layout style={{minHeight: 'calc(100vh - 156px)', marginLeft: '24px', marginTop: '24px'}}>
<Sider style={{ height: '100%' }} width={300}>
2017-08-11 17:24:50 +08:00
<div className="left-menu">
2017-08-21 10:38:16 +08:00
<Tabs type="card" activeKey={activeKey} onChange={this.onChange}>
2017-08-16 18:04:16 +08:00
<Tabs.TabPane tab="接口列表" key="api">
2017-08-19 19:06:09 +08:00
<InterfaceMenu router={matchPath(this.props.location.pathname, contentRouter)} projectId={this.props.match.params.id} />
2017-08-11 17:24:50 +08:00
</Tabs.TabPane>
2017-08-22 09:41:20 +08:00
<Tabs.TabPane tab="测试集合" key="colOrCase" >
2017-08-11 17:24:50 +08:00
<InterfaceColMenu />
</Tabs.TabPane>
</Tabs>
</div>
2017-09-19 20:04:18 +08:00
</Sider>
2017-09-20 15:35:37 +08:00
<Layout>
2017-09-22 19:40:51 +08:00
<Content style={{ height: '100%', margin: '0 24px 0 16px', overflow: 'initial',backgroundColor: '#fff'}}>
2017-09-19 20:04:18 +08:00
<div className="right-content">
<Switch>
<Route exact path="/project/:id/interface/:action" component={InterfaceRoute} />
<Route {...contentRouter} component={InterfaceRoute} />
</Switch>
</div>
</Content>
</Layout>
</Layout>)
2017-08-11 17:24:50 +08:00
}
}
2017-08-16 18:04:16 +08:00
2017-08-17 16:10:34 +08:00
export default Interface