lu-lowcode-package-form 0.10.40 → 0.10.42

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lu-lowcode-package-form",
3
- "version": "0.10.40",
3
+ "version": "0.10.42",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^4.8.1",
6
6
  "@dnd-kit/core": "^6.1.0",
@@ -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,6 +180,35 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
180
180
  return needRefresh;
181
181
 
182
182
  };
183
+ const removeLastFieldsValues = (name, isTable = false) => {
184
+ if (!lastFormValues.current) return
185
+ if (isTable) {
186
+ const lastFormValuesKeys = Object.keys(lastFormValues.current)
187
+ for (let index = 0; index < lastFormValuesKeys.length; index++) {
188
+ const key = lastFormValuesKeys[index];
189
+ if (key.includes(`${name},`)) {
190
+ delete lastFormValues.current[key]
191
+ }
192
+ }
193
+ }
194
+ else delete lastFormValues.current[name]
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
+ }
183
212
 
184
213
  // 处理填充规则
185
214
  const handleFillRules = (current_identifier, parentIdentifier, fieldValues, fillRules) => {
@@ -221,6 +250,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
221
250
  return target_item_value
222
251
  })
223
252
  setValue = target_value
253
+ removeLastFieldsValues(target, true)
224
254
  eventEmitter.emit('reloadTable', target);
225
255
  }
226
256
  // 同级字段
@@ -253,14 +283,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
253
283
  }
254
284
 
255
285
  setTimeout(() => {
256
- var changedKeys = Object.keys(changedFields)
257
- if (changedKeys.length > 0) {
258
- changedKeys.forEach(key => {
259
- changedFieldsState.current[key] = changedFields[key];
260
- })
261
-
262
- debounceHandleFieldsChange();
263
- }
286
+ recordFieldsChange(changedFields,true)
264
287
  // console.log("idGroups", idGroups)
265
288
  if (idGroups.length > 0) idGroups.forEach(ids => { if (Array.isArray(ids) && ids.length > 0) handleTableAddRow(ids) })
266
289
  }, 0)
@@ -395,6 +418,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
395
418
  return result
396
419
  }
397
420
 
421
+
398
422
  const changedFieldsState = React.useRef({});
399
423
  const debounceHandleFieldsChange = debounce(() => {
400
424
  const fieldValues = form.getFieldsValue();
@@ -402,10 +426,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
402
426
  lockStatus.current = 0
403
427
  let needRefresh = false;
404
428
  if (!lastFormValues.current) lastFormValues.current = {}
429
+
405
430
  for (let key in changedFieldsState.current) {
406
431
  let field = changedFieldsState.current[key];
407
- // console.log("field",field.value)
408
- // console.log("getLastFieldValue(field.name)",getLastFieldValue(field.name))
409
432
  if (!isEqual(field.value, getLastFieldValue(field.name))) {
410
433
  if (lockStatus_ != 1) {
411
434
  needRefresh = handleFieldsWith(field.name, fieldValues);
@@ -493,9 +516,11 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
493
516
  const onCustomChange = (value) => {
494
517
  form.setFieldValue(identifier, value)
495
518
  }
519
+
496
520
  let childComponent
497
- if (isTable || isLayoutComponent)
498
- 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
+ }
499
524
  else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
500
525
  childComponent = <Form.Item
501
526
  hidden={hidden}
@@ -524,7 +549,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
524
549
  >
525
550
  {({ getFieldsValue }) => {
526
551
  const fieldsValue = getFieldsValue();
527
- 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})
528
553
  return componentName === "show.WithTable" ? <>{element}</> : <Form.Item
529
554
  style={{ marginBottom: 0 }}
530
555
  label=""
@@ -543,7 +568,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
543
568
  name={identifier}
544
569
  rules={rules}
545
570
  >
546
- {React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender })}
571
+ {React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender,recordFieldsChange })}
547
572
  </Form.Item>
548
573
  }
549
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