lu-lowcode-package-form 0.9.97 → 0.9.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +89 -89
- package/dist/index.es.js +2190 -2085
- package/package.json +2 -1
- package/src/components/field/table/index.jsx +20 -2
- package/src/components/form-container/index.jsx +6 -4
- package/src/utils/events.jsx +5 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "lu-lowcode-package-form",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.98",
|
4
4
|
"dependencies": {
|
5
5
|
"@ant-design/icons": "^4.8.1",
|
6
6
|
"@dnd-kit/core": "^6.1.0",
|
@@ -15,6 +15,7 @@
|
|
15
15
|
"@wangeditor/editor-for-react": "^1.0.6",
|
16
16
|
"antd": "^5.13.2",
|
17
17
|
"dayjs": "^1.11.11",
|
18
|
+
"eventemitter3": "^5.0.1",
|
18
19
|
"nanoid": "^5.0.7",
|
19
20
|
"postcss-modules": "^6.0.0",
|
20
21
|
"quill": "^2.0.2",
|
@@ -1,9 +1,10 @@
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
2
2
|
import { Button, Form, Input } from "antd";
|
3
3
|
import { DeleteOutlined } from "@ant-design/icons";
|
4
4
|
import { BaseWrapper } from "../base.jsx"
|
5
5
|
import { type } from "@testing-library/user-event/dist/type/index.js";
|
6
6
|
import { nanoid } from "nanoid";
|
7
|
+
import {eventEmitter} from '../../../utils/events'
|
7
8
|
|
8
9
|
const TableAction = ({ label, subTableIndex, children, subTableHead = false, ...props }) => {
|
9
10
|
//fsticky fright-0
|
@@ -29,6 +30,9 @@ const TableCol = ({ children, width, ...props }) => {
|
|
29
30
|
}
|
30
31
|
|
31
32
|
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, ...props }) => {
|
33
|
+
useEffect(()=>{
|
34
|
+
console.log("Table form reload",form)
|
35
|
+
},[form])
|
32
36
|
const [init, setInit] = useState(false);
|
33
37
|
const name = props.componentId || props.__id
|
34
38
|
const childrenIds = React.Children.map(children, (child) => `${name}.${child.props.componentId || child.props.__id}`)
|
@@ -37,6 +41,20 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
37
41
|
if (!init) setInit(true);
|
38
42
|
form?.setFieldValue(fieldName, [{}])
|
39
43
|
}
|
44
|
+
const [tableId, setTableId] = useState()
|
45
|
+
const handleReloadTable = (target) => {
|
46
|
+
if(fieldName == target) {
|
47
|
+
setTableId(nanoid())
|
48
|
+
}
|
49
|
+
}
|
50
|
+
useEffect(() => {
|
51
|
+
setTableId(nanoid())
|
52
|
+
eventEmitter.on('reloadTable', handleReloadTable);
|
53
|
+
return () => {
|
54
|
+
eventEmitter.off('reloadTable', handleReloadTable);
|
55
|
+
}
|
56
|
+
|
57
|
+
},[])
|
40
58
|
|
41
59
|
if (props.isRequired)
|
42
60
|
rules.push({ required: true, message: `子表[${props.label}]必须填写` });
|
@@ -60,7 +78,7 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
60
78
|
</TableAction>}
|
61
79
|
</div>}
|
62
80
|
{fields.map((field, index) => (
|
63
|
-
<div key={field.key} className="fborder-b fflex flex-nowrap fmin-w-full ">
|
81
|
+
<div key={`${tableId}.${field.key}`} className="fborder-b fflex flex-nowrap fmin-w-full ">
|
64
82
|
|
65
83
|
{React.Children.map(children, (child, childIndex) => {
|
66
84
|
let { props } = child;
|
@@ -4,7 +4,8 @@ import { Form, Row, Col, message } from "antd";
|
|
4
4
|
import { debounce, isEqual } from 'lodash';
|
5
5
|
import { evalFormula } from '../../utils/formula'
|
6
6
|
import { nanoid } from 'nanoid';
|
7
|
-
|
7
|
+
import {eventEmitter} from '../../utils/events'
|
8
|
+
|
8
9
|
|
9
10
|
function batchElements(elements, groupSize) {
|
10
11
|
const groupedElements = [];
|
@@ -203,6 +204,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
203
204
|
return target_item_value
|
204
205
|
})
|
205
206
|
setValue = target_value
|
207
|
+
eventEmitter.emit('reloadTable', target);
|
206
208
|
}
|
207
209
|
// 同级字段
|
208
210
|
else {
|
@@ -239,10 +241,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
239
241
|
changedKeys.forEach(key => {
|
240
242
|
changedFieldsState.current[key] = changedFields[key];
|
241
243
|
})
|
242
|
-
console.log("changedFieldsState",changedFieldsState.current)
|
244
|
+
// console.log("changedFieldsState",changedFieldsState.current)
|
243
245
|
debounceHandleFieldsChange();
|
244
246
|
}
|
245
|
-
console.log("idGroups", idGroups)
|
247
|
+
// console.log("idGroups", idGroups)
|
246
248
|
if (idGroups.length > 0) idGroups.forEach(ids => { if (Array.isArray(ids) && ids.length > 0) handleTableAddRow(ids) })
|
247
249
|
}, 0)
|
248
250
|
|
@@ -406,7 +408,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
406
408
|
}, 100);
|
407
409
|
|
408
410
|
const handleFieldsChange = (changedFields) => {
|
409
|
-
console.log("changedFields", changedFields)
|
411
|
+
// console.log("changedFields", changedFields)
|
410
412
|
changedFields.filter(field => {
|
411
413
|
if (field.name && field.name.length > 0) {
|
412
414
|
// const fieldKey = field.name.filter(item => typeof item == "string").join(".")
|