lu-lowcode-package-form 0.10.37 → 0.10.38

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.37",
3
+ "version": "0.10.38",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^4.8.1",
6
6
  "@dnd-kit/core": "^6.1.0",
package/src/App.jsx CHANGED
@@ -103,7 +103,7 @@ function App() {
103
103
  }
104
104
  }
105
105
  const setFormFields = () => {
106
- formRef?.current?.setFieldsValue({ "userselect": "1213131","tianchong1":{"label":"选项1","value":"1"}, "remark11": { "label": "选项1", "value": "1", "name": "1111", "table": "[{\"price\":1,\"num\":2, \"remark11\":\"{ label: '选项3', value: '3' }\"},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" }, "table": [{ "product_num1": "123", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "remark11": { "label": "选项2", "value": "2" }, "product_price12": "" }, { "product_num1": "213", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "datetime2": "2024-08-22 11:09:07", "product_price13": 1, "product_price14": 2, "product_price12": "", "remark11": { "label": "选项3", "value": "3" } }], "product_total_price": "0.00", "DeptSelect": ["leaf11"], "PostSelect": ["parent 1-1", "leaf11"], "searchuser": [{ "id": 2, "name": "2222", "label": "2222", "value": 2 }, { "id": 4, "name": "4444", "label": "4444", "value": 4 }], "product_price": "213", "product_num": "21", "product_num_range": [1, 22], "product_sum": "4473", "switch": false, "datetime": "2024-08-25", "datetime2": "2024-08-25", "datetime3": "", "datetime4": "2024-08-22 11:09:04", "remark12": [{ "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" }] })
106
+ formRef?.current?.setFieldsValue({"id":1, "userselect": "1213131","tianchong1":{"label":"选项1","value":"1"}, "remark11": { "label": "选项1", "value": "1", "name": "1111", "table": "[{\"price\":1,\"num\":2, \"remark11\":\"{ label: '选项3', value: '3' }\"},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" }, "table": [{ "product_num1": "123", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "remark11": { "label": "选项2", "value": "2" }, "product_price12": "" }, { "product_num1": "213", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "datetime2": "2024-08-22 11:09:07", "product_price13": 1, "product_price14": 2, "product_price12": "", "remark11": { "label": "选项3", "value": "3" } }], "product_total_price": "0.00", "DeptSelect": ["leaf11"], "PostSelect": ["parent 1-1", "leaf11"], "searchuser": [{ "id": 2, "name": "2222", "label": "2222", "value": 2 }, { "id": 4, "name": "4444", "label": "4444", "value": 4 }], "product_price": "213", "product_num": "21", "product_num_range": [1, 22], "product_sum": "4473", "switch": false, "datetime": "2024-08-25", "datetime2": "2024-08-25", "datetime3": "", "datetime4": "2024-08-22 11:09:04", "remark12": [{ "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" }] })
107
107
  // formRef?.current?.setFieldsValue({"tianchong1":{"label":"选项1","value":"1"}, })
108
108
  }
109
109
  const handleCols = () => {
@@ -4,8 +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
- import {eventEmitter} from '../../utils/events'
8
-
7
+ import { eventEmitter } from '../../utils/events'
8
+
9
9
 
10
10
  function batchElements(elements, groupSize) {
11
11
  const groupedElements = [];
@@ -14,7 +14,7 @@ function batchElements(elements, groupSize) {
14
14
  const fillWithReactElement = (size, array) => {
15
15
  const missingElementsCount = size - array.length;
16
16
  if (missingElementsCount > 0)
17
- array.push(...new Array(missingElementsCount).fill(React.createElement('div')));
17
+ array.push(...new Array(missingElementsCount).fill(React.createElement('div')));
18
18
  };
19
19
 
20
20
  for (const element of elements) {
@@ -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)
60
+ form.setFieldsValue({...values,__id: values?.id })
61
61
  },
62
62
  initializeFieldVisibility,
63
63
  }), []);
@@ -66,7 +66,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
66
66
  initializeFormRender();
67
67
  }, [children, cols]);
68
68
 
69
- const initializeFormRender = ()=>{
69
+ const initializeFormRender = () => {
70
70
  initializeDependencyMap();
71
71
  setFormContent(renderChildren());
72
72
  }
@@ -224,7 +224,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
224
224
  setValue = current_value[withFillIndex]?.[source]
225
225
  }
226
226
  }
227
- changedFields[target] = { name: [target], value: setValue};
227
+ changedFields[target] = { name: [target], value: setValue };
228
228
  }
