lu-lowcode-package-form 0.10.21 → 0.10.28
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 +338 -338
- package/dist/index.es.js +29421 -29387
- package/package.json +1 -1
- package/src/App.jsx +10 -2
- package/src/components/field/base.jsx +15 -1
- package/src/components/field/table/index.jsx +12 -7
- package/src/components/form-container/index.jsx +22 -9
- package/src/components/form-container/layout/form-row.jsx +3 -3
package/package.json
CHANGED
package/src/App.jsx
CHANGED
|
@@ -78,6 +78,7 @@ const treeData = [
|
|
|
78
78
|
function App() {
|
|
79
79
|
const formRef = React.createRef();
|
|
80
80
|
const testRef = React.useRef()
|
|
81
|
+
const [testCalcHidden, setTestCalcHidden] = useState(false);
|
|
81
82
|
useEffect(() => {
|
|
82
83
|
// console.log("testRef //////", testRef.current)
|
|
83
84
|
}, [testRef.current])
|
|
@@ -116,6 +117,9 @@ function App() {
|
|
|
116
117
|
return (
|
|
117
118
|
<div className='fflex fflex-col fitems-center fh-screen '>
|
|
118
119
|
<div className='fflex fgap-2 fitems-center fjustify-center fw-full'>
|
|
120
|
+
<Button type="primary" onClick={()=>{
|
|
121
|
+
setTestCalcHidden(!testCalcHidden)
|
|
122
|
+
}}>testCalcHidden</Button>
|
|
119
123
|
<Button type="primary" onClick={validateFields}>validateFields</Button>
|
|
120
124
|
<Button type="primary" onClick={getFormFields}>GetValues</Button>
|
|
121
125
|
<Button type="primary" onClick={setFormFields}>SetValues</Button>
|
|
@@ -175,6 +179,10 @@ function App() {
|
|
|
175
179
|
|
|
176
180
|
<FormContainerWrapper cols={cols} className="" ref={formRef} >
|
|
177
181
|
|
|
182
|
+
<Field.Number label="测试" __id="aa2" />
|
|
183
|
+
<Field.Number label="测试" __id="aa3" />
|
|
184
|
+
<Field.Number label="测试" __id="aa1" isRequired={true} calcHidden={true} />
|
|
185
|
+
<Field.Number label="测试" __id="aa4" />
|
|
178
186
|
<Field.UserSelect label="选择用户" __id="userselect" defaultValue={[{ id: 1, username: "十天" }]} />
|
|
179
187
|
<Layout.FormGroupTitle title={"基本信息"} />
|
|
180
188
|
<Field.WithSingleSelect
|
|
@@ -195,7 +203,7 @@ function App() {
|
|
|
195
203
|
|
|
196
204
|
]} label="发票类型" options={[{ label: '选项1', value: '1', shuilv: 15, }, { label: '选项2', value: '2', shuilv: 50 }, { label: '选项3', value: '3', shuilv: 2 }]} __id="fapiaoleixing" />
|
|
197
205
|
|
|
198
|
-
<Field.Number label="税率(%)" __id="shuilv" />
|
|
206
|
+
<Field.Number label="税率(%)" __id="shuilv" calcHidden={true} />
|
|
199
207
|
|
|
200
208
|
<Field.WithSingleSelect isRequired={true} ref={testRef} fillRules={[
|
|
201
209
|
{
|
|
@@ -295,7 +303,7 @@ function App() {
|
|
|
295
303
|
<Field.Input label="测试被填充1" __id="tcinput1" />
|
|
296
304
|
<Field.Input label="测试被填充2" __id="tcinput2" />
|
|
297
305
|
|
|
298
|
-
<Field.Number label="税率(%)" __id="shuilv_table" withIds={[
|
|
306
|
+
<Field.Number label="税率(%)" isRequired={true} calcHidden={true} __id="shuilv_table" withIds={[
|
|
299
307
|
"shuilv"
|
|
300
308
|
]}
|
|
301
309
|
withFill={{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
2
|
|
|
3
3
|
const FieldLable = ({ value, onChange }) => {
|
|
4
4
|
const [text, setText] = useState("");
|
|
@@ -24,19 +24,33 @@ export const BaseWrapper = ({
|
|
|
24
24
|
hidePrompt = false,
|
|
25
25
|
subTableIndex,
|
|
26
26
|
addWrapper = true,
|
|
27
|
+
calcHidden,
|
|
27
28
|
defaultValue,
|
|
28
29
|
value,
|
|
29
30
|
onChange,
|
|
30
31
|
readonly,
|
|
31
32
|
isRequired,
|
|
33
|
+
initializeFormRender,
|
|
32
34
|
...otherProps
|
|
33
35
|
}) => {
|
|
36
|
+
const calcHiddenRef = useRef(false);
|
|
37
|
+
useEffect(()=>{
|
|
38
|
+
console.log("typeof initializeFormRender", typeof initializeFormRender)
|
|
39
|
+
console.log("calcHidden", calcHidden)
|
|
40
|
+
console.log("calcHiddenRef.current", calcHiddenRef.current)
|
|
41
|
+
if (calcHiddenRef.current != calcHidden)
|
|
42
|
+
{
|
|
43
|
+
typeof initializeFormRender == "function" && initializeFormRender();
|
|
44
|
+
calcHiddenRef.current = calcHidden;
|
|
45
|
+
}
|
|
46
|
+
},[calcHidden])
|
|
34
47
|
useEffect(()=>{
|
|
35
48
|
if (defaultValue && typeof onChange === "function" && !value) {
|
|
36
49
|
// console.log("defaultValue changed", defaultValue)
|
|
37
50
|
onChange(defaultValue)
|
|
38
51
|
}
|
|
39
52
|
},[])
|
|
53
|
+
// if (noShow) return null;
|
|
40
54
|
if (!addWrapper) return children;
|
|
41
55
|
// 不接管只读属性的组件
|
|
42
56
|
const ignoreReadonly = ["UploadImage", "UploadFile", "Table", "WithMultipleSelect", "WithSingleSelect"]
|
|
@@ -19,17 +19,18 @@ const TableAction = ({ label, subTableIndex, children, subTableHead = false, ...
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
const TableCol = ({ children, width, ...props }) => {
|
|
22
|
+
const TableCol = ({ children, width, hidden, ...props }) => {
|
|
23
23
|
const [sWidth, setSWidth] = useState(0);
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
setSWidth(width);
|
|
26
26
|
}, [width]);
|
|
27
|
+
if (hidden) return children;
|
|
27
28
|
return <div className="fflex-1 fpx-1" style={{ minWidth: `${sWidth}px` }} {...props}>
|
|
28
29
|
{children}
|
|
29
30
|
</div>
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, ...props }) => {
|
|
33
|
+
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName,initializeFormRender, mode, ...props }) => {
|
|
33
34
|
useEffect(()=>{
|
|
34
35
|
console.log("Table form reload",form)
|
|
35
36
|
},[form])
|
|
@@ -66,9 +67,10 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
|
66
67
|
return <div className="fw-full ">
|
|
67
68
|
<div className="fw-full frelative fmin-h-20 foverflow-x-auto">
|
|
68
69
|
{fields.length === 0 && <div key={`tableHead`} className="fborder-b fflex flex-nowrap fmin-w-full ">
|
|
69
|
-
{React.Children.map(children, (child, childIndex) => {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
{React.Children.map(children, ( child, childIndex) => {
|
|
71
|
+
const hidden = child?.props?.calcHidden;
|
|
72
|
+
return <TableCol width={150} key={`row_${0}_col_${childIndex}`} hidden={hidden}>
|
|
73
|
+
{hidden ? null : React.cloneElement(child, {
|
|
72
74
|
key: `row_${0}_child_${childIndex}`,
|
|
73
75
|
subTable: true,
|
|
74
76
|
subTableHead: true,
|
|
@@ -102,9 +104,11 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
|
102
104
|
const componentName = child.type?.displayName || _componentName;
|
|
103
105
|
const identifier = componentId || __id;
|
|
104
106
|
|
|
105
|
-
|
|
107
|
+
const hidden = props.calcHidden && mode != "desgin";
|
|
108
|
+
return <TableCol width={150} key={`row_${field.key}_col_${childIndex}`} hidden={hidden}>
|
|
106
109
|
<Form.Item
|
|
107
110
|
style={{ margin: 0 }}
|
|
111
|
+
hidden={hidden}
|
|
108
112
|
shouldUpdate={(prevValues, curValues) => {
|
|
109
113
|
let result = false;
|
|
110
114
|
if (
|
|
@@ -143,7 +147,7 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
|
143
147
|
{( {getFieldsValue}) => {
|
|
144
148
|
const fieldsValue = getFieldsValue();
|
|
145
149
|
// const newid = nanoid()
|
|
146
|
-
console.log(`[${child.props.label}] key`,`row_${field.key}_child_${childIndex}_${newidRefs.current[childIndex]}` )
|
|
150
|
+
// console.log(`[${child.props.label}] key`,`row_${field.key}_child_${childIndex}_${newidRefs.current[childIndex]}` )
|
|
147
151
|
return <Form.Item
|
|
148
152
|
label=""
|
|
149
153
|
style={{ marginBottom: 0 }}
|
|
@@ -158,6 +162,7 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
|
158
162
|
form,
|
|
159
163
|
fieldName: [fieldName, field.name, col_id],
|
|
160
164
|
fieldsValue:fieldsValue,
|
|
165
|
+
initializeFormRender,
|
|
161
166
|
})}
|
|
162
167
|
</Form.Item>
|
|
163
168
|
}}
|
|
@@ -13,6 +13,7 @@ function batchElements(elements, groupSize) {
|
|
|
13
13
|
|
|
14
14
|
const fillWithReactElement = (size, array) => {
|
|
15
15
|
const missingElementsCount = size - array.length;
|
|
16
|
+
if (missingElementsCount > 0)
|
|
16
17
|
array.push(...new Array(missingElementsCount).fill(React.createElement('div')));
|
|
17
18
|
};
|
|
18
19
|
|
|
@@ -28,7 +29,8 @@ function batchElements(elements, groupSize) {
|
|
|
28
29
|
groupedElements.push([element]);
|
|
29
30
|
} else {
|
|
30
31
|
tempArray.push(element);
|
|
31
|
-
|
|
32
|
+
const visibleElementsCount = tempArray.filter(el => !el?.props?.calcHidden).length;
|
|
33
|
+
if (visibleElementsCount === groupSize) {
|
|
32
34
|
groupedElements.push(tempArray);
|
|
33
35
|
tempArray = [];
|
|
34
36
|
}
|
|
@@ -61,10 +63,13 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
61
63
|
}), []);
|
|
62
64
|
|
|
63
65
|
useEffect(() => {
|
|
64
|
-
|
|
65
|
-
setFormContent(renderChildren());
|
|
66
|
+
initializeFormRender();
|
|
66
67
|
}, [children, cols]);
|
|
67
68
|
|
|
69
|
+
const initializeFormRender = ()=>{
|
|
70
|
+
initializeDependencyMap();
|
|
71
|
+
setFormContent(renderChildren());
|
|
72
|
+
}
|
|
68
73
|
|
|
69
74
|
const lastFormValues = React.useRef(null);
|
|
70
75
|
const getLastFieldValue = (path) => {
|
|
@@ -465,6 +470,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
465
470
|
const identifier = componentId || __id;
|
|
466
471
|
const isLayoutComponent = componentName && componentName.startsWith('Layout.');
|
|
467
472
|
const isTable = componentName && componentName == 'Field.Table';
|
|
473
|
+
const hidden = props.calcHidden && mode != "desgin";
|
|
474
|
+
|
|
468
475
|
const rules = []
|
|
469
476
|
if (props.isRequired)
|
|
470
477
|
rules.push({ required: true, message: `${props.label}必须填写` });
|
|
@@ -481,9 +488,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
481
488
|
}
|
|
482
489
|
let childComponent
|
|
483
490
|
if (isTable || isLayoutComponent)
|
|
484
|
-
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange })
|
|
491
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange,initializeFormRender,mode })
|
|
485
492
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect") {
|
|
486
493
|
childComponent = <Form.Item
|
|
494
|
+
hidden={hidden}
|
|
487
495
|
style={{ margin: 0 }}
|
|
488
496
|
shouldUpdate={(prevValues, curValues) => {
|
|
489
497
|
let result = false;
|
|
@@ -515,24 +523,29 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
515
523
|
name={identifier}
|
|
516
524
|
rules={rules}
|
|
517
525
|
>
|
|
518
|
-
{React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue })}
|
|
526
|
+
{React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue,initializeFormRender })}
|
|
519
527
|
</Form.Item>
|
|
520
528
|
}}
|
|
521
529
|
</Form.Item>
|
|
522
530
|
} else {
|
|
523
531
|
childComponent = <Form.Item
|
|
532
|
+
hidden={hidden}
|
|
524
533
|
style={{ marginBottom: 0 }}
|
|
525
534
|
label=""
|
|
526
535
|
name={identifier}
|
|
527
536
|
rules={rules}
|
|
528
537
|
>
|
|
529
|
-
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange })}
|
|
538
|
+
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange,initializeFormRender })}
|
|
530
539
|
</Form.Item>
|
|
531
540
|
}
|
|
532
541
|
return (
|
|
533
|
-
<Col
|
|
534
|
-
|
|
535
|
-
|
|
542
|
+
<Col
|
|
543
|
+
key={identifier || `col-${index}`}
|
|
544
|
+
span={props.calcHidden ? 0 : (isLayoutComponent ? 24 : 24 / cols)}
|
|
545
|
+
style={{ marginBottom: 0 }}
|
|
546
|
+
>
|
|
547
|
+
{childComponent}
|
|
548
|
+
</Col>
|
|
536
549
|
);
|
|
537
550
|
})}
|
|
538
551
|
</Row>
|
|
@@ -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 }) => {
|
|
4
|
+
const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form,initializeFormRender ,mode}) => {
|
|
5
5
|
layout = layout || '1';
|
|
6
6
|
const getColSpan = (layoutStr) => {
|
|
7
7
|
const layoutArray = layoutStr.split(',').map(Number);
|
|
@@ -25,9 +25,9 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
|
25
25
|
|
|
26
26
|
let childComponent = null
|
|
27
27
|
if (componentName == 'Field.Table')
|
|
28
|
-
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form ,fieldName:name})
|
|
28
|
+
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form ,fieldName:name,initializeFormRender,mode})
|
|
29
29
|
else if (React.isValidElement(child))
|
|
30
|
-
childComponent = React.cloneElement(child, { form: form ,fieldName:name })
|
|
30
|
+
childComponent = React.cloneElement(child, { form: form ,fieldName:name,initializeFormRender })
|
|
31
31
|
else childComponent = child
|
|
32
32
|
|
|
33
33
|
if (name) {
|