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/share/braftContent/index.jsx | 57 ++++++++++++++++++++++++++++++++------------------------- 1 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/tabviews/custom/components/share/braftContent/index.jsx b/src/tabviews/custom/components/share/braftContent/index.jsx index 527e61f..553249f 100644 --- a/src/tabviews/custom/components/share/braftContent/index.jsx +++ b/src/tabviews/custom/components/share/braftContent/index.jsx @@ -1,13 +1,12 @@ -import React, {Component} from 'react' +import React, { Component } from 'react' import PropTypes from 'prop-types' -import { is, fromJS } from 'immutable' import './index.scss' class BraftContent extends Component { static propTpyes = { value: PropTypes.any, // 鍐呭 - encryption: PropTypes.any, // 鏄惁瑙g爜 + script: PropTypes.any // 鑷畾涔夎剼鏈� } state = { @@ -15,34 +14,42 @@ } UNSAFE_componentWillMount () { - const { encryption, value } = this.props - let html = value - - if (encryption === 'true' && html) { - try { - html = window.decodeURIComponent(window.atob(html)) - } catch (e) { - html = value - } - } + const { value } = this.props - this.setState({html}) + this.setState({html: value}) + } + + componentDidMount() { + this.loadScript() } UNSAFE_componentWillReceiveProps(nextProps) { - if (!is(fromJS(this.props), fromJS(nextProps))) { - const { encryption, value } = nextProps - let html = value + if (this.props.value !== nextProps.value) { + this.setState({html: nextProps.value}, () => { + this.loadScript() + }) + } + } - if (encryption === 'true' && html) { - try { - html = window.decodeURIComponent(window.atob(html)) - } catch (e) { - html = value - } + loadScript = () => { + const { script } = this.props + const { html } = this.state + + if (script && html) { + const that = this + let _html = '' + try { + // eslint-disable-next-line + let func = new Function('that', 'html', script) + _html = func(that, html) + } catch (e) { + _html = '' + console.warn(e) } - - this.setState({html}) + + if (_html) { + this.setState({html: _html}) + } } } -- Gitblit v1.8.0