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

72 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'
import { autobind } from 'core-decorators'
2017-07-18 12:53:53 +08:00
import ReqList from './ReqList.js'
2017-08-07 19:34:34 +08:00
import {
2017-07-19 15:12:10 +08:00
addReqHeader
2017-08-08 10:07:55 +08:00
} from '../../../reducer/modules/addInterface.js'
2017-07-19 15:12:10 +08:00
// 重新渲染页面
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
2017-08-01 12:26:13 +08:00
let length = seqGroup.length
let id = length ? seqGroup[length-1].id : 0
2017-07-19 15:12:10 +08:00
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