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

66 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 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'
2017-07-26 12:31:42 +08:00
import { Tabs } from 'antd'
2017-07-20 14:48:29 +08:00
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-24 19:43:13 +08:00
const reg = /(<p>)|(<\/p>)|&nbsp;|(<br>)|\s+|<div>|<\/div>/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()
2017-07-24 19:43:13 +08:00
}, 400)
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 () {
2017-07-26 12:31:42 +08:00
const TabPane = Tabs.TabPane
2017-07-18 12:53:53 +08:00
return (
2017-07-26 12:31:42 +08:00
<section className="res-params-box">
<Tabs defaultActiveKey="1">
<TabPane tab="返回参数" key="1">
<div id="res-cover"></div>
</TabPane>
</Tabs>
2017-07-18 12:53:53 +08:00
</section>
)
}
}
2017-07-20 19:26:04 +08:00
export default ResParams