yapi/client/containers/AddInterface/ResParams/ResParams.js

63 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-07-18 12:53:53 +08:00
import React, { Component } from 'react'
2017-07-19 19:29:18 +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 { getResParams } from '../../../actions/addInterface.js'
2017-07-19 19:29:18 +08:00
2017-07-24 10:59:17 +08:00
const editor = new wangEditor('#res-cover')
2017-07-19 19:29:18 +08:00
@connect(
state => {
return {
resParams: state.addInterface.resParams
}
},
{
2017-07-20 14:48:29 +08:00
getResParams
2017-07-19 19:29:18 +08:00
}
)
2017-07-18 12:53:53 +08:00
class ResParams extends Component {
2017-07-19 19:29:18 +08:00
static propTypes = {
2017-07-20 14:48:29 +08:00
resParams: PropTypes.string,
getResParams: PropTypes.func
2017-07-19 19:29:18 +08:00
}
2017-07-18 12:53:53 +08:00
constructor(props) {
super(props)
}
2017-07-24 10:59:17 +08:00
initResParams () {
const { resParams } = this.props
if (resParams) {
editor.txt.html(resParams)
}
}
2017-07-20 14:48:29 +08:00
componentDidMount () {
2017-07-20 19:26:04 +08:00
const reg = /(<p>)|(<\/p>)|&nbsp;|(<br>)|\s+/g
2017-07-20 14:48:29 +08:00
editor.customConfig.menus = []
editor.customConfig.onchange = html => {
2017-07-20 19:26:04 +08:00
html = html.replace(reg, '')
2017-07-20 14:48:29 +08:00
this.props.getResParams(html)
2017-07-19 19:29:18 +08:00
}
2017-07-24 10:59:17 +08:00
setTimeout(() => {
this.initResParams()
}, 200)
2017-07-20 14:48:29 +08:00
editor.create()
2017-07-19 19:29:18 +08:00
}
2017-07-18 12:53:53 +08:00
render () {
return (
<section>
<div className="res-params">
<strong className="res-h3">返回参数 :</strong>
2017-07-20 14:48:29 +08:00
<div id="res-cover"></div>
2017-07-18 12:53:53 +08:00
</div>
</section>
)
}
}
2017-07-20 19:26:04 +08:00
export default ResParams