lu-lowcode-package-form 0.10.41 → 0.10.42
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs.js +320 -320
- package/dist/index.es.js +21756 -21733
- package/package.json +1 -1
- package/src/components/field/select/search-select.jsx +4 -3
- package/src/components/field/table/index.jsx +2 -1
- package/src/components/form-container/index.jsx +28 -16
- package/src/components/form-container/layout/form-row.jsx +4 -4
package/package.json
CHANGED
@@ -6,7 +6,7 @@ import { BaseWrapper } from "../base"
|
|
6
6
|
import { debounce, isEqual } from 'lodash';
|
7
7
|
|
8
8
|
|
9
|
-
const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsValue, value, type, defaultValue, onChange, option_label, option_value, option_search, options, request, requestParams, callError, subRequest, sub_option_label = "label", mode = "single", sub_option_value = "id", rightIconRender, rightIcon, rightIconClick, ...props }, ref) => {
|
9
|
+
const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsValue, value, type, defaultValue, onChange, option_label, option_value, option_search, options, request, requestParams, callError, subRequest, sub_option_label = "label", mode = "single", sub_option_value = "id", rightIconRender, rightIcon, rightIconClick,recordFieldsChange, ...props }, ref) => {
|
10
10
|
const [nOptions, setNOptions] = React.useState([])
|
11
11
|
const [fetching, setFetching] = useState(false);
|
12
12
|
useEffect(() => {
|
@@ -26,6 +26,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
26
26
|
if (!item) loadSelectOptions()
|
27
27
|
}
|
28
28
|
}, [value])
|
29
|
+
|
29
30
|
// useEffect(() => {
|
30
31
|
// initData(requestParams)
|
31
32
|
// }, [requestParams, fieldsValue])
|
@@ -186,7 +187,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
186
187
|
|
187
188
|
</OriginalSelect>
|
188
189
|
{!props?.disabled && rightIcon}
|
189
|
-
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName })}
|
190
|
+
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName,recordFieldsChange })}
|
190
191
|
</BaseWrapper>
|
191
192
|
) : (<>
|
192
193
|
<OriginalSelect
|
@@ -204,7 +205,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
204
205
|
|
205
206
|
</OriginalSelect>
|
206
207
|
{!props?.disabled && rightIcon}
|
207
|
-
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName })}
|
208
|
+
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName ,recordFieldsChange})}
|
208
209
|
</>
|
209
210
|
)
|
210
211
|
|
@@ -30,7 +30,7 @@ const TableCol = ({ children, width, hidden, ...props }) => {
|
|
30
30
|
</div>
|
31
31
|
}
|
32
32
|
|
33
|
-
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, initializeFormRender, mode, ...props }) => {
|
33
|
+
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, initializeFormRender,recordFieldsChange, mode, ...props }) => {
|
34
34
|
useEffect(() => {
|
35
35
|
// console.log("Table form reload", form)
|
36
36
|
}, [form])
|
@@ -160,6 +160,7 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
160
160
|
fieldName: [fieldName, field.name, col_id],
|
161
161
|
fieldsValue: fieldsValue,
|
162
162
|
initializeFormRender,
|
163
|
+
recordFieldsChange
|
163
164
|
})}
|
164
165
|
</Form.Item>
|
165
166
|
}}
|
@@ -57,7 +57,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
57
57
|
formRef: form,
|
58
58
|
setFieldsValue: (values) => {
|
59
59
|
lockStatus.current = 1;
|
60
|
-
form.setFieldsValue({...values,__id: values?.id })
|
60
|
+
form.setFieldsValue({ ...values, __id: values?.id })
|
61
61
|
},
|
62
62
|
initializeFieldVisibility,
|
63
63
|
}), []);
|
@@ -180,7 +180,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
180
180
|
return needRefresh;
|
181
181
|
|
182
182
|
};
|
183
|
-
const removeLastFieldsValues = (name
|
183
|
+
const removeLastFieldsValues = (name, isTable = false) => {
|
184
184
|
if (!lastFormValues.current) return
|
185
185
|
if (isTable) {
|
186
186
|
const lastFormValuesKeys = Object.keys(lastFormValues.current)
|
@@ -193,6 +193,23 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
193
193
|
}
|
194
194
|
else delete lastFormValues.current[name]
|
195
195
|
}
|
196
|
+
|
197
|
+
const recordFieldChange = (fieldName, fieldValue) => {
|
198
|
+
if (!changedFieldsState.current) {
|
199
|
+
changedFieldsState.current = {};
|
200
|
+
}
|
201
|
+
changedFieldsState.current[fieldName] = fieldValue;
|
202
|
+
}
|
203
|
+
const recordFieldsChange = (changedFields, handleChange = false) => {
|
204
|
+
var changedKeys = Object.keys(changedFields)
|
205
|
+
if (changedKeys.length > 0) {
|
206
|
+
changedKeys.forEach(key => {
|
207
|
+
recordFieldChange(key, changedFields[key])
|
208
|
+
})
|
209
|
+
if (handleChange) debounceHandleFieldsChange();
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
196
213
|
// 处理填充规则
|
197
214
|
const handleFillRules = (current_identifier, parentIdentifier, fieldValues, fillRules) => {
|
198
215
|
// 获取当前变更的字段数据
|
@@ -266,14 +283,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
266
283
|
}
|
267
284
|
|
268
285
|
setTimeout(() => {
|
269
|
-
|
270
|
-
if (changedKeys.length > 0) {
|
271
|
-
changedKeys.forEach(key => {
|
272
|
-
changedFieldsState.current[key] = changedFields[key];
|
273
|
-
})
|
274
|
-
|
275
|
-
debounceHandleFieldsChange();
|
276
|
-
}
|
286
|
+
recordFieldsChange(changedFields,true)
|
277
287
|
// console.log("idGroups", idGroups)
|
278
288
|
if (idGroups.length > 0) idGroups.forEach(ids => { if (Array.isArray(ids) && ids.length > 0) handleTableAddRow(ids) })
|
279
289
|
}, 0)
|
@@ -407,7 +417,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
407
417
|
}
|
408
418
|
return result
|
409
419
|
}
|
410
|
-
|
420
|
+
|
411
421
|
|
412
422
|
const changedFieldsState = React.useRef({});
|
413
423
|
const debounceHandleFieldsChange = debounce(() => {
|
@@ -416,7 +426,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
416
426
|
lockStatus.current = 0
|
417
427
|
let needRefresh = false;
|
418
428
|
if (!lastFormValues.current) lastFormValues.current = {}
|
419
|
-
|
429
|
+
|
420
430
|
for (let key in changedFieldsState.current) {
|
421
431
|
let field = changedFieldsState.current[key];
|
422
432
|
if (!isEqual(field.value, getLastFieldValue(field.name))) {
|
@@ -506,9 +516,11 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
506
516
|
const onCustomChange = (value) => {
|
507
517
|
form.setFieldValue(identifier, value)
|
508
518
|
}
|
519
|
+
|
509
520
|
let childComponent
|
510
|
-
if (isTable || isLayoutComponent)
|
511
|
-
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode })
|
521
|
+
if (isTable || isLayoutComponent){
|
522
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode , recordFieldsChange })
|
523
|
+
}
|
512
524
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
513
525
|
childComponent = <Form.Item
|
514
526
|
hidden={hidden}
|
@@ -537,7 +549,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
537
549
|
>
|
538
550
|
{({ getFieldsValue }) => {
|
539
551
|
const fieldsValue = getFieldsValue();
|
540
|
-
let element = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender })
|
552
|
+
let element = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender ,recordFieldsChange})
|
541
553
|
return componentName === "show.WithTable" ? <>{element}</> : <Form.Item
|
542
554
|
style={{ marginBottom: 0 }}
|
543
555
|
label=""
|
@@ -556,7 +568,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
556
568
|
name={identifier}
|
557
569
|
rules={rules}
|
558
570
|
>
|
559
|
-
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender })}
|
571
|
+
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender,recordFieldsChange })}
|
560
572
|
</Form.Item>
|
561
573
|
}
|
562
574
|
return (
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React, { useMemo } from 'react';
|
2
2
|
import { Form, Row, Col } from 'antd';
|
3
3
|
|
4
|
-
const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form, initializeFormRender, mode }) => {
|
4
|
+
const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form, initializeFormRender,recordFieldsChange, mode }) => {
|
5
5
|
layout = layout || '1';
|
6
6
|
const getColSpan = (layoutStr) => {
|
7
7
|
const layoutArray = layoutStr.split(',').map(Number);
|
@@ -40,7 +40,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
40
40
|
}
|
41
41
|
let childComponent = null
|
42
42
|
if (componentName == 'Field.Table')
|
43
|
-
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: name, initializeFormRender, mode })
|
43
|
+
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: name, initializeFormRender, mode,recordFieldsChange })
|
44
44
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
45
45
|
childComponent = <Form.Item
|
46
46
|
hidden={hidden}
|
@@ -68,7 +68,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
68
68
|
>
|
69
69
|
{({ getFieldsValue }) => {
|
70
70
|
const fieldsValue = getFieldsValue();
|
71
|
-
let element = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender })
|
71
|
+
let element = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender,recordFieldsChange })
|
72
72
|
return componentName === "Show.WithTable" ? <>{element}</> : <Form.Item
|
73
73
|
style={{ marginBottom: 0 }}
|
74
74
|
label=""
|
@@ -88,7 +88,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
88
88
|
name={name}
|
89
89
|
rules={rules}
|
90
90
|
>
|
91
|
-
{React.cloneElement(child, { form: form, fieldName: name, initializeFormRender })}
|
91
|
+
{React.cloneElement(child, { form: form, fieldName: name, initializeFormRender,recordFieldsChange })}
|
92
92
|
</Form.Item>
|
93
93
|
else childComponent = child
|
94
94
|
|