From 4f5f8002496e8b32c1ba83e9d3a0674e61c41c03 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 31 三月 2021 19:01:12 +0800 Subject: [PATCH] 2021-03-31 --- src/tabviews/zshare/mutilform/customTextArea/index.jsx | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/tabviews/zshare/mutilform/customTextArea/index.jsx b/src/tabviews/zshare/mutilform/customTextArea/index.jsx index caed9bf..457e5f2 100644 --- a/src/tabviews/zshare/mutilform/customTextArea/index.jsx +++ b/src/tabviews/zshare/mutilform/customTextArea/index.jsx @@ -14,19 +14,19 @@ state = { value: '', - encryption: 'false' + encryption: false } UNSAFE_componentWillMount () { let value = '' - let encryption = 'false' + let encryption = false if (this.props['data-__meta']) { value = this.props['data-__meta'].initialValue || '' } if (this.props.Item && this.props.Item.encryption === 'true') { - encryption = 'true' + encryption = true if (value) { try { value = window.decodeURIComponent(window.atob(value)) @@ -42,6 +42,22 @@ }) } + UNSAFE_componentWillReceiveProps(nextProps) { + const { value, encryption } = this.state + + if (!encryption && value !== nextProps.value) { + this.setState({ value: nextProps.value || '' }) + } else if (encryption && window.btoa(window.encodeURIComponent(value)) !== nextProps.value) { + let _value = nextProps.value || '' + try { + _value = window.decodeURIComponent(window.atob(_value)) + } catch { + _value = nextProps.value || '' + } + this.setState({ value: _value }) + } + } + onChange = (e) => { const { encryption } = this.state let val = e.target.value @@ -49,7 +65,7 @@ this.setState({ value: val }) let _val = val - if (encryption === 'true') { + if (encryption) { try { _val = window.btoa(window.encodeURIComponent(_val)) } catch { -- Gitblit v1.8.0