lu-lowcode-package-form 0.11.86 → 0.11.88
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 +270 -270
- package/dist/index.es.js +13783 -13857
- package/package.json +1 -1
- package/src/App.jsx +1 -1
- package/src/components/form-container/index.jsx +27 -192
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -109,7 +109,7 @@ function App() {
|
|
109
109
|
}
|
110
110
|
}
|
111
111
|
const setFormFields = () => {
|
112
|
-
formRef?.current?.setFieldsValue({ "__id": 1, "
|
112
|
+
formRef?.current?.setFieldsValue({ "__id": 1, "userselect": "1213131", "remark11": { "label": "选项1", "value": "1", "name": "1111", "table": "[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" }, "table2": [{}], "table": [{ "product_num1": "123", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "remark11": { "label": "选项2", "value": "2" }, "product_price12": "", "tianchong1": { "label": "选项1", "value": "1", "tianchong2": { "label": "选项2", "value": "2" }, "tcinput1": "1111" }, "tianchong2": { "label": "选项2", "value": "2", "tcinput1": "8989", "tcinput2": "2222" }, "tcinput1": "8989", "tcinput2": "2222", "tcinput3": "2222" }, { "product_num1": "213", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "datetime2": "2024-08-22 11:09:07", "product_price13": 1, "product_price14": 2, "product_price12": "", "remark11": { "label": "选项3", "value": "3" }, "product_price11": 3 }], "product_total_price": "0.00", "DeptSelect": ["leaf11"], "PostSelect": ["parent 1-1", "leaf11"], "searchuser": [{ "id": 2, "name": "2222", "label": "2222", "value": 2 }, { "id": 4, "name": "4444", "label": "4444", "value": 4 }], "product_price": "213", "product_num": "21", "product_num_range": [1, 22], "product_sum": "4473", "switch": false, "datetime": "2024-08-25", "datetime2": "2024-08-25", "datetime3": "", "datetime4": "2024-08-22 11:09:04", "remark12": JSON.stringify([{ "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" }]) })
|
113
113
|
// formRef?.current?.setFieldsValue({"tianchong1":{"label":"选项1","value":"1"}, })
|
114
114
|
}
|
115
115
|
const handleCols = () => {
|
@@ -50,7 +50,7 @@ function batchElements(elements, groupSize, dmap) {
|
|
50
50
|
}
|
51
51
|
|
52
52
|
|
53
|
-
const FormContainer = forwardRef(({ cols = 1, children, mode = "view"
|
53
|
+
const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) => {
|
54
54
|
const [form] = Form.useForm();
|
55
55
|
const formContentRef = React.useRef(null);
|
56
56
|
const [formContent, setFormContent] = React.useState(null);
|
@@ -114,8 +114,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
114
114
|
setFieldsValue: (values) => {
|
115
115
|
lockStatus.current = 1;
|
116
116
|
let formData = { ...values, __id: values?.id }
|
117
|
-
|
118
|
-
// denyEdit 模式下仍需要记录字段变化用于显示/隐藏逻辑
|
119
117
|
for (let key in values) {
|
120
118
|
changedFieldsState.current[key] = { name: key, value: values[key] }
|
121
119
|
if (dependencyMap.current.has(key) && dependencyMap.current.get(key).componentName == "Field.Table" && Array.isArray(values[key])) {
|
@@ -128,19 +126,12 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
128
126
|
}
|
129
127
|
}
|
130
128
|
form.setFieldsValue(formData)
|
131
|
-
|
132
|
-
// denyEdit 模式下跳过复杂的级联处理,但保留简单的显示/隐藏处理
|
133
|
-
if (denyEdit) {
|
134
|
-
// 只处理显示/隐藏逻辑,不处理填充和数据获取
|
135
|
-
debounceHandleFieldsChange_ReadOnly()
|
136
|
-
} else {
|
137
|
-
debounceHandleFieldsChange()
|
138
|
-
}
|
129
|
+
debounceHandleFieldsChange()
|
139
130
|
},
|
140
131
|
initializeFieldVisibility: (reloadFields) => {
|
141
132
|
initializeFieldVisibility(reloadFields);
|
142
133
|
},
|
143
|
-
}), [
|
134
|
+
}), []);
|
144
135
|
|
145
136
|
// 添加节流后的 initializeFormRender
|
146
137
|
const throttledInitializeFormRender = React.useCallback(
|
@@ -257,7 +248,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
257
248
|
|
258
249
|
|
259
250
|
// 计算字段级联关系
|
260
|
-
const handleFieldsWith = async (identifier, fieldValues, init = false, fieldId = null) => {
|
251
|
+
const handleFieldsWith = async (identifier, fieldValues, init = false, fieldId = null, targetRowIndex = -1) => {
|
261
252
|
if (mode == "desgin") {
|
262
253
|
console.log("设计模式下不进行字段级联计算")
|
263
254
|
return false
|
@@ -291,24 +282,25 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
291
282
|
const dependentChildren = dependent.children;
|
292
283
|
|
293
284
|
|
294
|
-
if (!init && dependent?.fillRules && Array.isArray(dependent?.fillRules) && dependent?.fillRules.length > 0) {
|
285
|
+
if (!init && dependent?.fillRules && Array.isArray(dependent?.fillRules) && dependent?.fillRules.length > 0 && (!(typeof targetRowIndex === 'number' && targetRowIndex >= 0))) {
|
295
286
|
handleFillRules(identifier, parentIdentifier, fieldValues, dependent?.fillRules)
|
296
287
|
}
|
297
288
|
for (let index = 0; index < dependentChildren.length; index++) {
|
298
289
|
const child = dependentChildren[index];
|
299
|
-
if (
|
300
|
-
|
301
|
-
|
302
|
-
|
290
|
+
if (!(typeof targetRowIndex === 'number' && targetRowIndex >= 0)) {
|
291
|
+
if (child.component.props.withVisibleFunc && typeof child.component.props.withVisibleFunc === 'function') {
|
292
|
+
let needRefresh_ = handleFieldsVisibleFunc(fieldValues, child, parentIdentifier)
|
293
|
+
needRefresh = needRefresh || needRefresh_
|
294
|
+
}
|
303
295
|
|
304
|
-
|
305
|
-
|
306
|
-
|
296
|
+
if (child.component.props.withVisible) {
|
297
|
+
let needRefresh_ = await handleFieldsVisible(fieldValues, child, parentIdentifier, dependent?.componentName)
|
298
|
+
needRefresh = needRefresh || needRefresh_
|
299
|
+
}
|
307
300
|
}
|
308
301
|
|
309
|
-
|
310
302
|
if (!init && child.component.props.withFill)
|
311
|
-
await handleFieldsWithFill(fieldValues, child, parentIdentifier, dependent?.componentName, currentFieldId)
|
303
|
+
await handleFieldsWithFill(fieldValues, child, parentIdentifier, dependent?.componentName, currentFieldId, targetRowIndex)
|
312
304
|
|
313
305
|
}
|
314
306
|
}
|
@@ -319,54 +311,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
319
311
|
|
320
312
|
return needRefresh;
|
321
313
|
};
|
322
|
-
|
323
|
-
// denyEdit 模式专用函数 - 只处理显示/隐藏逻辑
|
324
|
-
const handleFieldsWithVisibleOnly = async (identifier, fieldValues, init = false, fieldId = null) => {
|
325
|
-
if (mode == "desgin") {
|
326
|
-
console.log("设计模式下不进行字段级联计算")
|
327
|
-
return false
|
328
|
-
}
|
329
|
-
|
330
|
-
console.log("handleFieldsWithVisibleOnly identifier", identifier)
|
331
|
-
let needRefresh = false;
|
332
|
-
let parentIdentifier = [];
|
333
|
-
if (Array.isArray(identifier)) {
|
334
|
-
parentIdentifier = [...(identifier.slice(0, -1))]
|
335
|
-
identifier = identifier.filter(item => typeof item == "string").join(".")
|
336
|
-
}
|
337
|
-
|
338
|
-
const currentFieldId = fieldId || identifier;
|
339
|
-
|
340
|
-
try {
|
341
|
-
if (dependencyMap.current.has(identifier)) {
|
342
|
-
const dependent = dependencyMap.current.get(identifier)
|
343
|
-
const dependentChildren = dependent.children;
|
344
|
-
|
345
|
-
// 只处理显示/隐藏逻辑,跳过填充规则
|
346
|
-
for (let index = 0; index < dependentChildren.length; index++) {
|
347
|
-
const child = dependentChildren[index];
|
348
|
-
|
349
|
-
// 处理 withVisibleFunc
|
350
|
-
if (child.component.props.withVisibleFunc && typeof child.component.props.withVisibleFunc === 'function') {
|
351
|
-
let needRefresh_ = handleFieldsVisibleFunc(fieldValues, child, parentIdentifier)
|
352
|
-
needRefresh = needRefresh || needRefresh_
|
353
|
-
}
|
354
|
-
|
355
|
-
// 处理 withVisible(但跳过数据获取部分)
|
356
|
-
if (child.component.props.withVisible) {
|
357
|
-
let needRefresh_ = await handleFieldsVisibleReadOnly(fieldValues, child, parentIdentifier, dependent?.componentName)
|
358
|
-
needRefresh = needRefresh || needRefresh_
|
359
|
-
}
|
360
|
-
|
361
|
-
// 跳过 withFill 处理
|
362
|
-
}
|
363
|
-
}
|
364
|
-
} catch (error) {
|
365
|
-
console.log("handleFieldsWithVisibleOnly error", error)
|
366
|
-
}
|
367
|
-
|
368
|
-
return needRefresh;
|
369
|
-
};
|
370
314
|
const removeLastFieldsValues = (name, isTable = false) => {
|
371
315
|
if (!lastFormValues.current) return
|
372
316
|
if (isTable) {
|
@@ -403,7 +347,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
403
347
|
const handleFillRules = (current_identifier, parentIdentifier, fieldValues, fillRules) => {
|
404
348
|
// 获取当前变更的字段数据
|
405
349
|
let current_value = getParamValue("fieldsValue", current_identifier, fieldValues, null)
|
406
|
-
console.log("handleFillRules current_value" + current_identifier, current_value)
|
407
350
|
let changedFields = {}
|
408
351
|
|
409
352
|
// 将标识符标准化为字符串
|
@@ -491,7 +434,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
491
434
|
console.log("rule?.type == 1 current_identifier", current_identifier)
|
492
435
|
form.setFieldValue(target, undefined);
|
493
436
|
}
|
494
|
-
console.log("form.setFieldValue(target, setValue) " +target, setValue)
|
437
|
+
console.log("form.setFieldValue(target, setValue) " + target, setValue)
|
495
438
|
form.setFieldValue(target, setValue)
|
496
439
|
|
497
440
|
// 处理完当前字段后从依赖路径中移除
|
@@ -618,64 +561,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
618
561
|
}
|
619
562
|
return needRefresh
|
620
563
|
}
|
621
|
-
|
622
|
-
// denyEdit 模式专用 - 处理级联显示隐藏(跳过数据获取)
|
623
|
-
const handleFieldsVisibleReadOnly = async (fieldValues, child, parentIdentifier, componentName) => {
|
624
|
-
let needRefresh = false;
|
625
|
-
const withFill = child?.component?.props.withVisible;
|
626
|
-
let withFillIndex = 0
|
627
|
-
let withFillGroup = ""
|
628
|
-
let childIdentifier = child.identifier;
|
629
|
-
|
630
|
-
// 跳过数据获取部分,使用空数组作为 withDatas
|
631
|
-
let withDatas = [];
|
632
|
-
|
633
|
-
// 构造计算公式(但不获取远程数据)
|
634
|
-
let formula;
|
635
|
-
if (withFill.value && withFill.value.length > 0) {
|
636
|
-
formula = withFill.value.map(item => {
|
637
|
-
let result = "";
|
638
|
-
const { insert, attributes } = item
|
639
|
-
if (typeof insert !== "string") {
|
640
|
-
if (insert?.span && attributes && attributes.tagKey && attributes.id) {
|
641
|
-
result = getParamValue(attributes.tagKey, attributes.id, fieldValues, withDatas)
|
642
|
-
if (Array.isArray(result)) {
|
643
|
-
if (Array.isArray(childIdentifier) && result.length > withFillIndex) {
|
644
|
-
result = result[withFillIndex]
|
645
|
-
}
|
646
|
-
if (typeof result === "object" && result !== null)
|
647
|
-
result = JSON.stringify(result)
|
648
|
-
}
|
649
|
-
else if (typeof result === "object" && result !== null) {
|
650
|
-
result = JSON.stringify(result)
|
651
|
-
}
|
652
|
-
else if (result.length > 0) result = `"${result}"`
|
653
|
-
}
|
654
|
-
}
|
655
|
-
else result = insert
|
656
|
-
return result
|
657
|
-
})
|
658
|
-
}
|
659
|
-
|
660
|
-
if (dependencyMap.current.has(childIdentifier)) {
|
661
|
-
const childData = dependencyMap.current.get(childIdentifier);
|
662
|
-
if (formula && formula.length > 0) {
|
663
|
-
const formulaResult = (evalFormula(formula) == "true");
|
664
|
-
console.log(`${childIdentifier} 只读模式计算公式:`, formula)
|
665
|
-
console.log(`${childIdentifier} 只读模式计算结果:`, formulaResult)
|
666
|
-
if (childData.show != formulaResult) {
|
667
|
-
childData.show = formulaResult;
|
668
|
-
dependencyMap.current.set(childIdentifier, childData);
|
669
|
-
needRefresh = true;
|
670
|
-
}
|
671
|
-
}
|
672
|
-
}
|
673
|
-
return needRefresh
|
674
|
-
}
|
675
|
-
|
676
564
|
// 处理级联数据源
|
677
565
|
// 处理级联填充
|
678
|
-
const handleFieldsWithFill = async (fieldValues, child, parentIdentifier, componentName, sourceFieldId) => {
|
566
|
+
const handleFieldsWithFill = async (fieldValues, child, parentIdentifier, componentName, sourceFieldId, targetRowIndex = -1) => {
|
679
567
|
// console.log("handleFieldsWithFill child.identifier", child.identifier)
|
680
568
|
// console.log("handleFieldsWithFill parentIdentifier", parentIdentifier)
|
681
569
|
console.log("handleFieldsWithFill componentName", componentName)
|
@@ -696,9 +584,14 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
696
584
|
childIdentifier = childIdentifier.split(".")
|
697
585
|
let table_values = getParamValue("fieldsValue", childIdentifier[0], fieldValues, [])
|
698
586
|
if (Array.isArray(table_values) && table_values.length > 0)
|
699
|
-
|
700
|
-
|
587
|
+
if (targetTableName && typeof targetRowIndex === 'number' && targetRowIndex >= 0) {
|
588
|
+
if (targetRowIndex < table_values.length) {
|
589
|
+
await handleFieldsWithFill(fieldValues, child, [childIdentifier[0], targetRowIndex], componentName, sourceFieldId)
|
590
|
+
}
|
701
591
|
}
|
592
|
+
for (let index = 0; index < table_values.length; index++) {
|
593
|
+
await handleFieldsWithFill(fieldValues, child, [childIdentifier[0], index], componentName, sourceFieldId)
|
594
|
+
}
|
702
595
|
|
703
596
|
return
|
704
597
|
}
|
@@ -893,59 +786,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
893
786
|
updateFormContent();
|
894
787
|
}
|
895
788
|
}, delay);
|
896
|
-
}, [
|
897
|
-
|
898
|
-
// denyEdit 模式专用的防抖处理函数 - 只处理显示/隐藏,不处理填充和数据获取
|
899
|
-
const debounceHandleFieldsChange_ReadOnly = React.useCallback(() => {
|
900
|
-
if (timeoutRef.current) {
|
901
|
-
clearTimeout(timeoutRef.current);
|
902
|
-
}
|
903
|
-
|
904
|
-
// 只读模式使用更短的延迟
|
905
|
-
const delay = 50;
|
906
|
-
|
907
|
-
timeoutRef.current = setTimeout(async () => {
|
908
|
-
const currentChanges = { ...changedFieldsState.current };
|
909
|
-
changedFieldsState.current = {};
|
910
|
-
|
911
|
-
const fieldValues = form.getFieldsValue();
|
912
|
-
let needRefresh = false;
|
913
|
-
if (!lastFormValues.current) lastFormValues.current = {}
|
914
|
-
|
915
|
-
// 创建已处理字段集合,用于避免多次处理同一字段
|
916
|
-
const processedFields = new Set();
|
917
|
-
for (let key in currentChanges) {
|
918
|
-
try {
|
919
|
-
let field = currentChanges[key];
|
920
|
-
if (!isEqual(field.value || "", getLastFieldValue(field.name) || "")) {
|
921
|
-
// 获取字段标识符(字符串形式)
|
922
|
-
const fieldId = Array.isArray(field.name)
|
923
|
-
? field.name.map(item => typeof item == "string" ? item : item.toString()).join(".")
|
924
|
-
: field.name;
|
925
|
-
|
926
|
-
// 跳过已处理的字段
|
927
|
-
if (processedFields.has(fieldId)) {
|
928
|
-
console.log("跳过已处理的字段 processedFields", fieldId)
|
929
|
-
continue;
|
930
|
-
}
|
931
|
-
processedFields.add(fieldId);
|
932
|
-
|
933
|
-
// 只处理显示/隐藏逻辑,不处理填充和数据获取
|
934
|
-
let needRefresh_ = await handleFieldsWithVisibleOnly(field.name, fieldValues, false, fieldId);
|
935
|
-
needRefresh = needRefresh || needRefresh_;
|
936
|
-
|
937
|
-
lastFormValues.current[normalizeFieldPath(field.name)] = field.value;
|
938
|
-
}
|
939
|
-
} catch (error) {
|
940
|
-
console.log("debounceHandleFieldsChange_ReadOnly error", error)
|
941
|
-
}
|
942
|
-
}
|
943
|
-
if (needRefresh) {
|
944
|
-
console.log("needRefresh (ReadOnly mode)", needRefresh)
|
945
|
-
updateFormContent();
|
946
|
-
}
|
947
|
-
}, delay);
|
948
|
-
}, [denyEdit]);
|
789
|
+
}, []);
|
949
790
|
|
950
791
|
const handleFieldsChange = React.useCallback((changedFields) => {
|
951
792
|
// console.log("handleFieldsChange (disabled, using handleValuesChange instead)", JSON.stringify(changedFields))
|
@@ -1015,15 +856,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit
|
|
1015
856
|
});
|
1016
857
|
|
1017
858
|
console.log("handleValuesChange changedFieldsState", JSON.parse(JSON.stringify(changedFieldsState.current)));
|
1018
|
-
|
1019
|
-
// denyEdit 模式下使用专用的处理函数
|
1020
|
-
if (denyEdit) {
|
1021
|
-
debounceHandleFieldsChange_ReadOnly();
|
1022
|
-
} else {
|
1023
|
-
debounceHandleFieldsChange();
|
1024
|
-
}
|
859
|
+
debounceHandleFieldsChange();
|
1025
860
|
}
|
1026
|
-
}, [
|
861
|
+
}, []);
|
1027
862
|
|
1028
863
|
const getTableWithIds = (ids) => {
|
1029
864
|
let withAllIds = []
|