yapi/client/containers/AddInterface/ReqParams/ReqParams.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

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-26 12:31:42 +08:00
2017-07-24 10:59:17 +08:00
const editor = new wangEditor('#req-cover')
2017-07-26 12:31:42 +08:00
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>)|&nbsp;|(<br>)|\s+/g
2017-07-26 12:31:42 +08:00
let json = ''
2017-07-20 14:48:29 +08:00
editor.customConfig.menus = []
editor.customConfig.onchange = html => {
2017-07-26 12:31:42 +08:00
json = html.replace(reg, '')
this.props.getReqParams(json)
2017-07-19 15:12:10 +08:00
}
2017-07-24 10:59:17 +08:00
setTimeout(() => {
this.initParams()
2017-07-26 12:31:42 +08:00
}, 500)
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 (
2017-07-26 12:31:42 +08:00
<section className="req-params-box">
2017-07-18 12:53:53 +08:00
<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