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-27 20:35:19 +08:00
|
|
|
// import wangEditor from 'wangeditor'
|
2017-07-27 20:06:49 +08:00
|
|
|
import { Card } 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-27 19:32:08 +08:00
|
|
|
//const editor = new wangEditor('#res-cover')
|
|
|
|
|
|
|
|
|
2017-07-24 10:59:17 +08:00
|
|
|
|
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-27 19:32:08 +08:00
|
|
|
// initResParams () {
|
|
|
|
// const { resParams } = this.props
|
|
|
|
// if (resParams) {
|
|
|
|
// editor.txt.html(resParams)
|
|
|
|
// }
|
|
|
|
// }
|
2017-07-24 10:59:17 +08:00
|
|
|
|
2017-07-20 14:48:29 +08:00
|
|
|
componentDidMount () {
|
2017-07-27 19:32:08 +08:00
|
|
|
//const reg = /(<p>)|(<\/p>)| |(<br>)|\s+|<div>|<\/div>/g
|
|
|
|
//editor.customConfig.menus = []
|
|
|
|
// editor.customConfig.onchange = html => {
|
|
|
|
// html = html.replace(reg, '')
|
|
|
|
// this.props.getResParams(html)
|
|
|
|
// }
|
|
|
|
// setTimeout(() => {
|
|
|
|
// this.initResParams()
|
|
|
|
// }, 400)
|
|
|
|
//editor.create()
|
|
|
|
|
|
|
|
function json_parse(json){
|
|
|
|
try{
|
|
|
|
return JSON.stringify(JSON.parse(json), null, "\t");
|
|
|
|
}catch(e){
|
|
|
|
return json
|
|
|
|
}
|
2017-07-19 19:29:18 +08:00
|
|
|
}
|
2017-07-27 19:32:08 +08:00
|
|
|
|
|
|
|
let editor2 = this.editor = window.ace.edit("res-cover")
|
|
|
|
editor2.getSession().setMode("ace/mode/json");
|
|
|
|
editor2.getSession().on('change', ()=> {
|
|
|
|
this.props.getResParams(editor2.getValue())
|
|
|
|
});
|
|
|
|
setTimeout( () => {
|
|
|
|
editor2.setValue(json_parse(this.props.resParams))
|
|
|
|
} ,400)
|
2017-07-19 19:29:18 +08:00
|
|
|
}
|
|
|
|
|
2017-07-18 12:53:53 +08:00
|
|
|
render () {
|
|
|
|
return (
|
2017-07-26 12:31:42 +08:00
|
|
|
<section className="res-params-box">
|
2017-07-27 20:06:49 +08:00
|
|
|
<Card title="返回 Mock" style={{ width: 500 }}>
|
|
|
|
<div id="res-cover"></div>
|
|
|
|
</Card>
|
2017-07-18 12:53:53 +08:00
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 19:26:04 +08:00
|
|
|
export default ResParams
|