yapi/client/containers/AddInterface/ReqParams/ReqParams.js

74 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-07-18 12:53:53 +08:00
import React, { Component } from 'react'
import { Button } from 'antd'
2017-07-19 15:12:10 +08:00
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
2017-07-18 12:53:53 +08:00
import ParamsList from './ParamsList.js'
2017-07-19 15:12:10 +08:00
import { autobind } from 'core-decorators'
import {
addReqParams
} from '../../../actions/addInterface.js'
2017-07-19 19:29:18 +08:00
// 重新渲染页面
const getReqList = function (self) {
const [reqList, reqParams] = [[], self.props.reqParams]
reqParams.map((value, key) => {
reqList.push(<ParamsList key={key} dataNum={value.id} />)
})
return reqList
}
2017-07-19 15:12:10 +08:00
@connect(
state => {
return {
2017-07-19 19:29:18 +08:00
reqParams: state.addInterface.reqParams
2017-07-19 15:12:10 +08:00
}
},
{
addReqParams
}
)
2017-07-18 12:53:53 +08:00
class ReqParams extends Component {
2017-07-19 15:12:10 +08:00
static propTypes = {
addReqParams: PropTypes.func,
2017-07-19 19:29:18 +08:00
reqParams: PropTypes.array
2017-07-19 15:12:10 +08:00
}
2017-07-18 12:53:53 +08:00
constructor(props) {
super(props)
}
2017-07-19 15:12:10 +08:00
@autobind
addSeqParams () {
2017-07-19 19:29:18 +08:00
console.log(1)
2017-07-19 15:12:10 +08:00
let newSeqParams= []
2017-07-19 19:29:18 +08:00
let reqParams = this.props.reqParams
let id = reqParams[reqParams.length-1].id
2017-07-19 15:12:10 +08:00
let list = {
id: ++id,
paramsName: '',
describe: ''
}
2017-07-19 19:29:18 +08:00
reqParams.push(list)
newSeqParams.push(...reqParams)
console.log(newSeqParams)
this.props.addReqParams(newSeqParams)
2017-07-19 15:12:10 +08:00
}
2017-07-18 12:53:53 +08:00
render () {
return (
<section>
<div className="req-params">
<strong className="req-h3">请求参数 :</strong>
<ul>
2017-07-19 19:29:18 +08:00
{ getReqList(this) }
2017-07-18 12:53:53 +08:00
</ul>
</div>
2017-07-19 15:12:10 +08:00
<Button type="primary" className="req-save" onClick={this.addSeqParams}>添加</Button>
2017-07-18 12:53:53 +08:00
</section>
)
}
}
export default ReqParams