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

103 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-08-16 18:04:16 +08:00
import React, { Component } from 'react'
import { connect } from 'react-redux';
import PropTypes from 'prop-types'
2017-08-11 17:25:57 +08:00
import { Tabs } from 'antd';
import Edit from './Edit.js'
import View from './View.js'
2017-08-17 11:26:20 +08:00
2017-08-16 18:04:16 +08:00
import { fetchInterfaceData } from '../../../../reducer/modules/interface.js';
import { withRouter } from 'react-router-dom';
2017-08-17 10:17:33 +08:00
import Run from './Run/Run.js'
2017-08-11 17:25:57 +08:00
const TabPane = Tabs.TabPane;
2017-08-16 18:04:16 +08:00
@connect(
state => {
return {
curdata: state.inter.curdata,
list: state.inter.list
}
},
{
2017-08-17 16:10:34 +08:00
fetchInterfaceData
2017-08-16 18:04:16 +08:00
}
)
class Content extends Component {
static propTypes = {
match: PropTypes.object,
list: PropTypes.array,
curdata: PropTypes.object,
2017-08-17 18:00:02 +08:00
fetchInterfaceData: PropTypes.func,
history: PropTypes.object
2017-08-16 18:04:16 +08:00
}
constructor(props) {
super(props)
this.state = {
curtab: 'view'
}
}
2017-08-11 17:25:57 +08:00
2017-08-17 16:10:34 +08:00
componentWillMount() {
2017-08-19 19:06:09 +08:00
const params = this.props.match.params;
this.actionId = params.actionId;
this.handleRequest(this.props);
}
componentWillReceiveProps(nextProps) {
const params = nextProps.match.params;
if(params.actionId !== this.actionId){
this.actionId = params.actionId;
this.handleRequest(nextProps)
2017-08-22 09:43:33 +08:00
}
2017-08-17 16:10:34 +08:00
}
2017-08-17 18:00:02 +08:00
handleRequest(nextProps) {
2017-08-19 19:06:09 +08:00
const params = nextProps.match.params;
this.props.fetchInterfaceData(params.actionId)
2017-08-16 18:04:16 +08:00
this.setState({
curtab: 'view'
})
}
2017-08-21 12:05:18 +08:00
switchToView = ()=>{
this.setState({
curtab: 'view'
})
}
2017-08-17 18:00:02 +08:00
onChange = (key) => {
2017-08-16 18:04:16 +08:00
this.setState({
curtab: key
})
}
render() {
const tabs = <Tabs onChange={this.onChange} activeKey={this.state.curtab} defaultActiveKey="view" >
<TabPane tab="预览" key="view">
{/* <View /> */}
2017-08-11 17:25:57 +08:00
</TabPane>
2017-08-16 18:04:16 +08:00
<TabPane tab="编辑" key="edit">
2017-08-11 17:25:57 +08:00
</TabPane>
2017-08-16 18:04:16 +08:00
<TabPane tab="运行" key="run">
{/* <Run /> */}
2017-08-11 17:25:57 +08:00
</TabPane>
2017-08-16 18:04:16 +08:00
</Tabs>;
let tabContent;
if (this.state.curtab === 'view') {
tabContent = <View />;
} else if (this.state.curtab === 'edit') {
2017-08-21 12:05:18 +08:00
tabContent = <Edit switchToView={this.switchToView} />
2017-08-16 18:04:16 +08:00
} else if (this.state.curtab === 'run') {
tabContent = <Run />
}
return <div className="interface-content">
{tabs}
{tabContent}
</div>
}
2017-08-11 17:25:57 +08:00
}
2017-08-17 11:26:20 +08:00
export default withRouter(Content)