lu-lowcode-package-form 0.9.88 → 0.9.90
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 +248 -248
- package/dist/index.es.js +8009 -7982
- package/package.json +1 -1
- package/src/App.jsx +1 -1
- package/src/components/field/select/select.jsx +7 -3
- package/src/components/field/switch/index.jsx +15 -15
- package/src/components/field/table/index.jsx +6 -4
- package/src/components/form-container/index.jsx +18 -9
- package/src/components/form-container/layout/form-row.jsx +13 -5
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -101,7 +101,7 @@ function App() {
|
|
101
101
|
const setFormFields = () => {
|
102
102
|
formRef?.current?.formRef?.setFieldsValue({
|
103
103
|
datetime: "2024-08-25", datetime2: "2024-08-25", datetime3: "",
|
104
|
-
"remark11": "{
|
104
|
+
"remark11": { label: '选项1', value: '1', name: "1111", table: "[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" },
|
105
105
|
"remark12": [{ "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" }],
|
106
106
|
"userselect": "1213131", "DeptSelect": ["leaf11"],
|
107
107
|
"searchuser": [{ "id": 2, "name": "2222", "label": "2222", "value": 2 }, { "id": 4, "name": "4444", "label": "4444", "value": 4 }],
|
@@ -71,16 +71,20 @@ const MultipleSelect = ({ onChange, value, ...props }) => {
|
|
71
71
|
* @param {*}
|
72
72
|
* @returns
|
73
73
|
*/
|
74
|
-
const WithSingleSelect = ({ readItemRender, readonly, onChange, value, ...props }) => {
|
74
|
+
const WithSingleSelect = ({ readItemRender, readonly, onChange, onCustomChange,value, form,fieldName, ...props }) => {
|
75
75
|
|
76
76
|
React.useEffect(() => {
|
77
77
|
if (value && typeof value === "string") {
|
78
78
|
try {
|
79
79
|
value = JSON.parse(value)
|
80
|
-
|
80
|
+
// typeof onCustomChange === "function" && onCustomChange(value)
|
81
|
+
// onChange(value)
|
82
|
+
form?.setFieldValue(fieldName, value )
|
83
|
+
console.log("WithSingleSelect useEffect onChange////// form",form)
|
81
84
|
console.log("WithSingleSelect useEffect onChange////// value",value)
|
85
|
+
console.log("WithSingleSelect useEffect onChange////// props",props)
|
82
86
|
} catch (error) {
|
83
|
-
|
87
|
+
console.log("WithSingleSelect useEffect error",error)
|
84
88
|
}
|
85
89
|
}
|
86
90
|
|
@@ -1,23 +1,23 @@
|
|
1
1
|
import React, { useEffect } from 'react';
|
2
2
|
import { Switch as OriginalSwitch } from 'antd';
|
3
3
|
import { BaseWrapper } from "../base.jsx"
|
4
|
-
const Switch = ({value,onChange,...props}) => {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}
|
4
|
+
const Switch = ({value,onChange, form,fieldName,...props}) => {
|
5
|
+
let tem_value = false
|
6
|
+
if( typeof value === "boolean" )
|
7
|
+
tem_value = value
|
8
|
+
else if (typeof value === "string")
|
9
|
+
tem_value =value == "1" || value == "true"
|
10
|
+
else if (typeof value == "number")
|
11
|
+
tem_value = value == 1
|
12
|
+
|
13
|
+
if (value!== tem_value)
|
14
|
+
{
|
15
|
+
form?.setFieldValue(fieldName,tem_value)
|
16
|
+
// onChange(tem_value)
|
17
|
+
}
|
18
18
|
return (
|
19
19
|
<BaseWrapper {...props}>
|
20
|
-
<OriginalSwitch {...props} onChange={onChange} value={
|
20
|
+
<OriginalSwitch {...props} onChange={onChange} value={value} />
|
21
21
|
</BaseWrapper>
|
22
22
|
);
|
23
23
|
}
|
@@ -28,21 +28,21 @@ const TableCol = ({ children, width, ...props }) => {
|
|
28
28
|
</div>
|
29
29
|
}
|
30
30
|
|
31
|
-
const Table = ({ children, onTableAddRow,disabled,readonly,onTableRemoveRow,
|
31
|
+
const Table = ({ children, onTableAddRow,disabled,readonly,onTableRemoveRow, form, fieldName,...props }) => {
|
32
32
|
const [init, setInit] = useState(false);
|
33
33
|
const name = props.componentId || props.__id
|
34
34
|
const childrenIds = React.Children.map(children, (child) => `${name}.${child.props.componentId || child.props.__id}`)
|
35
35
|
const rules = []
|
36
|
-
const handleAdd = (
|
36
|
+
const handleAdd = () => {
|
37
37
|
if (!init) setInit(true);
|
38
|
-
|
38
|
+
form?.setFieldValue(fieldName, [{}] )
|
39
39
|
}
|
40
40
|
|
41
41
|
if (props.isRequired)
|
42
42
|
rules.push({ required: true, message: `子表[${props.label}]必须填写` });
|
43
43
|
return <Form.List name={name} rules={rules}>
|
44
44
|
{(fields, { add, remove }) => {
|
45
|
-
if (fields.length === 0 && !init) handleAdd(
|
45
|
+
if (fields.length === 0 && !init) handleAdd();
|
46
46
|
return <div className="fw-full ">
|
47
47
|
<div className="fw-full frelative fmin-h-20 foverflow-x-auto">
|
48
48
|
{fields.length === 0 && <div key={`tableHead`} className="fborder-b fflex flex-nowrap fmin-w-full ">
|
@@ -91,6 +91,8 @@ const Table = ({ children, onTableAddRow,disabled,readonly,onTableRemoveRow, ...
|
|
91
91
|
subTable: true,
|
92
92
|
subTableIndex: index,
|
93
93
|
subTableHead: index == 0,
|
94
|
+
form,
|
95
|
+
fieldName: [field.name, col_id],
|
94
96
|
})}
|
95
97
|
</Form.Item>
|
96
98
|
</TableCol>
|
@@ -175,7 +175,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
175
175
|
if (dependencyMap.current.has(target)) {
|
176
176
|
let tableChildren = dependencyMap.current.get(target)?.component?.props?.children
|
177
177
|
if (Array.isArray(tableChildren) && tableChildren.length > 0) idGroups.push(tableChildren.map(item => `${source}.${item?.props?.componentId || item?.props?.__id}`))
|
178
|
-
|
178
|
+
|
179
179
|
}
|
180
180
|
if (source_value && typeof source_value == "string") {
|
181
181
|
try {
|
@@ -221,8 +221,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
221
221
|
handleFieldsWith(target, form.getFieldsValue())
|
222
222
|
// if (idGroups.length > 0) handleTableAddRow(idGroups)
|
223
223
|
}, 0);
|
224
|
-
|
225
|
-
|
224
|
+
|
225
|
+
|
226
226
|
// if (idGroups.length > 0) setTimeout(() => handleTableAddRow(idGroups), 0)
|
227
227
|
}
|
228
228
|
|
@@ -234,7 +234,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
234
234
|
})
|
235
235
|
debounceHandleFieldsChange();
|
236
236
|
}
|
237
|
-
console.log("idGroups",idGroups)
|
237
|
+
console.log("idGroups", idGroups)
|
238
238
|
if (idGroups.length > 0) idGroups.forEach(ids => { if (Array.isArray(ids) && ids.length > 0) handleTableAddRow(ids) })
|
239
239
|
}, 200)
|
240
240
|
|
@@ -339,7 +339,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
339
339
|
}
|
340
340
|
|
341
341
|
if (formula && formula.length > 0) {
|
342
|
-
console.log(`${
|
342
|
+
console.log(`${childIdentifier} 计算公式:`, formula)
|
343
343
|
const formulaResult = evalFormula(formula);
|
344
344
|
form.setFieldValue(childIdentifier, formulaResult)
|
345
345
|
handleFieldsWith(childIdentifier, form.getFieldsValue())
|
@@ -392,6 +392,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
392
392
|
}, 200);
|
393
393
|
|
394
394
|
const handleFieldsChange = (changedFields) => {
|
395
|
+
console.log("changedFields", changedFields)
|
395
396
|
changedFields.filter(field => {
|
396
397
|
if (field.name && field.name.length > 0) {
|
397
398
|
// const fieldKey = field.name.filter(item => typeof item == "string").join(".")
|
@@ -458,9 +459,14 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
458
459
|
else {
|
459
460
|
rules.push({ pattern: new RegExp(props.rules), message: props.rulesFailMessage ? props.rulesFailMessage : `${props.label}格式错误` })
|
460
461
|
}
|
461
|
-
|
462
|
-
|
463
|
-
|
462
|
+
const onCustomChange = (value) =>{
|
463
|
+
form.setFieldValue(identifier,value)
|
464
|
+
}
|
465
|
+
let childComponent
|
466
|
+
if (isTable || isLayoutComponent)
|
467
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName:identifier,onCustomChange })
|
468
|
+
else {
|
469
|
+
childComponent = React.cloneElement(child, { form: form , fieldName:identifier,onCustomChange})
|
464
470
|
}
|
465
471
|
return (
|
466
472
|
<Col key={identifier || `col-${index}`} span={isLayoutComponent ? 24 : 24 / group.length} style={{ marginBottom: 0 }}>
|
@@ -480,7 +486,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
480
486
|
};
|
481
487
|
|
482
488
|
return (
|
483
|
-
<Form form={form} className={"form-container fp-0 fw-full fh-full box-border fflex fflex-col fgap-y-2" + (mode == "desgin" ? " fp-6" : "")}
|
489
|
+
<Form form={form} className={"form-container fp-0 fw-full fh-full box-border fflex fflex-col fgap-y-2" + (mode == "desgin" ? " fp-6" : "")} onValuesChange={(changedValues, allValues)=>{
|
490
|
+
console.log("changedValues", changedValues)
|
491
|
+
// console.log("allValues", allValues)
|
492
|
+
}} onFieldsChange={handleFieldsChange}>
|
484
493
|
{formContent}
|
485
494
|
</Form>
|
486
495
|
);
|
@@ -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}) => {
|
4
|
+
const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form }) => {
|
5
5
|
layout = layout || '1';
|
6
6
|
const getColSpan = (layoutStr) => {
|
7
7
|
const layoutArray = layoutStr.split(',').map(Number);
|
@@ -18,10 +18,18 @@ const LayoutFormRow = ({ children, layout, onTableAddRow,onTableRemoveRow}) => {
|
|
18
18
|
const name = props?.componentId || props?.__id;
|
19
19
|
var componentName = child.type?.displayName || child.props?._componentName;
|
20
20
|
// console.log("initializeDependencyMap componentName", componentName)
|
21
|
-
let childComponent = child;
|
22
|
-
if (componentName == 'Field.Table')
|
23
|
-
|
24
|
-
|
21
|
+
// let childComponent = child;
|
22
|
+
// if (componentName == 'Field.Table')
|
23
|
+
// childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow })
|
24
|
+
|
25
|
+
|
26
|
+
let childComponent = null
|
27
|
+
if (componentName == 'Field.Table')
|
28
|
+
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form ,fieldName:name})
|
29
|
+
else if (React.isValidElement(child))
|
30
|
+
childComponent = React.cloneElement(child, { form: form ,fieldName:name })
|
31
|
+
else childComponent = child
|
32
|
+
|
25
33
|
if (name) {
|
26
34
|
return (
|
27
35
|
colSpans?.[index] && <Col span={colSpans[index]} key={index}>
|