yapi/client/containers/AddInterface/ReqHeader/ReqHeader.js

71 lines
1.4 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'
import { autobind } from 'core-decorators'
2017-07-18 12:53:53 +08:00
import ReqList from './ReqList.js'
2017-07-19 15:12:10 +08:00
import {
addReqHeader
} from '../../../actions/addInterface.js'
// 重新渲染页面
const getReqList = function (self) {
const [reqList, seqGroup] = [[], self.props.seqGroup]
seqGroup.map((value, key) => {
2017-07-24 10:59:17 +08:00
reqList.push(<ReqList key={key} value={value} dataNum={value.id} />)
2017-07-19 15:12:10 +08:00
})
return reqList
}
@connect(
state => {
return {
seqGroup: state.addInterface.seqGroup
}
},
{
addReqHeader
}
)
2017-07-18 12:53:53 +08:00
class ReqHeader extends Component {
2017-07-19 15:12:10 +08:00
static propTypes = {
seqGroup: PropTypes.array,
addReqHeader: PropTypes.func
}
2017-07-18 12:53:53 +08:00
constructor(props) {
super(props)
}
2017-07-19 15:12:10 +08:00
@autobind
addSeqGroup () {
let newSeqGroup = []
let seqGroup = this.props.seqGroup
let id = seqGroup[seqGroup.length-1].id
let list = {
id: ++id,
2017-07-24 10:59:17 +08:00
value: '',
name: ''
2017-07-19 15:12:10 +08:00
}
seqGroup.push(list)
newSeqGroup.push(...seqGroup)
this.props.addReqHeader(newSeqGroup)
}
2017-07-18 12:53:53 +08:00
render () {
return (
<section>
<div className="req-header">
<ul>
2017-07-19 15:12:10 +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.addSeqGroup}>添加</Button>
2017-07-18 12:53:53 +08:00
</section>
)
}
}
2017-07-19 15:12:10 +08:00
export default ReqHeader