lu-lowcode-package-form 0.10.36 → 0.10.38
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs.js +207 -207
- package/dist/index.es.js +11024 -11009
- package/package.json +1 -1
- package/src/App.jsx +3 -3
- package/src/components/form-container/index.jsx +30 -26
- package/src/components/form-container/layout/form-row.jsx +4 -35
- package/src/components/index.jsx +11 -3
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { FormContainer, Field, FormContainerWrapper, Layout, Setter, EditorQuill, EditorWang, EditorWang2, EditorWang3, WangEditor, WangEditorNext } from './components';
|
1
|
+
import { FormContainer, Field, FormContainerWrapper, Layout, Setter, EditorQuill, EditorWang, EditorWang2, EditorWang3, WangEditor, WangEditorNext, Show } from './components';
|
2
2
|
import './App.css';
|
3
3
|
import { Button, Input, Select } from 'antd';
|
4
4
|
import React, { useEffect, useState } from 'react';
|
@@ -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 = () => {
|
@@ -179,7 +179,7 @@ function App() {
|
|
179
179
|
|
180
180
|
<FormContainerWrapper cols={cols} className="" ref={formRef} >
|
181
181
|
<Layout.FormRow layout={'1'}>
|
182
|
-
<
|
182
|
+
<Show.WithTable label="测试关联子表" __id="withtable1"
|
183
183
|
filterRules={[
|
184
184
|
{
|
185
185
|
"value": {
|
@@ -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
|
-
|
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] =
|
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
|
-
|
236
|
-
|
237
|
-
|
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 })
|
492
|
-
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "
|
491
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode })
|
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,25 +507,26 @@ 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
|
-
|
522
|
+
let element = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender })
|
523
|
+
return componentName === "show.WithTable" ? <>{element}</> : <Form.Item
|
523
524
|
style={{ marginBottom: 0 }}
|
524
525
|
label=""
|
525
526
|
name={identifier}
|
526
527
|
rules={rules}
|
527
528
|
>
|
528
|
-
{
|
529
|
+
{element}
|
529
530
|
</Form.Item>
|
530
531
|
}}
|
531
532
|
</Form.Item>
|
@@ -537,17 +538,17 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
537
538
|
name={identifier}
|
538
539
|
rules={rules}
|
539
540
|
>
|
540
|
-
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange,initializeFormRender })}
|
541
|
+
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender })}
|
541
542
|
</Form.Item>
|
542
543
|
}
|
543
544
|
return (
|
544
545
|
<Col
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
546
|
+
key={identifier || `col-${index}`}
|
547
|
+
span={props.calcHidden ? 0 : (isLayoutComponent ? 24 : 24 / cols)}
|
548
|
+
style={{ marginBottom: 0 }}
|
549
|
+
>
|
550
|
+
{childComponent}
|
551
|
+
</Col>
|
551
552
|
);
|
552
553
|
})}
|
553
554
|
</Row>
|
@@ -559,6 +560,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
559
560
|
// console.log("changedValues", changedValues)
|
560
561
|
// console.log("allValues", allValues)
|
561
562
|
}} onFieldsChange={handleFieldsChange}>
|
563
|
+
<Form.Item name="__id" hidden={true}>
|
564
|
+
<input type="hidden" />
|
565
|
+
</Form.Item>
|
562
566
|
{formContent}
|
563
567
|
</Form>
|
564
568
|
);
|
@@ -41,7 +41,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
41
41
|
let childComponent = null
|
42
42
|
if (componentName == 'Field.Table')
|
43
43
|
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: name, initializeFormRender, mode })
|
44
|
-
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "
|
44
|
+
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
45
45
|
childComponent = <Form.Item
|
46
46
|
hidden={hidden}
|
47
47
|
style={{ margin: 0 }}
|
@@ -68,13 +68,14 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
68
68
|
>
|
69
69
|
{({ getFieldsValue }) => {
|
70
70
|
const fieldsValue = getFieldsValue();
|
71
|
-
|
71
|
+
let element = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender })
|
72
|
+
return componentName === "Show.WithTable" ? <>{element}</> : <Form.Item
|
72
73
|
style={{ marginBottom: 0 }}
|
73
74
|
label=""
|
74
75
|
name={identifier}
|
75
76
|
rules={rules}
|
76
77
|
>
|
77
|
-
{
|
78
|
+
{element}
|
78
79
|
</Form.Item>
|
79
80
|
}}
|
80
81
|
</Form.Item>
|
@@ -99,38 +100,6 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
99
100
|
);
|
100
101
|
|
101
102
|
|
102
|
-
if (name) {
|
103
|
-
const rules = []
|
104
|
-
if (props.isRequired)
|
105
|
-
rules.push({ required: true, message: `${props.label}必须填写` });
|
106
|
-
if (props.rules)
|
107
|
-
if (Array.isArray(props.rules)) {
|
108
|
-
const pattern = props.rules.join("|")
|
109
|
-
rules.push({ pattern: new RegExp(pattern), message: props.rulesFailMessage ? props.rulesFailMessage : `${props.label}格式错误` })
|
110
|
-
}
|
111
|
-
else {
|
112
|
-
rules.push({ pattern: new RegExp(props.rules), message: props.rulesFailMessage ? props.rulesFailMessage : `${props.label}格式错误` })
|
113
|
-
}
|
114
|
-
return (
|
115
|
-
colSpans?.[index] && <Col span={colSpans[index]} key={index}>
|
116
|
-
<Form.Item
|
117
|
-
style={{ marginBottom: 0 }}
|
118
|
-
label=""
|
119
|
-
key={`${name}-form-item`}
|
120
|
-
name={name}
|
121
|
-
rules={rules}
|
122
|
-
>
|
123
|
-
{childComponent}
|
124
|
-
</Form.Item>
|
125
|
-
</Col>
|
126
|
-
);
|
127
|
-
} else {
|
128
|
-
return (
|
129
|
-
colSpans?.[index] && <Col span={colSpans[index]} key={index}>
|
130
|
-
{childComponent}
|
131
|
-
</Col>
|
132
|
-
);
|
133
|
-
}
|
134
103
|
});
|
135
104
|
}, [children, colSpans]);
|
136
105
|
|
package/src/components/index.jsx
CHANGED
@@ -36,8 +36,7 @@ const Field = {
|
|
36
36
|
Custom,
|
37
37
|
UserSelect,
|
38
38
|
DeptSelect,
|
39
|
-
PostSelect
|
40
|
-
WithTable
|
39
|
+
PostSelect
|
41
40
|
}
|
42
41
|
Object.keys(Field).forEach(key => {
|
43
42
|
Field[key].displayName = `Field.${key}`;
|
@@ -50,10 +49,19 @@ const Layout = {
|
|
50
49
|
FormGroupTitle: LayoutFormGroupTitle,
|
51
50
|
TableCol
|
52
51
|
}
|
52
|
+
|
53
53
|
Object.keys(Layout).forEach(key => {
|
54
54
|
Layout[key].displayName = `Layout.${key}`;
|
55
55
|
});
|
56
|
-
|
56
|
+
// 纯显示类型的组件
|
57
|
+
const Show = {
|
58
|
+
WithTable
|
59
|
+
}
|
60
|
+
Object.keys(Show).forEach(key => {
|
61
|
+
Show[key].displayName = `Show.${key}`;
|
62
|
+
});
|
63
|
+
|
64
|
+
export { FormContainer, Field ,FormContainerWrapper,Layout,Show }
|
57
65
|
import { default as OptionSetter} from './setter/optionsetter'
|
58
66
|
const Setter = {
|
59
67
|
OptionSetter
|