2017-07-18 12:53:53 +08:00
|
|
|
import React, { Component } from 'react'
|
2017-07-19 15:12:10 +08:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { connect } from 'react-redux'
|
2017-07-20 14:48:29 +08:00
|
|
|
import wangEditor from 'wangeditor'
|
|
|
|
import { getReqParams } from '../../../actions/addInterface.js'
|
2017-07-24 10:59:17 +08:00
|
|
|
const editor = new wangEditor('#req-cover')
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-07-20 14:48:29 +08:00
|
|
|
getReqParams
|
2017-07-19 15:12:10 +08:00
|
|
|
}
|
|
|
|
)
|
2017-07-18 12:53:53 +08:00
|
|
|
|
|
|
|
class ReqParams extends Component {
|
2017-07-19 15:12:10 +08:00
|
|
|
static propTypes = {
|
2017-07-20 14:48:29 +08:00
|
|
|
reqParams: PropTypes.string,
|
|
|
|
getReqParams: PropTypes.func
|
2017-07-19 15:12:10 +08:00
|
|
|
}
|
|
|
|
|
2017-07-18 12:53:53 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
2017-07-24 10:59:17 +08:00
|
|
|
initParams () {
|
|
|
|
const { reqParams } = this.props
|
|
|
|
if (reqParams) {
|
|
|
|
editor.txt.html(reqParams)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 14:48:29 +08:00
|
|
|
componentDidMount () {
|
|
|
|
const reg = /(<p>)|(<\/p>)| |(<br>)|\s+/g
|
|
|
|
editor.customConfig.menus = []
|
|
|
|
editor.customConfig.onchange = html => {
|
|
|
|
html = html.replace(reg, '')
|
|
|
|
this.props.getReqParams(html)
|
2017-07-19 15:12:10 +08:00
|
|
|
}
|
2017-07-24 10:59:17 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
this.initParams()
|
|
|
|
}, 200)
|
2017-07-20 14:48:29 +08:00
|
|
|
editor.create()
|
2017-07-19 15:12:10 +08:00
|
|
|
}
|
2017-07-20 14:48:29 +08:00
|
|
|
|
2017-07-18 12:53:53 +08:00
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<section>
|
|
|
|
<div className="req-params">
|
|
|
|
<strong className="req-h3">请求参数 :</strong>
|
2017-07-20 14:48:29 +08:00
|
|
|
<div id="req-cover"></div>
|
2017-07-18 12:53:53 +08:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 14:48:29 +08:00
|
|
|
export default ReqParams
|