lu-lowcode-package-form 0.11.50 → 0.11.51
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 +184 -184
- package/dist/index.es.js +13133 -13128
- package/package.json +1 -1
- package/src/App.jsx +1 -1
- package/src/components/field/select/search-select.jsx +2 -7
- package/src/components/form-container/index.jsx +80 -79
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -575,7 +575,7 @@ function App() {
|
|
575
575
|
code: 0, data: {
|
576
576
|
list:
|
577
577
|
[
|
578
|
-
{ label: '选项1', value: '1', table_fill: [{ fill_shuilv:0.13, fill_tianchong1: { label: '选项1', value: '1' }, fill_tianchong2: { label: '选项2', value: '2' } }] },
|
578
|
+
{ label: '选项1', value: '1', table_fill: [{ fill_shuilv:0.13, fill_tianchong1: { label: '选项1', value: '1' }, fill_tianchong2: { label: '选项2', value: '2' } },{ fill_shuilv:0.13, fill_tianchong1: { label: '选项1', value: '1' }, fill_tianchong2: { label: '选项2', value: '2' } }] },
|
579
579
|
{ label: '选项2', value: '2' },
|
580
580
|
{ label: '选项3', value: '3' }
|
581
581
|
]
|
@@ -79,18 +79,16 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
79
79
|
// console.log("callback loadValue", loadValue)
|
80
80
|
// let item = selectOptions.find(item => item.value == loadValue?.value || item.value == loadValue);
|
81
81
|
// if (item && !isEqual(item, loadValue)) {
|
82
|
-
// console.log(`[${props?.label}]debounceFetchOptions new value /////`, item);
|
83
82
|
// typeof onChange === 'function' && onChange(item);
|
84
83
|
// }
|
85
84
|
// }
|
86
85
|
// });
|
87
86
|
debounceFetchOptions({ ...requestParams, [option_value]: loadValue?.value }, null, (selectOptions) => {
|
88
87
|
if (selectOptions && selectOptions.length > 0) {
|
89
|
-
console.log(`[${props?.label}]callback selectOptions`, selectOptions)
|
90
|
-
console.log(`[${props?.label}]callback loadValue`, loadValue)
|
88
|
+
// console.log(`[${props?.label}]callback selectOptions`, selectOptions)
|
89
|
+
// console.log(`[${props?.label}]callback loadValue`, loadValue)
|
91
90
|
let item = selectOptions.find(item => item.value == loadValue?.value || item.value == loadValue);
|
92
91
|
if (item && !isEqual(item, loadValue)) {
|
93
|
-
console.log(`[${props?.label}]debounceFetchOptions new value /////`, item);
|
94
92
|
typeof onChange === 'function' && onChange(item);
|
95
93
|
}
|
96
94
|
}
|
@@ -124,11 +122,8 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
124
122
|
if (debounceFetchOptionsRef.current) clearTimeout(debounceFetchOptionsRef.current);
|
125
123
|
debounceFetchOptionsRef.current = setTimeout(() => {
|
126
124
|
const callbacks = callbackQueue.current;
|
127
|
-
console.log(`[${props?.label}]debounceFetchOptions callbackQueue`, JSON.parse(JSON.stringify(callbacks)));
|
128
125
|
callbackQueue.current = [];
|
129
126
|
fetchOptions(params, ruleParams, fieldName).then(result => {
|
130
|
-
console.log(`[${props?.label}]debounceFetchOptions result`, result);
|
131
|
-
console.log(`[${props?.label}]debounceFetchOptions callbacks`, callbacks);
|
132
127
|
while (callbacks.length > 0) {
|
133
128
|
const callback = callbacks.shift();
|
134
129
|
if (typeof callback === 'function') {
|
@@ -8,7 +8,7 @@ import { nanoid } from 'nanoid';
|
|
8
8
|
import { eventEmitter } from '../../utils/events'
|
9
9
|
|
10
10
|
|
11
|
-
function batchElements(elements, groupSize,dmap) {
|
11
|
+
function batchElements(elements, groupSize, dmap) {
|
12
12
|
const groupedElements = [];
|
13
13
|
let tempArray = [];
|
14
14
|
|
@@ -61,7 +61,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
61
61
|
if (!isEqual(formContentRef.current, newFormContent)) {
|
62
62
|
formContentRef.current = newFormContent;
|
63
63
|
setFormContent(newFormContent);
|
64
|
-
|
64
|
+
}
|
65
65
|
}
|
66
66
|
// 调用setFieldsValue时,进入锁定状态,阻止因字段值变化而触发级联处理
|
67
67
|
const lockStatus = React.useRef(0);
|
@@ -74,31 +74,31 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
74
74
|
// 当前更新周期的依赖路径
|
75
75
|
updatePath: [],
|
76
76
|
// 开始新的更新周期
|
77
|
-
startNewCycle: function() {
|
77
|
+
startNewCycle: function () {
|
78
78
|
this.currentCycleId++;
|
79
79
|
this.updatePath = [];
|
80
80
|
return this.currentCycleId;
|
81
81
|
},
|
82
82
|
// 添加依赖路径
|
83
|
-
addToPath: function(fieldId) {
|
83
|
+
addToPath: function (fieldId) {
|
84
84
|
this.updatePath.push(fieldId);
|
85
85
|
},
|
86
86
|
// 检查是否形成循环
|
87
|
-
hasCircularDependency: function(targetFieldId) {
|
87
|
+
hasCircularDependency: function (targetFieldId) {
|
88
88
|
return this.updatePath.includes(targetFieldId);
|
89
89
|
},
|
90
90
|
// 获取当前依赖路径
|
91
|
-
getCurrentPath: function() {
|
91
|
+
getCurrentPath: function () {
|
92
92
|
return [...this.updatePath];
|
93
93
|
},
|
94
94
|
// 结束当前字段的处理
|
95
|
-
finishField: function() {
|
95
|
+
finishField: function () {
|
96
96
|
if (this.updatePath.length > 0) {
|
97
97
|
this.updatePath.pop();
|
98
98
|
}
|
99
99
|
}
|
100
100
|
});
|
101
|
-
|
101
|
+
|
102
102
|
React.useImperativeHandle(ref, () => ({
|
103
103
|
formRef: form,
|
104
104
|
setFieldsValue: (values) => {
|
@@ -164,7 +164,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
164
164
|
// return current;
|
165
165
|
}
|
166
166
|
const initializeDependencyMap = async () => {
|
167
|
-
|
167
|
+
|
168
168
|
const fields = [];
|
169
169
|
function traverse(currentNode, parentNode = null) {
|
170
170
|
var componentName = currentNode.type?.displayName || currentNode.props?._componentName;
|
@@ -212,10 +212,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
212
212
|
};
|
213
213
|
const initializeFieldVisibilityImmediate = async (reloadFields = false) => {
|
214
214
|
console.log("initializeFieldVisibility *************************************")
|
215
|
-
|
216
|
-
|
215
|
+
|
216
|
+
|
217
217
|
const fieldValues = form.getFieldsValue();
|
218
|
-
|
218
|
+
|
219
219
|
await Promise.all(Array.from(dependencyMap.current.keys()).map(async (key) => {
|
220
220
|
await handleFieldsWith(key, fieldValues, true);
|
221
221
|
}))
|
@@ -226,7 +226,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
226
226
|
};
|
227
227
|
// 初始化字段的级联关系
|
228
228
|
const initializeFieldVisibility = debounce(async (reloadFields = false) => {
|
229
|
-
console.log("initializeFieldVisibility begin",reloadFields)
|
230
229
|
await initializeFieldVisibilityImmediate(reloadFields);
|
231
230
|
}, 100);
|
232
231
|
|
@@ -239,21 +238,21 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
239
238
|
if (Array.isArray(identifier)) {
|
240
239
|
parentIdentifier = [...(identifier.slice(0, -1))]
|
241
240
|
identifier = identifier.filter(item => typeof item == "string").join(".")
|
241
|
+
|
242
242
|
}
|
243
|
-
|
243
|
+
|
244
244
|
// 将标识符标准化为字符串,用于依赖图谱
|
245
245
|
const currentFieldId = fieldId || identifier;
|
246
|
-
|
247
246
|
// 检查是否在当前更新链路中已存在,避免循环依赖
|
248
247
|
if (dependencyGraphRef.current.hasCircularDependency(currentFieldId)) {
|
249
248
|
const currentPath = dependencyGraphRef.current.getCurrentPath();
|
250
249
|
console.log(`检测到循环依赖链路: ${[...currentPath, currentFieldId].join(' -> ')}`);
|
251
250
|
return false;
|
252
251
|
}
|
253
|
-
|
252
|
+
|
254
253
|
// 将当前字段添加到依赖路径
|
255
254
|
dependencyGraphRef.current.addToPath(currentFieldId);
|
256
|
-
|
255
|
+
|
257
256
|
try {
|
258
257
|
if (dependencyMap.current.has(identifier)) {
|
259
258
|
const dependent = dependencyMap.current.get(identifier)
|
@@ -285,7 +284,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
285
284
|
// 在处理完毕后,从依赖路径中移除当前字段
|
286
285
|
dependencyGraphRef.current.finishField();
|
287
286
|
}
|
288
|
-
|
287
|
+
|
289
288
|
return needRefresh;
|
290
289
|
};
|
291
290
|
const removeLastFieldsValues = (name, isTable = false) => {
|
@@ -309,12 +308,12 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
309
308
|
changedFieldsState.current[fieldName] = fieldValue;
|
310
309
|
}
|
311
310
|
const recordFieldsChange = (changedFields, handleChange = false) => {
|
312
|
-
console.log("recordFieldsChange", changedFields,handleChange)
|
311
|
+
console.log("recordFieldsChange", changedFields, handleChange)
|
313
312
|
var changedKeys = Object.keys(changedFields)
|
314
313
|
if (changedKeys.length > 0) {
|
315
314
|
changedKeys.forEach(key => {
|
316
315
|
recordFieldChange(key, changedFields[key])
|
317
|
-
|
316
|
+
|
318
317
|
})
|
319
318
|
if (handleChange) debounceHandleFieldsChange();
|
320
319
|
}
|
@@ -327,7 +326,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
327
326
|
let changedFields = {}
|
328
327
|
|
329
328
|
// 将标识符标准化为字符串
|
330
|
-
const sourceFieldId = Array.isArray(current_identifier)
|
329
|
+
const sourceFieldId = Array.isArray(current_identifier)
|
331
330
|
? current_identifier.filter(item => typeof item == "string").join(".")
|
332
331
|
: current_identifier;
|
333
332
|
|
@@ -337,29 +336,29 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
337
336
|
let { source, target } = rule
|
338
337
|
let source_value = current_value?.[source]
|
339
338
|
let setValue = source_value
|
340
|
-
|
339
|
+
|
341
340
|
// 将sourceField格式化为字符串形式,用于依赖跟踪
|
342
|
-
const sourceField = Array.isArray(current_identifier)
|
341
|
+
const sourceField = Array.isArray(current_identifier)
|
343
342
|
? current_identifier.filter(item => typeof item == "string").join(".")
|
344
343
|
: current_identifier;
|
345
|
-
|
344
|
+
|
346
345
|
// 格式化目标字段
|
347
|
-
const targetField = Array.isArray(target)
|
346
|
+
const targetField = Array.isArray(target)
|
348
347
|
? target.filter(item => typeof item == "string").join(".")
|
349
348
|
: target;
|
350
|
-
|
349
|
+
|
351
350
|
// // 检查循环依赖 - 使用更高级的依赖图检测
|
352
351
|
// if (dependencyGraphRef.current.hasCircularDependency(targetField)) {
|
353
352
|
// const currentPath = dependencyGraphRef.current.getCurrentPath();
|
354
353
|
// console.log(`检测到填充规则中的循环依赖链路: ${[...currentPath, targetField].join(' -> ')}`);
|
355
354
|
// continue; // 跳过这条规则
|
356
355
|
// }
|
357
|
-
|
358
|
-
|
356
|
+
|
357
|
+
|
359
358
|
//// 添加到依赖路径
|
360
359
|
// dependencyGraphRef.current.addToPath(targetField);
|
361
|
-
|
362
|
-
|
360
|
+
|
361
|
+
|
363
362
|
// 子表
|
364
363
|
if (rule?.type == 1) {
|
365
364
|
if (dependencyMap.current.has(target)) {
|
@@ -409,7 +408,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
409
408
|
form.setFieldValue(target, undefined);
|
410
409
|
}
|
411
410
|
form.setFieldValue(target, setValue)
|
412
|
-
|
411
|
+
|
413
412
|
// 处理完当前字段后从依赖路径中移除
|
414
413
|
// dependencyGraphRef.current.finishField();
|
415
414
|
}
|
@@ -560,25 +559,25 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
560
559
|
for (let index = 0; index < table_values.length; index++) {
|
561
560
|
await handleFieldsWithFill(fieldValues, child, [childIdentifier[0], index], componentName, sourceFieldId)
|
562
561
|
}
|
563
|
-
|
562
|
+
|
564
563
|
return
|
565
564
|
}
|
566
|
-
|
565
|
+
|
567
566
|
// 将目标字段ID标准化为字符串
|
568
|
-
const targetFieldId = Array.isArray(childIdentifier)
|
569
|
-
? childIdentifier.
|
567
|
+
const targetFieldId = Array.isArray(childIdentifier)
|
568
|
+
? childIdentifier.join(".")
|
570
569
|
: childIdentifier;
|
571
|
-
|
570
|
+
|
572
571
|
// 检查是否在当前依赖链中已存在,避免循环依赖
|
573
572
|
if (dependencyGraphRef.current.hasCircularDependency(targetFieldId)) {
|
574
573
|
const currentPath = dependencyGraphRef.current.getCurrentPath();
|
575
574
|
console.log(`检测到公式计算中的循环依赖链路: ${[...currentPath, targetFieldId].join(' -> ')}`);
|
576
575
|
return;
|
577
576
|
}
|
578
|
-
|
577
|
+
|
579
578
|
// // 将当前字段添加到依赖路径
|
580
579
|
// dependencyGraphRef.current.addToPath(targetFieldId);
|
581
|
-
|
580
|
+
|
582
581
|
try {
|
583
582
|
let withDatas = [];
|
584
583
|
// 先处理依赖数据
|
@@ -654,8 +653,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
654
653
|
const formulaResult = evalFormula(formula);
|
655
654
|
console.log(`${childIdentifier} 计算公式:`, formula)
|
656
655
|
console.log(`${childIdentifier} 计算结果:`, formulaResult)
|
657
|
-
|
658
|
-
|
656
|
+
|
657
|
+
|
659
658
|
form.setFieldValue(childIdentifier, formulaResult)
|
660
659
|
await handleFieldsWith(childIdentifier, form.getFieldsValue(), false, targetFieldId)
|
661
660
|
}
|
@@ -716,26 +715,26 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
716
715
|
|
717
716
|
// 创建已处理字段集合,用于避免多次处理同一字段
|
718
717
|
const processedFields = new Set();
|
719
|
-
|
720
718
|
for (let key in changedFieldsState.current) {
|
721
719
|
let field = changedFieldsState.current[key];
|
722
720
|
if (!isEqual(field.value || "", getLastFieldValue(field.name) || "")) {
|
723
721
|
if (lockStatus_ != 1) {
|
724
722
|
// 获取字段标识符(字符串形式)
|
725
|
-
const fieldId = Array.isArray(field.name)
|
726
|
-
? field.name.
|
723
|
+
const fieldId = Array.isArray(field.name)
|
724
|
+
? field.name.map(item => typeof item == "string" ? item : item.toString()).join(".")
|
727
725
|
: field.name;
|
728
|
-
|
726
|
+
|
729
727
|
// 跳过已处理的字段
|
730
728
|
if (processedFields.has(fieldId)) continue;
|
731
729
|
processedFields.add(fieldId);
|
732
|
-
|
730
|
+
|
733
731
|
// 处理字段依赖关系,传递字段ID和依赖图谱
|
734
732
|
let needRefresh_ = await handleFieldsWith(field.name, fieldValues, false, fieldId);
|
735
733
|
needRefresh = needRefresh || needRefresh_;
|
736
734
|
}
|
737
735
|
lastFormValues.current[field.name] = field.value;
|
738
736
|
}
|
737
|
+
else console.log(`重复的field`, field.name)
|
739
738
|
}
|
740
739
|
if (needRefresh) {
|
741
740
|
console.log("needRefresh", needRefresh)
|
@@ -746,16 +745,18 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
746
745
|
}, []);
|
747
746
|
|
748
747
|
const handleFieldsChange = React.useCallback((changedFields) => {
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
}
|
756
|
-
})
|
748
|
+
setTimeout(() => {
|
749
|
+
changedFields.filter(field => {
|
750
|
+
if (field.name && field.name.length > 0) {
|
751
|
+
// const fieldKey = field.name.filter(item => typeof item == "string").join(".")
|
752
|
+
changedFieldsState.current[field.name] = field;
|
757
753
|
|
758
|
-
|
754
|
+
|
755
|
+
}
|
756
|
+
})
|
757
|
+
console.log("handleFieldsChange", changedFieldsState.current)
|
758
|
+
debounceHandleFieldsChange();
|
759
|
+
}, 0);
|
759
760
|
}, []);
|
760
761
|
|
761
762
|
const getTableWithIds = (ids) => {
|
@@ -773,7 +774,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
773
774
|
})
|
774
775
|
return withAllIds
|
775
776
|
}
|
776
|
-
const handleTableAddRow =
|
777
|
+
const handleTableAddRow = (ids) => {
|
777
778
|
let withAllIds = getTableWithIds(ids)
|
778
779
|
const fieldValues = form.getFieldsValue();
|
779
780
|
setTimeout(async () => {
|
@@ -807,7 +808,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
807
808
|
return renderChildren();
|
808
809
|
}
|
809
810
|
return null;
|
810
|
-
|
811
|
+
}
|
811
812
|
const renderChildren = () => {
|
812
813
|
console.log("renderChildren")
|
813
814
|
const renderKey = nanoid()
|
@@ -824,7 +825,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
824
825
|
);
|
825
826
|
|
826
827
|
|
827
|
-
|
828
|
+
|
828
829
|
|
829
830
|
|
830
831
|
|
@@ -860,7 +861,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
860
861
|
|
861
862
|
let childComponent
|
862
863
|
if (isTable || isLayoutComponent) {
|
863
|
-
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, getTableWithIds, onTableRemoveRow: handleTableRemoveRow, removeLastFieldsValues, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode, recordFieldsChange
|
864
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, getTableWithIds, onTableRemoveRow: handleTableRemoveRow, removeLastFieldsValues, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode, recordFieldsChange, getDependencyMapItem, renderKey })
|
864
865
|
}
|
865
866
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
866
867
|
childComponent = <Form.Item
|
@@ -925,7 +926,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
925
926
|
style={{ marginBottom: 0 }}
|
926
927
|
>
|
927
928
|
{childComponent}
|
928
|
-
</Col>
|
929
|
+
</Col>
|
929
930
|
);
|
930
931
|
})}
|
931
932
|
</Row>
|
@@ -934,26 +935,26 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
934
935
|
|
935
936
|
return (
|
936
937
|
<ConfigProvider
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
938
|
+
theme={{
|
939
|
+
components: {
|
940
|
+
Table: {
|
941
|
+
rowHoverBg: '#ebebeb',
|
942
|
+
// "fontSize": 14,
|
943
|
+
// "cellPaddingBlock": 6
|
944
|
+
},
|
945
|
+
},
|
946
|
+
token: {
|
947
|
+
colorBgContainerDisabled: 'rgba(0, 0, 0, 0.02)', // 设置更浅的灰色背景
|
948
|
+
colorTextDisabled: '#333',
|
949
|
+
}
|
950
|
+
}}
|
951
|
+
>
|
952
|
+
<Form form={form} className={"form-container fp-0 fw-full fh-full box-border fflex fflex-col " + (mode == "desgin" ? " fp-6" : "")} onFieldsChange={handleFieldsChange}>
|
953
|
+
<Form.Item name="__id" hidden={true}>
|
954
|
+
<input type="hidden" />
|
955
|
+
</Form.Item>
|
956
|
+
{formContent}
|
957
|
+
</Form>
|
957
958
|
</ConfigProvider>
|
958
959
|
);
|
959
960
|
});
|