|
@@ -1,4 +1,4 @@
|
|
-import React, { useState } from 'react';
|
|
|
|
|
|
+import React, { useState, useEffect } from 'react';
|
|
import FormContent from './FormContent';
|
|
import FormContent from './FormContent';
|
|
import ComponentLibrary from './ComponentLibrary';
|
|
import ComponentLibrary from './ComponentLibrary';
|
|
import ItemAttribute from './ItemAttribute';
|
|
import ItemAttribute from './ItemAttribute';
|
|
@@ -6,13 +6,14 @@ import { uuidv4 } from '@antv/xflow';
|
|
import { Button } from 'antd';
|
|
import { Button } from 'antd';
|
|
|
|
|
|
function AuditForm(props) {
|
|
function AuditForm(props) {
|
|
|
|
+ const { value, onChange } = props;
|
|
const [formList, setFormList] = useState([]);
|
|
const [formList, setFormList] = useState([]);
|
|
const [select, setSelect] = useState(-1);
|
|
const [select, setSelect] = useState(-1);
|
|
const [visible, setVisible] = useState(false);
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
|
|
const handleAddItem = item => {
|
|
const handleAddItem = item => {
|
|
const formItem = generateItem(item);
|
|
const formItem = generateItem(item);
|
|
- setFormList([...formList, formItem]);
|
|
|
|
|
|
+ handleChangeList([...formList, formItem]);
|
|
setVisible(false);
|
|
setVisible(false);
|
|
};
|
|
};
|
|
|
|
|
|
@@ -27,9 +28,20 @@ function AuditForm(props) {
|
|
const onChangeAttribute = newItem => {
|
|
const onChangeAttribute = newItem => {
|
|
let oldValue = formList[select].props;
|
|
let oldValue = formList[select].props;
|
|
formList[select].props = { ...oldValue, ...newItem };
|
|
formList[select].props = { ...oldValue, ...newItem };
|
|
- setFormList([...formList]);
|
|
|
|
|
|
+ handleChangeList([...formList]);
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const handleChangeList = list => {
|
|
|
|
+ setFormList(list);
|
|
|
|
+ onChange?.(list);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (value instanceof Array) {
|
|
|
|
+ setFormList([...value]);
|
|
|
|
+ }
|
|
|
|
+ }, [value]);
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<div>
|
|
<div>
|
|
<Button onClick={() => setVisible(true)}>增加控件</Button>
|
|
<Button onClick={() => setVisible(true)}>增加控件</Button>
|
|
@@ -42,7 +54,7 @@ function AuditForm(props) {
|
|
marginTop: 20,
|
|
marginTop: 20,
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
- <FormContent onSelect={setSelect} onChange={setFormList} list={formList}></FormContent>
|
|
|
|
|
|
+ <FormContent onSelect={setSelect} onChange={handleChangeList} list={formList}></FormContent>
|
|
<ItemAttribute item={formList[select]} onChange={onChangeAttribute}></ItemAttribute>
|
|
<ItemAttribute item={formList[select]} onChange={onChangeAttribute}></ItemAttribute>
|
|
</div>
|
|
</div>
|
|
<ComponentLibrary
|
|
<ComponentLibrary
|