浏览代码

Merge branch 'develop_audit_flow' of http://120.55.44.4:10080/xujunjie/WorkloadWeb into develop_audit_flow

hanxin 2 年之前
父节点
当前提交
ad1e4fa025
共有 2 个文件被更改,包括 19 次插入7 次删除
  1. 16 4
      src/components/AuditForm/index.js
  2. 3 3
      src/pages/PurchaseAdmin/PurchaseList/List/NewList.js

+ 16 - 4
src/components/AuditForm/index.js

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

+ 3 - 3
src/pages/PurchaseAdmin/PurchaseList/List/NewList.js

@@ -135,8 +135,8 @@ function List(props) {
 
   return (
     <div>
-      {/* <AuditForm /> */}
-      <Table
+      <AuditForm />
+      {/* <Table
         loading={loading || loading2}
         rowKey="id"
         dataSource={excel.list}
@@ -152,7 +152,7 @@ function List(props) {
         version={version}
         onCommit={onCommit}
         onChangeVersion={version => changeVersion(version)}
-      />
+      /> */}
       {/* <VersionModal
         loading={getLoading()}
         visible={versionVisible}