1616 */
1717
1818import React , { Component , Fragment } from "react" ;
19- import { Modal , Form , Switch , Input , Select , Divider , InputNumber } from "antd" ;
19+ import { Divider , Form , Input , InputNumber , Modal , Select , Switch } from "antd" ;
2020import { connect } from "dva" ;
21+ import ReactJson from "react-json-view" ;
2122import { getIntlContent } from "../../../utils/IntlUtils" ;
2223
2324const { Option } = Select ;
@@ -27,8 +28,45 @@ const FormItem = Form.Item;
2728 platform : global . platform ,
2829} ) )
2930class AddModal extends Component {
31+ constructor ( props ) {
32+ super ( props ) ;
33+ this . state = {
34+ jsonKey : null ,
35+ jsonValue : { } ,
36+ } ;
37+ this . parseJson ( ) ;
38+ }
39+
40+ parseJson = ( ) => {
41+ let { config, data } = this . props ;
42+ try {
43+ const jsonData = data . find ( ( i ) => i . dataType === 4 ) ;
44+ if ( config ) {
45+ config = JSON . parse ( config ) ;
46+ }
47+ const fieldName = jsonData ?. field ;
48+ this . state . jsonKey = fieldName ;
49+ this . state . jsonValue = config [ fieldName ] || { } ;
50+ } catch ( e ) {
51+ this . state . jsonValue = { } ;
52+ }
53+ } ;
54+
55+ updateJson = ( obj , fieldName ) => {
56+ const { form } = this . props ;
57+ let fieldsValue = form . getFieldsValue ( ) ;
58+ this . state . jsonValue = obj . updated_src ;
59+ const value = { [ fieldName ] : this . state . jsonValue } ;
60+ if ( ! fieldsValue [ fieldName ] ) {
61+ form . setFields ( { [ fieldName ] : { value } } ) ;
62+ } else {
63+ form . setFieldsValue ( value ) ;
64+ }
65+ } ;
66+
3067 handleSubmit = ( e ) => {
3168 const { form, handleOk, id = "" , data } = this . props ;
69+ const { jsonKey, jsonValue } = this . state ;
3270 e . preventDefault ( ) ;
3371 form . validateFieldsAndScroll ( ( err , values ) => {
3472 if ( ! err ) {
@@ -41,6 +79,9 @@ class AddModal extends Component {
4179 config [ item . field ] = values [ fieldName ] ;
4280 }
4381 } ) ;
82+ if ( data . some ( ( i ) => i . dataType === 4 ) ) {
83+ config [ jsonKey ] = jsonValue ;
84+ }
4485 config = JSON . stringify ( config ) ;
4586 if ( config === "{}" ) {
4687 config = "" ;
@@ -52,6 +93,7 @@ class AddModal extends Component {
5293 } ;
5394
5495 render ( ) {
96+ const { jsonValue } = this . state ;
5597 let {
5698 handleCancel,
5799 form,
@@ -190,6 +232,26 @@ class AddModal extends Component {
190232 ) }
191233 </ FormItem >
192234 ) ;
235+ } else if ( dataType === 4 ) {
236+ return (
237+ < FormItem
238+ label = { eachField . label }
239+ name = { fieldName }
240+ { ...formItemLayout }
241+ key = { index }
242+ >
243+ < ReactJson
244+ src = { jsonValue }
245+ theme = "monokai"
246+ displayDataTypes = { false }
247+ name = { false }
248+ onAdd = { ( obj ) => this . updateJson ( obj , fieldName ) }
249+ onEdit = { ( obj ) => this . updateJson ( obj , fieldName ) }
250+ onDelete = { ( obj ) => this . updateJson ( obj , fieldName ) }
251+ style = { { borderRadius : 4 , padding : 16 } }
252+ />
253+ </ FormItem >
254+ ) ;
193255 } else {
194256 return (
195257 < FormItem
0 commit comments