From 4fcad7ab9334897449360194848cec1c998973df Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 18 一月 2021 17:49:16 +0800 Subject: [PATCH] 2021-01-18 --- src/components/editor/index.jsx | 38 ++++++++++++++++++++++++++++++++------ 1 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/components/editor/index.jsx b/src/components/editor/index.jsx index b7745fe..2c0bd2b 100644 --- a/src/components/editor/index.jsx +++ b/src/components/editor/index.jsx @@ -4,7 +4,7 @@ import BraftEditor from 'braft-editor' import 'braft-editor/dist/index.css' import 'braft-extensions/dist/table.css' -import 'braft-editor/dist/output.css' +// import 'braft-editor/dist/output.css' import Table from 'braft-extensions/dist/table' import SparkMD5 from 'spark-md5' import moment from 'moment' @@ -23,31 +23,57 @@ class NormalEditor extends Component { static propTpyes = { - card: PropTypes.object, // 鏉$爜璁剧疆 - value: PropTypes.any, // 鏉$爜鍊� + Item: PropTypes.object, // 琛ㄥ崟鍏冪礌 + onChange: PropTypes.func, // 琛ㄥ崟鏇存柊 } state = { - editorState: '' + editorState: '', + encryption: 'false', } UNSAFE_componentWillMount () { let initVal = null + let encryption = 'false' if (this.props['data-__meta']) { initVal = this.props['data-__meta'].initialValue || null } + + if (this.props.Item && this.props.Item.encryption === 'true') { + encryption = 'true' + if (initVal) { + try { + initVal = window.decodeURIComponent(window.atob(initVal)) + } catch { + initVal = this.props['data-__meta'].initialValue || null + } + } + } - this.setState({editorState: BraftEditor.createEditorState(initVal)}) + this.setState({ + editorState: BraftEditor.createEditorState(initVal), + encryption + }) } shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.props), fromJS(nextProps)) } handleEditorChange = (editorState) => { + const { encryption } = this.state + this.setState({ editorState }) if (this.props.onChange) { - this.props.onChange(editorState.toHTML()) + let val = editorState.toHTML() + if (encryption === 'true') { + try { + val = window.btoa(window.encodeURIComponent(val)) + } catch { + val = editorState.toHTML() + } + } + this.props.onChange(val) } } -- Gitblit v1.8.0