lu-lowcode-package-form 0.11.84 → 0.11.85
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 +304 -304
- package/dist/index.es.js +26233 -26159
- package/package.json +1 -1
- package/src/App.jsx +2 -2
- package/src/components/form-container/index.jsx +176 -6
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, "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" }]) })
|
112
|
+
formRef?.current?.setFieldsValue({ "__id": 1, "routeType":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 = () => {
|
@@ -189,7 +189,7 @@ function App() {
|
|
189
189
|
<div className='fw-[960px] frounded fbg-slate-50 fflex fflex-col fitems-center fpb-10'>
|
190
190
|
|
191
191
|
|
192
|
-
<FormContainerWrapper cols={cols} key={"formc"} className="" ref={formRef} >
|
192
|
+
<FormContainerWrapper denyEdit={true} cols={cols} key={"formc"} className="" ref={formRef} >
|
193
193
|
|
194
194
|
<Field.WithSingleSelect
|
195
195
|
ref={testRef}
|
@@ -50,7 +50,7 @@ function batchElements(elements, groupSize, dmap) {
|
|
50
50
|
}
|
51
51
|
|
52
52
|
|
53
|
-
const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) => {
|
53
|
+
const FormContainer = forwardRef(({ cols = 1, children, mode = "view", denyEdit = false }, ref) => {
|
54
54
|
const [form] = Form.useForm();
|
55
55
|
const formContentRef = React.useRef(null);
|
56
56
|
const [formContent, setFormContent] = React.useState(null);
|
@@ -114,6 +114,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
114
114
|
setFieldsValue: (values) => {
|
115
115
|
lockStatus.current = 1;
|
116
116
|
let formData = { ...values, __id: values?.id }
|
117
|
+
|
118
|
+
// denyEdit 模式下仍需要记录字段变化用于显示/隐藏逻辑
|
117
119
|
for (let key in values) {
|
118
120
|
changedFieldsState.current[key] = { name: key, value: values[key] }
|
119
121
|
if (dependencyMap.current.has(key) && dependencyMap.current.get(key).componentName == "Field.Table" && Array.isArray(values[key])) {
|
@@ -126,12 +128,19 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
126
128
|
}
|
127
129
|
}
|
128
130
|
form.setFieldsValue(formData)
|
129
|
-
|
131
|
+
|
132
|
+
// denyEdit 模式下跳过复杂的级联处理,但保留简单的显示/隐藏处理
|
133
|
+
if (denyEdit) {
|
134
|
+
// 只处理显示/隐藏逻辑,不处理填充和数据获取
|
135
|
+
debounceHandleFieldsChange_ReadOnly()
|
136
|
+
} else {
|
137
|
+
debounceHandleFieldsChange()
|
138
|
+
}
|
130
139
|
},
|
131
140
|
initializeFieldVisibility: (reloadFields) => {
|
132
141
|
initializeFieldVisibility(reloadFields);
|
133
142
|
},
|
134
|
-
}), []);
|
143
|
+
}), [denyEdit]);
|
135
144
|
|
136
145
|
// 添加节流后的 initializeFormRender
|
137
146
|
const throttledInitializeFormRender = React.useCallback(
|
@@ -310,6 +319,54 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
310
319
|
|
311
320
|
return needRefresh;
|
312
321
|
};
|
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
|
+
};
|
313
370
|
const removeLastFieldsValues = (name, isTable = false) => {
|
314
371
|
if (!lastFormValues.current) return
|
315
372
|
if (isTable) {
|
@@ -560,6 +617,61 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
560
617
|
}
|
561
618
|
return needRefresh
|
562
619
|
}
|
620
|
+
|
621
|
+
// denyEdit 模式专用 - 处理级联显示隐藏(跳过数据获取)
|
622
|
+
const handleFieldsVisibleReadOnly = async (fieldValues, child, parentIdentifier, componentName) => {
|
623
|
+
let needRefresh = false;
|
624
|
+
const withFill = child?.component?.props.withVisible;
|
625
|
+
let withFillIndex = 0
|
626
|
+
let withFillGroup = ""
|
627
|
+
let childIdentifier = child.identifier;
|
628
|
+
|
629
|
+
// 跳过数据获取部分,使用空数组作为 withDatas
|
630
|
+
let withDatas = [];
|
631
|
+
|
632
|
+
// 构造计算公式(但不获取远程数据)
|
633
|
+
let formula;
|
634
|
+
if (withFill.value && withFill.value.length > 0) {
|
635
|
+
formula = withFill.value.map(item => {
|
636
|
+
let result = "";
|
637
|
+
const { insert, attributes } = item
|
638
|
+
if (typeof insert !== "string") {
|
639
|
+
if (insert?.span && attributes && attributes.tagKey && attributes.id) {
|
640
|
+
result = getParamValue(attributes.tagKey, attributes.id, fieldValues, withDatas)
|
641
|
+
if (Array.isArray(result)) {
|
642
|
+
if (Array.isArray(childIdentifier) && result.length > withFillIndex) {
|
643
|
+
result = result[withFillIndex]
|
644
|
+
}
|
645
|
+
if (typeof result === "object" && result !== null)
|
646
|
+
result = JSON.stringify(result)
|
647
|
+
}
|
648
|
+
else if (typeof result === "object" && result !== null) {
|
649
|
+
result = JSON.stringify(result)
|
650
|
+
}
|
651
|
+
else if (result.length > 0) result = `"${result}"`
|
652
|
+
}
|
653
|
+
}
|
654
|
+
else result = insert
|
655
|
+
return result
|
656
|
+
})
|
657
|
+
}
|
658
|
+
|
659
|
+
if (dependencyMap.current.has(childIdentifier)) {
|
660
|
+
const childData = dependencyMap.current.get(childIdentifier);
|
661
|
+
if (formula && formula.length > 0) {
|
662
|
+
const formulaResult = (evalFormula(formula) == "true");
|
663
|
+
console.log(`${childIdentifier} 只读模式计算公式:`, formula)
|
664
|
+
console.log(`${childIdentifier} 只读模式计算结果:`, formulaResult)
|
665
|
+
if (childData.show != formulaResult) {
|
666
|
+
childData.show = formulaResult;
|
667
|
+
dependencyMap.current.set(childIdentifier, childData);
|
668
|
+
needRefresh = true;
|
669
|
+
}
|
670
|
+
}
|
671
|
+
}
|
672
|
+
return needRefresh
|
673
|
+
}
|
674
|
+
|
563
675
|
// 处理级联数据源
|
564
676
|
// 处理级联填充
|
565
677
|
const handleFieldsWithFill = async (fieldValues, child, parentIdentifier, componentName, sourceFieldId) => {
|
@@ -780,7 +892,59 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
780
892
|
updateFormContent();
|
781
893
|
}
|
782
894
|
}, delay);
|
783
|
-
}, []);
|
895
|
+
}, [denyEdit]);
|
896
|
+
|
897
|
+
// denyEdit 模式专用的防抖处理函数 - 只处理显示/隐藏,不处理填充和数据获取
|
898
|
+
const debounceHandleFieldsChange_ReadOnly = React.useCallback(() => {
|
899
|
+
if (timeoutRef.current) {
|
900
|
+
clearTimeout(timeoutRef.current);
|
901
|
+
}
|
902
|
+
|
903
|
+
// 只读模式使用更短的延迟
|
904
|
+
const delay = 50;
|
905
|
+
|
906
|
+
timeoutRef.current = setTimeout(async () => {
|
907
|
+
const currentChanges = { ...changedFieldsState.current };
|
908
|
+
changedFieldsState.current = {};
|
909
|
+
|
910
|
+
const fieldValues = form.getFieldsValue();
|
911
|
+
let needRefresh = false;
|
912
|
+
if (!lastFormValues.current) lastFormValues.current = {}
|
913
|
+
|
914
|
+
// 创建已处理字段集合,用于避免多次处理同一字段
|
915
|
+
const processedFields = new Set();
|
916
|
+
for (let key in currentChanges) {
|
917
|
+
try {
|
918
|
+
let field = currentChanges[key];
|
919
|
+
if (!isEqual(field.value || "", getLastFieldValue(field.name) || "")) {
|
920
|
+
// 获取字段标识符(字符串形式)
|
921
|
+
const fieldId = Array.isArray(field.name)
|
922
|
+
? field.name.map(item => typeof item == "string" ? item : item.toString()).join(".")
|
923
|
+
: field.name;
|
924
|
+
|
925
|
+
// 跳过已处理的字段
|
926
|
+
if (processedFields.has(fieldId)) {
|
927
|
+
console.log("跳过已处理的字段 processedFields", fieldId)
|
928
|
+
continue;
|
929
|
+
}
|
930
|
+
processedFields.add(fieldId);
|
931
|
+
|
932
|
+
// 只处理显示/隐藏逻辑,不处理填充和数据获取
|
933
|
+
let needRefresh_ = await handleFieldsWithVisibleOnly(field.name, fieldValues, false, fieldId);
|
934
|
+
needRefresh = needRefresh || needRefresh_;
|
935
|
+
|
936
|
+
lastFormValues.current[normalizeFieldPath(field.name)] = field.value;
|
937
|
+
}
|
938
|
+
} catch (error) {
|
939
|
+
console.log("debounceHandleFieldsChange_ReadOnly error", error)
|
940
|
+
}
|
941
|
+
}
|
942
|
+
if (needRefresh) {
|
943
|
+
console.log("needRefresh (ReadOnly mode)", needRefresh)
|
944
|
+
updateFormContent();
|
945
|
+
}
|
946
|
+
}, delay);
|
947
|
+
}, [denyEdit]);
|
784
948
|
|
785
949
|
const handleFieldsChange = React.useCallback((changedFields) => {
|
786
950
|
// console.log("handleFieldsChange (disabled, using handleValuesChange instead)", JSON.stringify(changedFields))
|
@@ -850,9 +1014,15 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
850
1014
|
});
|
851
1015
|
|
852
1016
|
console.log("handleValuesChange changedFieldsState", JSON.parse(JSON.stringify(changedFieldsState.current)));
|
853
|
-
|
1017
|
+
|
1018
|
+
// denyEdit 模式下使用专用的处理函数
|
1019
|
+
if (denyEdit) {
|
1020
|
+
debounceHandleFieldsChange_ReadOnly();
|
1021
|
+
} else {
|
1022
|
+
debounceHandleFieldsChange();
|
1023
|
+
}
|
854
1024
|
}
|
855
|
-
}, []);
|
1025
|
+
}, [denyEdit]);
|
856
1026
|
|
857
1027
|
const getTableWithIds = (ids) => {
|
858
1028
|
let withAllIds = []
|