import React, { Component } from 'react'; import './index.less'; import Editor from 'wangeditor'; export default class KindEditor extends Component { defaultValueHead = `
`; defaultValueFoot = '
'; editor = Editor; constructor(props) { super(props); this.state = { editorContent: '', isActive: false }; } /** * 清空内容 */ onClear = () => { this.editor.txt.clear(); this.editor.config.focus = false; this.setState({ isActive: false, editorContent: '', }); }; /** * 回现代码 */ onCashBack = () => { let { cashBackText } = this.props; if (!!!cashBackText) { return; } this.editor.txt.html(`${cashBackText}`); this.editor.config.focus = true; }; /** * 获得焦点 */ onFocus = () => { this.editor.config.focus = true; this.setState({ isActive: true, }); }; componentDidMount() { const elemMenu = this.refs.editorElemMenu; const elemBody = this.refs.editorElemBody; if (this.editor) return this.editor = new Editor(elemMenu, elemBody); // // 使用 onchange 函数监听内容的变化,并实时更新到 state 中 this.editor.config.onchange = (html) => { let htmlStr = this.editor.txt.html(); // console.log('htmlStr ---', htmlStr); if (htmlStr?.indexOf('
); } } KindEditor.defaultProps = { bodyHeight: 320, bodyWidth: '100%', borderRadius: '4px', };