OnstopWang.js 1.4 KB
Newer Older
1 2 3
import React, { useState, useEffect, forwardRef } from 'react';
import WangEditor from './OneStopWangEditor';

4
function Index({ onChange, value, otherProps, dataColumn, disabled, json, uuid }) {
5
  const [ready, setReady] = useState(false);
6
  const domKey = uuid || 'wang-editor-dom-content';
7
  useEffect(() => {
8
    let dom = document.getElementById(`wangEditor-${domKey}`);
9 10 11 12 13 14 15 16 17
    if(dom && dom.parentNode){
      dom.parentNode.removeChild(dom);
    }
    setReady(true);
  }, []);

  if(!ready){
    return null;
  }
18
  if(disabled){
钟是志's avatar
钟是志 committed
19 20 21
    if(!value || value === 'null'){
      return <div></div>
    }
钟是志's avatar
钟是志 committed
22 23 24
    return <div dangerouslySetInnerHTML={{__html: `<div class="wangEditorHtml">${value}</div>`}}>

    </div>
25 26
  }

27 28 29
  return (
    <WangEditor
      key={'cmsContent'}
30 31 32
      zIndex={otherProps?.zIndex || undefined}
      menus={otherProps?.menus || undefined}
      placeholder={json.placeholder || ''}
33 34
      height={otherProps?.height || 450}
      value={value || ''}
35
      domKey={domKey}
36 37 38 39 40 41
      onChangeValue={onChange}
    />
  );
}

export default forwardRef((props, _ref) => {
42
  let otherProps = {};
43 44
  // console.log(props);
  if(!props.uuid){
45 46 47 48 49 50 51 52 53 54 55 56
    return <div></div>;
  }
  if (props.json?.otherProps) {
    otherProps = props.json?.otherProps;
    try {
      otherProps = new Function(otherProps)();
      // console.log(this.otherProps);
    } catch (e) {

    }
  }
  return <Index {...props} otherProps={otherProps}/>;
57
});