import React, { useState, useCallback } from 'react'; import isPlainObject from 'lodash/isPlainObject'; import isArray from 'lodash/isArray'; const { CodeControl } = window?.VisualEngineUtils || {}; const { Button, CnBalloon, CnMessage } = window.CNUI || {}; export function JsonEditor(props) { const [visible, setVisible] = useState(false); const [code, setCode] = useState(''); const { value, onChange } = props; const edit = () => { if (value) { if (isPlainObject(value) || isArray(value)) { try { setCode(JSON.stringify(value, null, '\t')); } catch (e) {} setVisible(true); } } }; const onOk = () => { try { const result = JSON.parse(code); if (result) { onChange?.(result); setCode(''); setVisible(false); } } catch (e) { CnMessage.error('数据不符合JSON格式'); } }; return (