2017-07-18 12:53:53 +08:00
|
|
|
import React, { Component } from 'react'
|
2017-07-24 19:43:13 +08:00
|
|
|
import { Select, Input, Icon } 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'
|
|
|
|
import {
|
|
|
|
reqTagValue,
|
|
|
|
reqHeaderValue,
|
|
|
|
deleteReqHeader
|
|
|
|
} from '../../../actions/addInterface.js'
|
|
|
|
|
|
|
|
@connect(
|
|
|
|
state => {
|
|
|
|
return {
|
|
|
|
seqGroup: state.addInterface.seqGroup,
|
|
|
|
reqTagValue: state.addInterface.reqTagValue,
|
|
|
|
reqHeaderValue: state.addInterface.reqHeaderValue
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
reqTagValue,
|
|
|
|
reqHeaderValue,
|
|
|
|
deleteReqHeader
|
|
|
|
}
|
|
|
|
)
|
2017-07-18 12:53:53 +08:00
|
|
|
|
|
|
|
class ReqList extends Component {
|
2017-07-19 15:12:10 +08:00
|
|
|
static propTypes = {
|
|
|
|
seqGroup: PropTypes.array,
|
|
|
|
reqTagValue: PropTypes.func,
|
|
|
|
reqHeaderValue: PropTypes.func,
|
|
|
|
deleteReqHeader: PropTypes.func,
|
2017-07-24 10:59:17 +08:00
|
|
|
_id: PropTypes.number,
|
|
|
|
dataNum: PropTypes.number,
|
|
|
|
value: PropTypes.object
|
2017-07-19 15:12:10 +08:00
|
|
|
}
|
|
|
|
|
2017-07-18 12:53:53 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
2017-07-19 19:29:18 +08:00
|
|
|
@autobind
|
2017-07-19 15:12:10 +08:00
|
|
|
handleChange (value) {
|
2017-07-24 10:59:17 +08:00
|
|
|
const dir = 'AddInterface/edit'
|
|
|
|
const url = location.href
|
|
|
|
if (url.includes(dir)) {
|
|
|
|
const { seqGroup, value: { id } } = this.props
|
|
|
|
seqGroup[id].name = value
|
|
|
|
} else {
|
|
|
|
const { seqGroup, dataNum } = this.props
|
|
|
|
seqGroup[dataNum].name = value
|
|
|
|
}
|
2017-07-19 15:12:10 +08:00
|
|
|
}
|
|
|
|
|
2017-07-19 19:29:18 +08:00
|
|
|
@autobind
|
2017-07-19 15:12:10 +08:00
|
|
|
handleBlur (e) {
|
|
|
|
const value = e.target.value
|
2017-07-24 10:59:17 +08:00
|
|
|
const { seqGroup, value: { id } } = this.props
|
|
|
|
seqGroup[id].value = value
|
2017-07-19 15:12:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
2017-07-24 10:59:17 +08:00
|
|
|
deleteReqHeader () {
|
2017-07-19 15:12:10 +08:00
|
|
|
let newSeqGroup = []
|
|
|
|
let seqGroup = this.props.seqGroup
|
2017-07-24 10:59:17 +08:00
|
|
|
let id = this.props.value.id
|
2017-07-24 19:43:13 +08:00
|
|
|
|
2017-07-19 15:12:10 +08:00
|
|
|
seqGroup.map(value => {
|
2017-07-24 10:59:17 +08:00
|
|
|
if (+id !== value.id) {
|
2017-07-19 15:12:10 +08:00
|
|
|
newSeqGroup.push(value)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.props.deleteReqHeader(newSeqGroup)
|
|
|
|
}
|
|
|
|
|
2017-07-18 12:53:53 +08:00
|
|
|
render () {
|
2017-07-24 10:59:17 +08:00
|
|
|
const propsValue = this.props.value
|
2017-07-18 12:53:53 +08:00
|
|
|
const Option = Select.Option
|
2017-07-24 10:59:17 +08:00
|
|
|
const value = propsValue.value
|
2017-07-26 12:31:42 +08:00
|
|
|
const name = propsValue.name || ''
|
2017-07-18 12:53:53 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<li>
|
2017-07-24 10:59:17 +08:00
|
|
|
<em className="title">头部标签</em>
|
|
|
|
<Select defaultValue={name} style={{ width: 220 }} onChange={this.handleChange} size="large">
|
2017-07-26 12:31:42 +08:00
|
|
|
<Option value="">选择请求头</Option>
|
2017-07-24 10:59:17 +08:00
|
|
|
<Option value="Accept">Accept</Option>
|
2017-07-18 12:53:53 +08:00
|
|
|
<Option value="Accept-Charset">Accept-Charset</Option>
|
|
|
|
<Option value="Accept-Encoding">Accept-Encoding</Option>
|
|
|
|
<Option value="Accept-Language">Accept-Language</Option>
|
|
|
|
<Option value="Accept-Ranges">Accept-Ranges</Option>
|
|
|
|
</Select>
|
|
|
|
<em className="title">头部内容</em>
|
2017-07-24 10:59:17 +08:00
|
|
|
<Input defaultValue={value} placeholder="Basic usage" className="req-content" size="large" onBlur={this.handleBlur} />
|
2017-07-24 19:43:13 +08:00
|
|
|
<Icon className="dynamic-delete-button" type="minus-circle-o" onClick={this.deleteReqHeader} />
|
2017-07-18 12:53:53 +08:00
|
|
|
</li>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ReqList
|