lu-lowcode-package-form 0.10.21 → 0.10.27
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 +301 -301
- package/dist/index.es.js +16226 -16194
- package/package.json +1 -1
- package/src/App.jsx +7 -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 +21 -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,7 @@ function App() {
|
|
|
175
179
|
|
|
176
180
|
<FormContainerWrapper cols={cols} className="" ref={formRef} >
|
|
177
181
|
|
|
182
|
+
<Field.Number label="测试" __id="shuilv111" isRequired={true} calcHidden={testCalcHidden} />
|
|
178
183
|
<Field.UserSelect label="选择用户" __id="userselect" defaultValue={[{ id: 1, username: "十天" }]} />
|
|
179
184
|
<Layout.FormGroupTitle title={"基本信息"} />
|
|
180
185
|
<Field.WithSingleSelect
|
|
@@ -195,7 +200,7 @@ function App() {
|
|
|
195
200
|
|
|
196
201
|
]} label="发票类型" options={[{ label: '选项1', value: '1', shuilv: 15, }, { label: '选项2', value: '2', shuilv: 50 }, { label: '选项3', value: '3', shuilv: 2 }]} __id="fapiaoleixing" />
|
|
197
202
|
|
|
198
|
-
<Field.Number label="税率(%)" __id="shuilv" />
|
|
203
|
+
<Field.Number label="税率(%)" __id="shuilv" calcHidden={true} />
|
|
199
204
|
|
|
200
205
|
<Field.WithSingleSelect isRequired={true} ref={testRef} fillRules={[
|
|
201
206
|
{
|
|
@@ -295,7 +300,7 @@ function App() {
|
|
|
295
300
|
<Field.Input label="测试被填充1" __id="tcinput1" />
|
|
296
301
|
<Field.Input label="测试被填充2" __id="tcinput2" />
|
|
297
302
|
|
|
298
|
-
<Field.Number label="税率(%)" __id="shuilv_table" withIds={[
|
|
303
|
+
<Field.Number label="税率(%)" isRequired={true} calcHidden={true} __id="shuilv_table" withIds={[
|
|
299
304
|
"shuilv"
|
|
300
305
|
]}
|
|
301
306
|
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
|
}}
|
|
@@ -28,7 +28,8 @@ function batchElements(elements, groupSize) {
|
|
|
28
28
|
groupedElements.push([element]);
|
|
29
29
|
} else {
|
|
30
30
|
tempArray.push(element);
|
|
31
|
-
|
|
31
|
+
const visibleElementsCount = tempArray.filter(el => !el?.props?.calcHidden).length;
|
|
32
|
+
if (visibleElementsCount === groupSize) {
|
|
32
33
|
groupedElements.push(tempArray);
|
|
33
34
|
tempArray = [];
|
|
34
35
|
}
|
|
@@ -61,10 +62,13 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
61
62
|
}), []);
|
|
62
63
|
|
|
63
64
|
useEffect(() => {
|
|
64
|
-
|
|
65
|
-
setFormContent(renderChildren());
|
|
65
|
+
initializeFormRender();
|
|
66
66
|
}, [children, cols]);
|
|
67
67
|
|
|
68
|
+
const initializeFormRender = ()=>{
|
|
69
|
+
initializeDependencyMap();
|
|
70
|
+
setFormContent(renderChildren());
|
|
71
|
+
}
|
|
68
72
|
|
|
69
73
|
const lastFormValues = React.useRef(null);
|
|
70
74
|
const getLastFieldValue = (path) => {
|
|
@@ -465,6 +469,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
465
469
|
const identifier = componentId || __id;
|
|
466
470
|
const isLayoutComponent = componentName && componentName.startsWith('Layout.');
|
|
467
471
|
const isTable = componentName && componentName == 'Field.Table';
|
|
472
|
+
const hidden = props.calcHidden && mode != "desgin";
|
|
473
|
+
|
|
468
474
|
const rules = []
|
|
469
475
|
if (props.isRequired)
|
|
470
476
|
rules.push({ required: true, message: `${props.label}必须填写` });
|
|
@@ -481,9 +487,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
481
487
|
}
|
|
482
488
|
let childComponent
|
|
483
489
|
if (isTable || isLayoutComponent)
|
|
484
|
-
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange })
|
|
490
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange,initializeFormRender,mode })
|
|
485
491
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect") {
|
|
486
492
|
childComponent = <Form.Item
|
|
493
|
+
hidden={hidden}
|
|
487
494
|
style={{ margin: 0 }}
|
|
488
495
|
shouldUpdate={(prevValues, curValues) => {
|
|
489
496
|
let result = false;
|
|
@@ -515,24 +522,29 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
515
522
|
name={identifier}
|
|
516
523
|
rules={rules}
|
|
517
524
|
>
|
|
518
|
-
{React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue })}
|
|
525
|
+
{React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue,initializeFormRender })}
|
|
519
526
|
</Form.Item>
|
|
520
527
|
}}
|
|
521
528
|
</Form.Item>
|
|
522
529
|
} else {
|
|
523
530
|
childComponent = <Form.Item
|
|
531
|
+
hidden={hidden}
|
|
524
532
|
style={{ marginBottom: 0 }}
|
|
525
533
|
label=""
|
|
526
534
|
name={identifier}
|
|
527
535
|
rules={rules}
|
|
528
536
|
>
|
|
529
|
-
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange })}
|
|
537
|
+
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange,initializeFormRender })}
|
|
530
538
|
</Form.Item>
|
|
531
539
|
}
|
|
532
540
|
return (
|
|
533
|
-
<Col
|
|
534
|
-
|
|
535
|
-
|
|
541
|
+
<Col
|
|
542
|
+
key={identifier || `col-${index}`}
|
|
543
|
+
span={props.calcHidden ? 0 : (isLayoutComponent ? 24 : 24 / cols)}
|
|
544
|
+
style={{ marginBottom: 0 }}
|
|
545
|
+
>
|
|
546
|
+
{childComponent}
|
|
547
|
+
</Col>
|
|
536
548
|
);
|
|
537
549
|
})}
|
|
538
550
|
</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) {
|