lu-lowcode-package-form 0.11.16 → 0.11.18
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 +158 -158
- package/dist/index.es.js +8099 -8092
- package/package.json +1 -1
- package/src/App.jsx +54 -1
- package/src/components/field/select/search-select.jsx +4 -4
- package/src/components/field/table/index.jsx +13 -4
- package/src/components/form-container/index.jsx +36 -28
- package/src/components/form-container/layout/form-row.jsx +12 -5
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -197,7 +197,40 @@ function App() {
|
|
197
197
|
option_label="label"
|
198
198
|
option_value="value"
|
199
199
|
option_search="label" label="测试填充2" __id="fill_tianchong1_test" />
|
200
|
-
|
200
|
+
<Field.RadioGroup
|
201
|
+
buttonStyle="solid"
|
202
|
+
label="菜单类型"
|
203
|
+
__id="routeType"
|
204
|
+
defaultValue={2}
|
205
|
+
options={[{ label: "菜单分组", value: 999 }, { label: "URL", value: 1 }, { label: "绑定表单", value: 2 }]} />
|
206
|
+
<Layout.FormRow layout={'1'}>
|
207
|
+
<Field.Input label="测试 withVisible" __id="withVisible"
|
208
|
+
isRequired={true}
|
209
|
+
withIds={["routeType"]}
|
210
|
+
withVisible={{
|
211
|
+
"value": [
|
212
|
+
{
|
213
|
+
"insert": {
|
214
|
+
"span": true
|
215
|
+
},
|
216
|
+
"attributes": {
|
217
|
+
"id": "routeType",
|
218
|
+
"color": "blue",
|
219
|
+
"tagKey": "fieldsValue",
|
220
|
+
"content": "当前表单.开关"
|
221
|
+
}
|
222
|
+
},
|
223
|
+
{
|
224
|
+
"insert": " == 1\n"
|
225
|
+
}
|
226
|
+
],
|
227
|
+
"version": 1734400834533,
|
228
|
+
"withData": [
|
229
|
+
|
230
|
+
]
|
231
|
+
}}
|
232
|
+
/>
|
233
|
+
</Layout.FormRow>
|
201
234
|
<Layout.FormRow layout={'1'}>
|
202
235
|
|
203
236
|
|
@@ -209,6 +242,26 @@ function App() {
|
|
209
242
|
console.log("request params", params)
|
210
243
|
return { code: 0, data: { list: [{ label: '选项1', value: '1', fill_tianchong1_test: "sdfsdf", fill_tianchong2: { label: '选项2', value: '2' }, fill_tcinput1: "1111", }, { label: '选项2', value: '2' }, { label: '选项3', value: '3' }] } }
|
211
244
|
}}
|
245
|
+
|
246
|
+
withIds={["routeType"]}
|
247
|
+
withVisible={{
|
248
|
+
"value": [
|
249
|
+
{
|
250
|
+
"insert": {
|
251
|
+
"span": true
|
252
|
+
},
|
253
|
+
"attributes": {
|
254
|
+
"id": "routeType",
|
255
|
+
"color": "blue",
|
256
|
+
"tagKey": "fieldsValue",
|
257
|
+
"content": "当前表单.开关"
|
258
|
+
}
|
259
|
+
},
|
260
|
+
{
|
261
|
+
"insert": "== 1"
|
262
|
+
},
|
263
|
+
]
|
264
|
+
}}
|
212
265
|
option_label="label"
|
213
266
|
option_value="value"
|
214
267
|
fillRules={[
|
@@ -69,13 +69,13 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
69
69
|
|
70
70
|
const loadSelectOptions = async (loadValue) => {
|
71
71
|
if (request && option_value) {
|
72
|
-
console.log(`[${props?.label}]loadSelectOptions loadValue`, loadValue);
|
73
|
-
console.log(`[${props?.label}]loadSelectOptions loadValue2`, loadValue);
|
72
|
+
// console.log(`[${props?.label}]loadSelectOptions loadValue`, loadValue);
|
73
|
+
// console.log(`[${props?.label}]loadSelectOptions loadValue2`, loadValue);
|
74
74
|
callbackQueue.current.push((selectOptions) => {
|
75
75
|
if (selectOptions && selectOptions.length > 0) {
|
76
76
|
let item = selectOptions.find(item => item.value == loadValue?.value || item.value == loadValue);
|
77
77
|
if (item && !isEqual(item, loadValue)) {
|
78
|
-
console.log(`[${props?.label}]debounceFetchOptions new value /////`, item);
|
78
|
+
// console.log(`[${props?.label}]debounceFetchOptions new value /////`, item);
|
79
79
|
typeof onChange === 'function' && onChange(item);
|
80
80
|
}
|
81
81
|
}
|
@@ -107,7 +107,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
107
107
|
|
108
108
|
const debounceFetchOptions = useCallback(debounce((params, ruleParams) => {
|
109
109
|
fetchOptions(params, ruleParams).then(result => {
|
110
|
-
console.log(`[${props?.label}]debounceFetchOptions result`, result);
|
110
|
+
// console.log(`[${props?.label}]debounceFetchOptions result`, result);
|
111
111
|
while (callbackQueue.current.length > 0) {
|
112
112
|
const callback = callbackQueue.current.shift();
|
113
113
|
if (typeof callback === 'function') {
|
@@ -33,11 +33,11 @@ const TableCol = ({ children, width, hidden, ...props }) => {
|
|
33
33
|
</div>
|
34
34
|
}
|
35
35
|
|
36
|
-
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, initializeFormRender, recordFieldsChange, getTableWithIds,removeLastFieldsValues, mode, isAllowCopy=false, isAllowAdd=true, ...props }) => {
|
36
|
+
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, initializeFormRender, recordFieldsChange, getTableWithIds,removeLastFieldsValues, mode, isAllowCopy=false, isAllowAdd=true,getDependencyMapItem, ...props }) => {
|
37
37
|
useEffect(() => {
|
38
38
|
// console.log("Table form reload", form)
|
39
39
|
}, [form])
|
40
|
-
|
40
|
+
const tableComponentId = props.componentId || props.__id
|
41
41
|
const newidRefs = useRef(React.Children.map(children, () => nanoid()));
|
42
42
|
const [init, setInit] = useState(false);
|
43
43
|
const name = props.componentId || props.__id
|
@@ -67,6 +67,15 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
67
67
|
}
|
68
68
|
return []
|
69
69
|
}
|
70
|
+
|
71
|
+
const getDependencyMapShow = (identifier) => {
|
72
|
+
if (typeof getDependencyMapItem == "function") {
|
73
|
+
const dependencyMapItem = getDependencyMapItem(`${tableComponentId}.${identifier}`)
|
74
|
+
if (dependencyMapItem) return dependencyMapItem?.show
|
75
|
+
}
|
76
|
+
return true
|
77
|
+
}
|
78
|
+
|
70
79
|
if (props.isRequired)
|
71
80
|
rules.push({ required: true, message: `子表[${props.label}]必须填写` });
|
72
81
|
return <Form.List name={name} rules={rules}>
|
@@ -76,7 +85,7 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
76
85
|
<div className="fw-full frelative fmin-h-20 foverflow-x-auto" style={{ position: 'relative' }}>
|
77
86
|
{fields.length === 0 && <div key={`tableHead`} className="fborder-b fflex flex-nowrap fmin-w-full ">
|
78
87
|
{React.Children.map(children, (child, childIndex) => {
|
79
|
-
const hidden = child?.props?.calcHidden;
|
88
|
+
const hidden = (child?.props?.calcHidden || !getDependencyMapShow(child?.props?.componentId || child?.props?.__id)) && mode != "desgin";
|
80
89
|
return <TableCol width={150} key={`row_${0}_col_${childIndex}`} hidden={hidden}>
|
81
90
|
{hidden ? null : React.cloneElement(child, {
|
82
91
|
key: `row_${0}_child_${childIndex}`,
|
@@ -112,7 +121,7 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
112
121
|
const componentName = child.type?.displayName || _componentName;
|
113
122
|
const identifier = componentId || __id;
|
114
123
|
|
115
|
-
const hidden = props.calcHidden && mode != "desgin";
|
124
|
+
const hidden = (props.calcHidden || !getDependencyMapShow(identifier) ) && mode != "desgin" ;
|
116
125
|
return <TableCol width={150} key={`row_${field.key}_col_${childIndex}`} hidden={hidden}>
|
117
126
|
<Form.Item
|
118
127
|
style={{ margin: 0 }}
|
@@ -81,12 +81,12 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
81
81
|
// 添加节流后的 initializeFormRender
|
82
82
|
const throttledInitializeFormRender = React.useCallback(
|
83
83
|
throttle(async () => {
|
84
|
-
console.log("throttledInitializeFormRender")
|
84
|
+
// console.log("throttledInitializeFormRender")
|
85
85
|
await initializeDependencyMap();
|
86
86
|
requestAnimationFrame(() => {
|
87
87
|
setFormContent(renderChildren());
|
88
88
|
})
|
89
|
-
console.log("throttledInitializeFormRender end")
|
89
|
+
// console.log("throttledInitializeFormRender end")
|
90
90
|
|
91
91
|
}, 300),
|
92
92
|
[children, cols]
|
@@ -159,11 +159,11 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
159
159
|
...field
|
160
160
|
});
|
161
161
|
});
|
162
|
-
console.log("dependencyMap.current", dependencyMap.current)
|
162
|
+
// console.log("dependencyMap.current", dependencyMap.current)
|
163
163
|
await initializeFieldVisibilityImmediate();
|
164
164
|
};
|
165
165
|
const initializeFieldVisibilityImmediate = async (reloadFields = false) => {
|
166
|
-
console.log("initializeFieldVisibility *************************************")
|
166
|
+
// console.log("initializeFieldVisibility *************************************")
|
167
167
|
const fieldValues = form.getFieldsValue();
|
168
168
|
|
169
169
|
await Promise.all(Array.from(dependencyMap.current.keys()).map(async (key) => {
|
@@ -351,23 +351,23 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
351
351
|
let withFillGroup = ""
|
352
352
|
let childIdentifier = child.identifier;
|
353
353
|
|
354
|
-
if (parentIdentifier && Array.isArray(parentIdentifier) && parentIdentifier.length > 1) {
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
}
|
361
|
-
// 被依赖字段不是子表字段,依赖字段是子表字段的情况
|
362
|
-
else if (childIdentifier.indexOf(".") >= 0) {
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
}
|
354
|
+
// if (parentIdentifier && Array.isArray(parentIdentifier) && parentIdentifier.length > 1) {
|
355
|
+
// withFillGroup = parentIdentifier.filter(item => typeof item == "string").join(".")
|
356
|
+
// withFillIndex = parentIdentifier[parentIdentifier.length - 1]
|
357
|
+
// if (childIdentifier.startsWith(`${withFillGroup}.`)) {
|
358
|
+
// childIdentifier = [...parentIdentifier, childIdentifier.replace(`${withFillGroup}.`, "")]
|
359
|
+
// }
|
360
|
+
// }
|
361
|
+
// // 被依赖字段不是子表字段,依赖字段是子表字段的情况
|
362
|
+
// else if (childIdentifier.indexOf(".") >= 0) {
|
363
|
+
// childIdentifier = childIdentifier.split(".")
|
364
|
+
// let table_values = getParamValue("fieldsValue", childIdentifier[0], fieldValues, [])
|
365
|
+
// if (Array.isArray(table_values) && table_values.length > 0)
|
366
|
+
// for (let index = 0; index < table_values.length; index++) {
|
367
|
+
// await handleFieldsVisible(fieldValues, child, [childIdentifier[0], index], componentName)
|
368
|
+
// }
|
369
|
+
// return
|
370
|
+
// }
|
371
371
|
let withDatas = [];
|
372
372
|
// 先处理依赖数据
|
373
373
|
if (withFill?.withData && withFill?.withData.length > 0 && withDataFetch && typeof withDataFetch === 'function') {
|
@@ -428,9 +428,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
428
428
|
const childData = dependencyMap.current.get(childIdentifier);
|
429
429
|
if (formula && formula.length > 0) {
|
430
430
|
const formulaResult = (evalFormula(formula) == "true");
|
431
|
-
console.log(`${childIdentifier} 计算公式:`, formula)
|
432
|
-
console.log(`${childIdentifier} 计算结果:`, formulaResult)
|
433
|
-
console.log(`${childIdentifier} childData.show:`, childData.show)
|
431
|
+
// console.log(`${childIdentifier} 计算公式:`, formula)
|
432
|
+
// console.log(`${childIdentifier} 计算结果:`, formulaResult)
|
433
|
+
// console.log(`${childIdentifier} childData.show:`, childData.show)
|
434
434
|
if (childData.show != formulaResult) {
|
435
435
|
childData.show = formulaResult;
|
436
436
|
dependencyMap.current.set(childIdentifier, childData);
|
@@ -443,8 +443,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
443
443
|
// 处理级联数据源
|
444
444
|
// 处理级联填充
|
445
445
|
const handleFieldsWithFill = async (fieldValues, child, parentIdentifier, componentName) => {
|
446
|
-
console.log("handleFieldsWithFill child.identifier", child.identifier)
|
447
|
-
console.log("handleFieldsWithFill parentIdentifier", parentIdentifier)
|
446
|
+
// console.log("handleFieldsWithFill child.identifier", child.identifier)
|
447
|
+
// console.log("handleFieldsWithFill parentIdentifier", parentIdentifier)
|
448
448
|
const withFill = child?.component?.props.withFill;
|
449
449
|
const withDataFetch = child?.component?.props.withDataFetch;
|
450
450
|
let withFillIndex = 0
|
@@ -586,7 +586,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
586
586
|
let field = changedFieldsState.current[key];
|
587
587
|
if (!isEqual(field.value || "", getLastFieldValue(field.name) || "")) {
|
588
588
|
if (lockStatus_ != 1) {
|
589
|
-
console.log("handleFieldsWith field.name", field.name)
|
589
|
+
// console.log("handleFieldsWith field.name", field.name)
|
590
590
|
let needRefresh_ = await handleFieldsWith(field.name, fieldValues);
|
591
591
|
needRefresh = needRefresh || needRefresh_
|
592
592
|
|
@@ -649,8 +649,16 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
649
649
|
}
|
650
650
|
|
651
651
|
const shouldUpdateKey = React.useRef({})
|
652
|
+
|
653
|
+
const getDependencyMapItem = (identifier) => {
|
654
|
+
if (dependencyMap.current && dependencyMap.current.has(identifier)) {
|
655
|
+
return dependencyMap.current.get(identifier)
|
656
|
+
}
|
657
|
+
return null
|
658
|
+
}
|
652
659
|
const renderChildren = () => {
|
653
660
|
console.log("renderChildren")
|
661
|
+
const renderKey = nanoid()
|
654
662
|
const childrenArray = React.Children.toArray(children);
|
655
663
|
const groupedChildren = batchElements(
|
656
664
|
childrenArray,
|
@@ -696,7 +704,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
696
704
|
|
697
705
|
let childComponent
|
698
706
|
if (isTable || isLayoutComponent) {
|
699
|
-
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, getTableWithIds, onTableRemoveRow: handleTableRemoveRow, removeLastFieldsValues, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode, recordFieldsChange })
|
707
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, getTableWithIds, onTableRemoveRow: handleTableRemoveRow, removeLastFieldsValues, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode, recordFieldsChange ,getDependencyMapItem,renderKey})
|
700
708
|
}
|
701
709
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
702
710
|
childComponent = <Form.Item
|
@@ -2,7 +2,7 @@ import React, { useMemo } from 'react';
|
|
2
2
|
import { nanoid } from 'nanoid';
|
3
3
|
import { Form, Row, Col } from 'antd';
|
4
4
|
|
5
|
-
const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form, initializeFormRender,recordFieldsChange, mode,getTableWithIds,removeLastFieldsValues }) => {
|
5
|
+
const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form, initializeFormRender,recordFieldsChange, mode,getTableWithIds,removeLastFieldsValues,getDependencyMapItem,renderKey }) => {
|
6
6
|
layout = layout || '1';
|
7
7
|
const getColSpan = (layoutStr) => {
|
8
8
|
const layoutArray = layoutStr.split(',').map(Number);
|
@@ -11,7 +11,13 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
11
11
|
};
|
12
12
|
|
13
13
|
const colSpans = useMemo(() => getColSpan(layout), [layout]);
|
14
|
-
|
14
|
+
const getDependencyMapShow = (identifier) => {
|
15
|
+
if (typeof getDependencyMapItem == "function") {
|
16
|
+
const dependencyMapItem = getDependencyMapItem(identifier)
|
17
|
+
if (dependencyMapItem) return dependencyMapItem?.show
|
18
|
+
}
|
19
|
+
return true
|
20
|
+
}
|
15
21
|
|
16
22
|
const shouldUpdateKey = React.useRef({})
|
17
23
|
const formItems = useMemo(() => {
|
@@ -27,7 +33,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
27
33
|
if (!(identifier in shouldUpdateKey.current)) {
|
28
34
|
shouldUpdateKey.current[identifier] = nanoid()
|
29
35
|
}
|
30
|
-
const hidden = props?.calcHidden && mode != "desgin";
|
36
|
+
const hidden = (props?.calcHidden || !getDependencyMapShow(identifier)) && mode != "desgin";
|
31
37
|
const rules = []
|
32
38
|
if (props?.isRequired)
|
33
39
|
rules.push({ required: true, message: `${props.label}必须填写` });
|
@@ -44,7 +50,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
44
50
|
}
|
45
51
|
let childComponent = null
|
46
52
|
if (componentName == 'Field.Table')
|
47
|
-
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: name, initializeFormRender, mode,recordFieldsChange ,getTableWithIds,removeLastFieldsValues })
|
53
|
+
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: name, initializeFormRender, mode,recordFieldsChange ,getTableWithIds,removeLastFieldsValues ,getDependencyMapItem,renderKey})
|
48
54
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
49
55
|
childComponent = <Form.Item
|
50
56
|
hidden={hidden}
|
@@ -94,6 +100,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
94
100
|
key={`${name}-form-item`}
|
95
101
|
name={name}
|
96
102
|
rules={rules}
|
103
|
+
hidden={hidden}
|
97
104
|
>
|
98
105
|
{React.cloneElement(child, { form: form, fieldName: name, initializeFormRender,recordFieldsChange })}
|
99
106
|
</Form.Item>
|
@@ -108,7 +115,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
108
115
|
|
109
116
|
|
110
117
|
});
|
111
|
-
}, [children, colSpans]);
|
118
|
+
}, [children, colSpans,renderKey]);
|
112
119
|
|
113
120
|
return <Row gutter={24}>{formItems}</Row>;
|
114
121
|
};
|