提交 4e2d1248 authored 作者: chscls@163.com's avatar chscls@163.com

富文本bug

上级 7528dc9b
...@@ -64,7 +64,6 @@ export default class DraftEditor extends React.Component { ...@@ -64,7 +64,6 @@ export default class DraftEditor extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
const value = props.value || {}; const value = props.value || {};
const editorState = changeToDraftState2(blocks)
this.state = { this.state = {
editorState: value.editorState, editorState: value.editorState,
......
...@@ -83,11 +83,11 @@ export default class DraftEditorCom extends React.Component { ...@@ -83,11 +83,11 @@ export default class DraftEditorCom extends React.Component {
this.onChange = (editorState,callback) => { this.onChange = (editorState,callback) => {
if (!('value' in this.props)) {
this.setState({ editorState },()=>{ this.setState({ editorState },()=>{
if(callback)callback() if(callback)callback()
}); });
}
this.triggerChange({ editorState },()=>{ this.triggerChange({ editorState },()=>{
if(callback)callback() if(callback)callback()
}); });
...@@ -141,12 +141,12 @@ export default class DraftEditorCom extends React.Component { ...@@ -141,12 +141,12 @@ export default class DraftEditorCom extends React.Component {
const xx = AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, text); const xx = AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, text);
if (!('value' in this.props)) {
this.setState({ editorState: xx }, () => { this.setState({ editorState: xx }, () => {
callback() callback()
}); });
}
this.triggerChange({ editorState: xx}, () => { this.triggerChange({ editorState: xx}, () => {
callback() callback()
...@@ -177,13 +177,13 @@ export default class DraftEditorCom extends React.Component { ...@@ -177,13 +177,13 @@ export default class DraftEditorCom extends React.Component {
); );
} }
componentWillReceiveProps(nextProps) { /* componentWillReceiveProps(nextProps) {
// Should be a controlled component. // Should be a controlled component.
if ('value' in nextProps) { if ('value' in nextProps) {
const value = nextProps.value; const value = nextProps.value;
this.setState({editorState: changeToDraftState(value)});
} }
} } */
...@@ -191,27 +191,27 @@ export default class DraftEditorCom extends React.Component { ...@@ -191,27 +191,27 @@ export default class DraftEditorCom extends React.Component {
} }
insertAttr = () => { insertAttr = () => {
if (!('value' in this.props)) {
this.setState({ modalVisible: true, fnKey: "attr" }); this.setState({ modalVisible: true, fnKey: "attr" });
}
this.triggerChange({ modalVisible: true, fnKey: "attr" }); this.triggerChange({ modalVisible: true, fnKey: "attr" });
} }
insertPic = () => { insertPic = () => {
if (!('value' in this.props)) {
this.setState({ modalVisible: true, fnKey: "image" }); this.setState({ modalVisible: true, fnKey: "image" });
}
this.triggerChange({ modalVisible: true, fnKey: "image" }); this.triggerChange({ modalVisible: true, fnKey: "image" });
} }
insertFormula = () => { insertFormula = () => {
if (!('value' in this.props)) {
this.setState({ modalVisible: true, fnKey: "formula" }); this.setState({ modalVisible: true, fnKey: "formula" });
}
this.triggerChange({ modalVisible: true, fnKey: "formula" }); this.triggerChange({ modalVisible: true, fnKey: "formula" });
} }
insertVideo = () => { insertVideo = () => {
if (!('value' in this.props)) {
this.setState({ modalVisible: true, fnKey: "video" }); this.setState({ modalVisible: true, fnKey: "video" });
}
this.triggerChange({ modalVisible: true, fnKey: "video" }); this.triggerChange({ modalVisible: true, fnKey: "video" });
} }
insertLink = () => { insertLink = () => {
...@@ -221,9 +221,9 @@ export default class DraftEditorCom extends React.Component { ...@@ -221,9 +221,9 @@ export default class DraftEditorCom extends React.Component {
message.error("请选择需要插入链接的内容") message.error("请选择需要插入链接的内容")
return return
} }
if (!('value' in this.props)) {
this.setState({ modalVisible: true, fnKey: "link" }); this.setState({ modalVisible: true, fnKey: "link" });
}
this.triggerChange({ modalVisible: true, fnKey: "link" }); this.triggerChange({ modalVisible: true, fnKey: "link" });
} }
...@@ -244,9 +244,9 @@ export default class DraftEditorCom extends React.Component { ...@@ -244,9 +244,9 @@ export default class DraftEditorCom extends React.Component {
if (!('value' in this.props)) {
this.setState({ editorState: xx, modalVisible: false, }); this.setState({ editorState: xx, modalVisible: false, });
}
this.triggerChange({ editorState: xx, modalVisible: false, }); this.triggerChange({ editorState: xx, modalVisible: false, });
} }
...@@ -267,9 +267,9 @@ export default class DraftEditorCom extends React.Component { ...@@ -267,9 +267,9 @@ export default class DraftEditorCom extends React.Component {
if (!('value' in this.props)) {
this.setState({ editorState: xx, modalVisible: false, }); this.setState({ editorState: xx, modalVisible: false, });
}
this.triggerChange({ editorState: xx, modalVisible: false, }); this.triggerChange({ editorState: xx, modalVisible: false, });
} }
...@@ -286,13 +286,8 @@ export default class DraftEditorCom extends React.Component { ...@@ -286,13 +286,8 @@ export default class DraftEditorCom extends React.Component {
const xx = AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, '[图片]'); const xx = AtomicBlockUtils.insertAtomicBlock(newEditorState, entityKey, '[图片]');
if (!('value' in this.props)) {
this.setState({ editorState: xx, modalVisible: false, }); this.setState({ editorState: xx, modalVisible: false, });
}
this.triggerChange({ editorState: xx, modalVisible: false, }); this.triggerChange({ editorState: xx, modalVisible: false, });
} }
...@@ -321,9 +316,9 @@ export default class DraftEditorCom extends React.Component { ...@@ -321,9 +316,9 @@ export default class DraftEditorCom extends React.Component {
entityKey entityKey
) )
if (!('value' in this.props)) {
this.setState({ editorState: xx, modalVisible: false}); this.setState({ editorState: xx, modalVisible: false});
}
this.triggerChange({ editorState: xx, modalVisible: false}); this.triggerChange({ editorState: xx, modalVisible: false});
} }
...@@ -361,9 +356,9 @@ export default class DraftEditorCom extends React.Component { ...@@ -361,9 +356,9 @@ export default class DraftEditorCom extends React.Component {
blocks.blocks.splice(j,1) blocks.blocks.splice(j,1)
const editorState = changeToDraftState2(blocks) const editorState = changeToDraftState2(blocks)
if (!('value' in this.props)) {
this.setState({ editorState }); this.setState({ editorState });
}
this.triggerChange({ editorState }); this.triggerChange({ editorState });
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论