yapi/client/containers/AddInterface/ReqParams/ReqParams.js
2017-07-24 10:59:17 +08:00

61 lines
1.2 KiB
JavaScript

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import wangEditor from 'wangeditor'
import { getReqParams } from '../../../actions/addInterface.js'
const editor = new wangEditor('#req-cover')
@connect(
state => {
return {
reqParams: state.addInterface.reqParams
}
},
{
getReqParams
}
)
class ReqParams extends Component {
static propTypes = {
reqParams: PropTypes.string,
getReqParams: PropTypes.func
}
constructor(props) {
super(props)
}
initParams () {
const { reqParams } = this.props
if (reqParams) {
editor.txt.html(reqParams)
}
}
componentDidMount () {
const reg = /(<p>)|(<\/p>)|&nbsp;|(<br>)|\s+/g
editor.customConfig.menus = []
editor.customConfig.onchange = html => {
html = html.replace(reg, '')
this.props.getReqParams(html)
}
setTimeout(() => {
this.initParams()
}, 200)
editor.create()
}
render () {
return (
<section>
<div className="req-params">
<strong className="req-h3">请求参数 :</strong>
<div id="req-cover"></div>
</div>
</section>
)
}
}
export default ReqParams