From 871597aaf2c838946723ee44fc7fa12487b56d34 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 22 一月 2025 15:14:25 +0800 Subject: [PATCH] 2025-01-22 --- src/tabviews/custom/components/editor/braft-editor/index.jsx | 42 +++++++++++++++++++++++++++++++++++------- 1 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/tabviews/custom/components/editor/braft-editor/index.jsx b/src/tabviews/custom/components/editor/braft-editor/index.jsx index 2c5ddd6..067b69f 100644 --- a/src/tabviews/custom/components/editor/braft-editor/index.jsx +++ b/src/tabviews/custom/components/editor/braft-editor/index.jsx @@ -73,7 +73,7 @@ } this.setState({ - data: _data, + data: this.decodeHtml(_data, _config.wrap), BID: BID || '', config: _config, }) @@ -130,7 +130,7 @@ let _data = window.GLOB.SyncData.get(config.dataName) || [] - this.setState({data: _data}) + this.setState({data: this.decodeHtml(_data, config.wrap)}) window.GLOB.SyncData.delete(config.dataName) @@ -158,7 +158,7 @@ _data = [_data] } - this.setState({data: _data}) + this.setState({data: this.decodeHtml(_data, config.wrap)}) } } @@ -224,7 +224,7 @@ let result = await Api.genericInterface(param) if (result.status) { this.setState({ - data: result.data || [], + data: this.decodeHtml(result.data, config.wrap), loading: false }) @@ -236,6 +236,35 @@ UtilsDM.queryFail(result) } + } + + decodeHtml = (data, wrap) => { + if (!data || data.length === 0) return [] + + data.forEach(item => { + item.$html = item[wrap.field] || '' + if (item.$html) { + if (wrap.encryption === 'true') { + try { + item.$html = window.decodeURIComponent(window.atob(item.$html)) + } catch (e) { + item.$html = item[wrap.field] || '' + } + } + + delete item[wrap.field] + + if (/\$[\s\S]+\$/.test(item.$html)) { + Object.keys(item).forEach(key => { + if (/^\$/.test(key)) return + let reg = new RegExp('\\$' + key + '\\$', 'ig') + item.$html = item.$html.replace(reg, item[key]) + }) + } + } + }) + + return data } render() { @@ -254,11 +283,10 @@ <NormalHeader config={config}/> {config.wrap.datatype === 'static' ? <BraftContent value={config.html} - encryption={'false'} /> : data.map((item, index) => <BraftContent key={index} - value={item[config.wrap.field] || ''} - encryption={config.wrap.encryption} + value={item.$html} + script={config.wrap.loaded === 'true' ? config.wrap.loadedfunc : ''} />)} </div> ) -- Gitblit v1.8.0