229
229
  if (rule?.type == 1) {
230
230
  form.setFieldValue(target, undefined);
@@ -232,9 +232,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
232
232
  form.setFieldValue(target, setValue)
233
233
  // handleFieldsWith(target, form.getFieldsValue())
234
234
  // setTimeout(() => {
235
- // form.setFieldValue(target, setValue)
236
- // handleFieldsWith(target, form.getFieldsValue())
237
- // if (idGroups.length > 0) handleTableAddRow(idGroups)
235
+ // form.setFieldValue(target, setValue)
236
+ // handleFieldsWith(target, form.getFieldsValue())
237
+ // if (idGroups.length > 0) handleTableAddRow(idGroups)
238
238
  // }, 0);
239
239
 
240
240
 
@@ -400,7 +400,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
400
400
  // console.log("field",field.value)
401
401
  // console.log("getLastFieldValue(field.name)",getLastFieldValue(field.name))
402
402
  if (!isEqual(field.value, getLastFieldValue(field.name))) {
403
- if (lockStatus_ !=1){
403
+ if (lockStatus_ != 1) {
404
404
  needRefresh = handleFieldsWith(field.name, fieldValues);
405
405
  }
406
406
  lastFormValues.current[field.name] = field.value;
@@ -471,7 +471,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
471
471
  const isLayoutComponent = componentName && componentName.startsWith('Layout.');
472
472
  const isTable = componentName && componentName == 'Field.Table';
473
473
  const hidden = props.calcHidden && mode != "desgin";
474
-
474
+
475
475
  const rules = []
476
476
  if (props.isRequired)
477
477
  rules.push({ required: true, message: `${props.label}必须填写` });
@@ -488,13 +488,13 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
488
488
  }
489
489
  let childComponent
490
490
  if (isTable || isLayoutComponent)
491
- childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange,initializeFormRender,mode })
491
+ childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode })
492
492
  else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
493
493
  childComponent = <Form.Item
494
494
  hidden={hidden}
495
495
  style={{ margin: 0 }}
496
496
  shouldUpdate={(prevValues, curValues) => {
497
- console.log(`componentName:${componentName}; identifier:${identifier};`,props.filterRules)
497
+ console.log(`componentName:${componentName}; identifier:${identifier};`, props.filterRules)
498
498
  let result = false;
499
499
  if (Array.isArray(props.filterRules) &&
500
500
  props.filterRules.length > 0
@@ -507,19 +507,19 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
507
507
  prevFieldValue = prevValues?.[rule.value.field_key];
508
508
  curFieldValue = curValues?.[rule.value.field_key];
509
509
  if (prevFieldValue !== curFieldValue) {
510
- result = true;
510
+ result = true;
511
511
  break;
512
512
  }
513
513
  }
514
514
  }
515
-
515
+
516
516
  console.log(`componentName:${componentName}; identifier:${identifier}; result:`, result)
517
517
  return result;
518
518
  }}
519
519
  >
520
- {({getFieldsValue}) => {
520
+ {({ getFieldsValue }) => {
521
521
  const fieldsValue = getFieldsValue();
522
- let element = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue,initializeFormRender })
522
+ let element = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender })
523
523
  return componentName === "show.WithTable" ? <>{element}</> : <Form.Item
524
524
  style={{ marginBottom: 0 }}
525
525
  label=""
@@ -538,17 +538,17 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
538
538
  name={identifier}
539
539
  rules={rules}
540
540
  >
541
- {React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange,initializeFormRender })}
541
+ {React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender })}
542
542
  </Form.Item>
543
543
  }
544
544
  return (
545
545
  <Col
546
- key={identifier || `col-${index}`}
547
- span={props.calcHidden ? 0 : (isLayoutComponent ? 24 : 24 / cols)}
548
- style={{ marginBottom: 0 }}
549
- >
550
- {childComponent}
551
- </Col>
546
+ key={identifier || `col-${index}`}
547
+ span={props.calcHidden ? 0 : (isLayoutComponent ? 24 : 24 / cols)}
548
+ style={{ marginBottom: 0 }}
549
+ >
550
+ {childComponent}
551
+ </Col>
552
552
  );
553
553
  })}
554
554
  </Row>
@@ -560,6 +560,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
560
560
  // console.log("changedValues", changedValues)
561
561
  // console.log("allValues", allValues)
562
562
  }} onFieldsChange={handleFieldsChange}>
563
+ <Form.Item name="__id" hidden={true}>
564
+ <input type="hidden" />
565
+ </Form.Item>
563
566
  {formContent}
564
567
  </Form>
565
568
  );