Commit 166c3dca by yuananting

fix:富文本创建重复

parent 9e16f517
...@@ -42,9 +42,16 @@ class QuestionEditor extends Component { ...@@ -42,9 +42,16 @@ class QuestionEditor extends Component {
blanksList: props.blanksList || [], blanksList: props.blanksList || [],
}; };
} }
componentDidMount() { componentDidMount() {
this.renderEditor(); const editorRoot = new E(
`#editor${this.state.editorId}_tabbar`,
`#editor${this.state.editorId}_content`
);
this.setState({ editorRoot }, () => {
this.renderEditor(editorRoot);
editorRoot.create();
this.editorRoot = editorRoot;
});
} }
static getDerivedStateFromProps(nextProps, prevState) { static getDerivedStateFromProps(nextProps, prevState) {
...@@ -57,7 +64,7 @@ class QuestionEditor extends Component { ...@@ -57,7 +64,7 @@ class QuestionEditor extends Component {
const { detailInfo, blanksList } = nextProps; const { detailInfo, blanksList } = nextProps;
if (this.state.detailInfo !== detailInfo) { if (this.state.detailInfo !== detailInfo) {
this.setState({ detailInfo: nextProps.detailInfo }, () => { this.setState({ detailInfo: nextProps.detailInfo }, () => {
this.renderEditor(); this.renderEditor(this.state.editorRoot);
}); });
} }
if (blanksList !== this.state.blanksList) { if (blanksList !== this.state.blanksList) {
...@@ -94,13 +101,9 @@ class QuestionEditor extends Component { ...@@ -94,13 +101,9 @@ class QuestionEditor extends Component {
); );
}; };
renderEditor() { renderEditor(editorRoot) {
const { editorId, detailInfo } = this.state; const { editorId, detailInfo } = this.state;
const { onChange, bindChangeContent } = this.props; const { onChange, bindChangeContent } = this.props;
const editorRoot = new E(
`#editor${editorId}_tabbar`,
`#editor${editorId}_content`
);
editorRoot.config.menus = []; editorRoot.config.menus = [];
editorRoot.config.uploadImgMaxSize = 1 * 1024 * 1024; editorRoot.config.uploadImgMaxSize = 1 * 1024 * 1024;
editorRoot.config.customAlert = function (info) { editorRoot.config.customAlert = function (info) {
...@@ -223,9 +226,6 @@ class QuestionEditor extends Component { ...@@ -223,9 +226,6 @@ class QuestionEditor extends Component {
}); });
}; };
editorRoot.create();
this.editorRoot = editorRoot;
const contentHtml = /^\<p/.test(detailInfo.content) const contentHtml = /^\<p/.test(detailInfo.content)
? detailInfo.content ? detailInfo.content
: `<p>${detailInfo.content}</p>`; : `<p>${detailInfo.content}</p>`;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment