feat: componetWillMount

This commit is contained in:
zwjamnsss 2017-08-17 16:10:34 +08:00
parent 8f96c51614
commit a953d27d2f
4 changed files with 52 additions and 15 deletions

View File

@ -10,6 +10,7 @@ import InterfaceContent from './InterfaceList/InterfaceContent.js'
import InterfaceColMenu from './InterfaceCol/InterfaceColMenu.js' import InterfaceColMenu from './InterfaceCol/InterfaceColMenu.js'
import InterfaceColContent from './InterfaceCol/InterfaceColContent.js' import InterfaceColContent from './InterfaceCol/InterfaceColContent.js'
import InterfaceCaseContent from './InterfaceCol/InterfaceCaseContent.js'
const InterfaceRoute = (props) => { const InterfaceRoute = (props) => {
let C; let C;
@ -17,6 +18,8 @@ const InterfaceRoute = (props) => {
C = InterfaceContent; C = InterfaceContent;
} else if (props.match.params.action === 'col') { } else if (props.match.params.action === 'col') {
C = InterfaceColContent; C = InterfaceColContent;
} else if (props.match.params.action === 'case') {
C = InterfaceCaseContent;
} }
return <C /> return <C />
} }
@ -28,7 +31,8 @@ InterfaceRoute.propTypes = {
class Interface extends Component { class Interface extends Component {
static propTypes = { static propTypes = {
match: PropTypes.object match: PropTypes.object,
history: PropTypes.object
} }
constructor(props) { constructor(props) {
@ -36,20 +40,28 @@ class Interface extends Component {
this.state = { this.state = {
curkey: this.props.match.params.action curkey: this.props.match.params.action
} }
console.log(this.props)
} }
onChange = (key) => { // componentWillReceiveProps(nextProps) {
this.setState({ //
curkey: key // }
})
onChange = (action) => {
// this.setState({
// curkey: key
// })
let params = this.props.match.params;
this.props.history.push('/project/'+params.id + '/interface/' + action)
} }
render() { render() {
const action = this.props.match.params.action;
return <div className="web-content g-row" style={{ marginBottom: "15px" }}> return <div className="web-content g-row" style={{ marginBottom: "15px" }}>
<Row gutter={16} > <Row gutter={16} >
<Col span={6}> <Col span={6}>
<div className="left-menu"> <div className="left-menu">
<Tabs type="card" activeKey={this.state.curkey} onChange={this.onChange}> <Tabs type="card" activeKey={action} onChange={this.onChange}>
<Tabs.TabPane tab="接口列表" key="api"> <Tabs.TabPane tab="接口列表" key="api">
<InterfaceMenu projectId={this.props.match.params.id} /> <InterfaceMenu projectId={this.props.match.params.id} />
</Tabs.TabPane> </Tabs.TabPane>

View File

@ -10,6 +10,8 @@ import { Input, Icon, Tag, Modal, Row, Col, message, Tooltip, Tree } from 'antd'
const TextArea = Input.TextArea; const TextArea = Input.TextArea;
const TreeNode = Tree.TreeNode; const TreeNode = Tree.TreeNode;
import './InterfaceColMenu.scss'
@connect( @connect(
state => { state => {
return { return {
@ -28,7 +30,8 @@ export default class InterfaceColMenu extends Component {
match: PropTypes.object, match: PropTypes.object,
interfaceColList: PropTypes.array, interfaceColList: PropTypes.array,
fetchInterfaceColList: PropTypes.func, fetchInterfaceColList: PropTypes.func,
fetchInterfaceCaseList: PropTypes.func fetchInterfaceCaseList: PropTypes.func,
history: PropTypes.object
} }
state = { state = {
@ -41,10 +44,22 @@ export default class InterfaceColMenu extends Component {
super(props) super(props)
} }
componentWillMount() { async componentWillMount() {
this.props.fetchInterfaceColList(this.props.match.params.id) const result = await this.props.fetchInterfaceColList(this.props.match.params.id)
let params = this.props.match.params;
if(!params.actionId){
this.props.history.push('/project/'+params.id + '/interface/col/' + result.payload.data.data[0]._id)
}
} }
// async componentWillReceiveProps(nextProps) {
// const result = await nextProps.fetchInterfaceColList(nextProps.match.params.id)
// let params = nextProps.match.params;
// if(!params.actionId){
// nextProps.history.replace('/project/'+params.id + '/interface/col/' + result.payload.data.data[0]._id)
// }
// }
@autobind @autobind
async addCol() { async addCol() {
const { addColName: name, addColDesc: desc } = this.state; const { addColName: name, addColDesc: desc } = this.state;
@ -78,6 +93,7 @@ export default class InterfaceColMenu extends Component {
</Tooltip> </Tooltip>
</div> </div>
<Tree <Tree
className="col-list-tree"
defaultExpandedKeys={['0-0-0', '0-0-1']} defaultExpandedKeys={['0-0-0', '0-0-1']}
defaultSelectedKeys={['0-0-0', '0-0-1']} defaultSelectedKeys={['0-0-0', '0-0-1']}
onSelect={this.onSelect} onSelect={this.onSelect}
@ -91,6 +107,7 @@ export default class InterfaceColMenu extends Component {
{ {
col.caseList && col.caseList.map((interfaceCase) => ( col.caseList && col.caseList.map((interfaceCase) => (
<TreeNode <TreeNode
style={{width: '100%'}}
key={interfaceCase._id} key={interfaceCase._id}
title={interfaceCase.casename} title={interfaceCase.casename}
></TreeNode> ></TreeNode>

View File

@ -37,6 +37,10 @@ class Content extends Component {
this._actionId = 0; this._actionId = 0;
} }
componentWillMount() {
this.handleRequest(this.props)
}
componentWillReceiveProps(nextProps){ componentWillReceiveProps(nextProps){
this.handleRequest(nextProps) this.handleRequest(nextProps)
} }

View File

@ -73,6 +73,10 @@ class InterfaceMenu extends Component {
this.handleRequest() this.handleRequest()
} }
// componentWillReceiveProps() {
// this.handleRequest()
// }
handleAddInterface = (data) => { handleAddInterface = (data) => {
data.project_id = this.props.projectId; data.project_id = this.props.projectId;
axios.post('/api/interface/add', data).then((res) => { axios.post('/api/interface/add', data).then((res) => {