szld-libs 0.2.70 → 0.2.72
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/szld-components.es.js +13051 -12759
- package/dist/szld-components.umd.js +54 -54
- package/es/components/DynamicForm/index.d.ts +7 -0
- package/es/components/DynamicForm/index.js +52 -7
- package/es/components/DynamicForm/useDynamicForm.d.ts +8 -2
- package/es/components/DynamicForm/useDynamicForm.js +263 -56
- package/es/utils/method.d.ts +21 -1
- package/es/utils/method.js +180 -80
- package/lib/components/DynamicForm/index.d.ts +7 -0
- package/lib/components/DynamicForm/index.js +49 -4
- package/lib/components/DynamicForm/useDynamicForm.d.ts +8 -2
- package/lib/components/DynamicForm/useDynamicForm.js +260 -53
- package/lib/utils/method.d.ts +21 -1
- package/lib/utils/method.js +180 -80
- package/package.json +1 -1
package/lib/utils/method.js
CHANGED
|
@@ -31,83 +31,119 @@ function isBase64(str) {
|
|
|
31
31
|
const handleSubmitForm = (originalData, allValues) => {
|
|
32
32
|
let updatedData = _.cloneDeep(originalData);
|
|
33
33
|
let uploadedFiles = [];
|
|
34
|
-
const processAttrList = (attrList) => {
|
|
35
|
-
var _a
|
|
36
|
-
const attrMap = new Map(attrList.map((item, index) => [item.attrid, index]));
|
|
34
|
+
const processAttrList = (attrList, item) => {
|
|
35
|
+
var _a;
|
|
37
36
|
try {
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
switch (inputType) {
|
|
50
|
-
case "image":
|
|
51
|
-
case "file":
|
|
52
|
-
case "video":
|
|
53
|
-
case "audio":
|
|
54
|
-
const parsedValue = typeof formValue === "string" ? JSON.parse(formValue) : formValue;
|
|
55
|
-
if (!Array.isArray(parsedValue)) {
|
|
56
|
-
attrItem.attrvalue = JSON.stringify([]);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const existingFiles = parsedValue.filter((file) => file.FileId);
|
|
60
|
-
const uploadedFileList = parsedValue.filter((file) => {
|
|
61
|
-
var _a2;
|
|
62
|
-
return file.status === "done" && ((_a2 = file.response) == null ? void 0 : _a2.data);
|
|
63
|
-
}).map((file) => file.response.data);
|
|
64
|
-
const allFiles = [...existingFiles, ...uploadedFileList];
|
|
65
|
-
uploadedFiles = [...uploadedFiles, ...uploadedFileList];
|
|
66
|
-
attrItem.attrvalue = JSON.stringify(allFiles);
|
|
67
|
-
break;
|
|
68
|
-
case "cascader":
|
|
69
|
-
if (Array.isArray(formValue) && formValue.length > 0) {
|
|
70
|
-
const delimiter = ((_c = attrItem.json) == null ? void 0 : _c["cascader-delimiter"]) || "/";
|
|
71
|
-
attrItem.attrvalue = formValue.join(delimiter);
|
|
72
|
-
} else {
|
|
73
|
-
attrItem.attrvalue = "";
|
|
74
|
-
}
|
|
75
|
-
break;
|
|
76
|
-
case "checkbox":
|
|
77
|
-
case "mult-select":
|
|
78
|
-
if (Array.isArray(formValue) && formValue.length > 0) {
|
|
79
|
-
attrItem.attrvalue = formValue.join(",");
|
|
80
|
-
} else {
|
|
81
|
-
attrItem.attrvalue = formValue;
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
|
-
case "date-picker":
|
|
85
|
-
if (formValue) {
|
|
86
|
-
attrItem.attrvalue = dayjs(formValue).format(format || "YYYY-MM-DD");
|
|
87
|
-
} else {
|
|
88
|
-
attrItem.attrvalue = "";
|
|
89
|
-
}
|
|
90
|
-
break;
|
|
91
|
-
case "time-picker":
|
|
92
|
-
if (formValue) {
|
|
93
|
-
attrItem.attrvalue = dayjs(formValue).format(format || "YYYY-MM-DD HH:mm:ss");
|
|
94
|
-
} else {
|
|
95
|
-
attrItem.attrvalue = "";
|
|
37
|
+
if ((_a = item == null ? void 0 : item.json) == null ? void 0 : _a["properties-multiple"]) {
|
|
38
|
+
const attrValue = allValues[item.attrid];
|
|
39
|
+
if (Array.isArray(attrValue)) {
|
|
40
|
+
const childrenObj = {};
|
|
41
|
+
attrValue.forEach((item2, index) => {
|
|
42
|
+
var _a2;
|
|
43
|
+
childrenObj[index] = _.cloneDeep(attrList);
|
|
44
|
+
for (const [fieldName, formValue] of Object.entries(item2)) {
|
|
45
|
+
const attrItem = (_a2 = childrenObj[index]) == null ? void 0 : _a2.find((item3) => item3.attrid === fieldName);
|
|
46
|
+
handleDealValue(attrItem, formValue);
|
|
96
47
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
attrItem.attrvalue = formValue;
|
|
100
|
-
break;
|
|
48
|
+
});
|
|
49
|
+
item.children = childrenObj;
|
|
101
50
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
51
|
+
} else {
|
|
52
|
+
const attrMap = new Map(attrList.map((item2, index) => [item2.attrid, index]));
|
|
53
|
+
for (const [fieldName, formValue] of Object.entries(allValues)) {
|
|
54
|
+
const index = attrMap.get(fieldName);
|
|
55
|
+
if (index === void 0)
|
|
56
|
+
continue;
|
|
57
|
+
const attrItem = attrList[index];
|
|
58
|
+
if (!formValue && formValue !== 0) {
|
|
59
|
+
attrItem.attrvalue = "";
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
handleDealValue(attrItem, formValue);
|
|
106
63
|
}
|
|
107
|
-
|
|
64
|
+
attrList.forEach((item2) => {
|
|
65
|
+
if (item2.children && Array.isArray(item2.children) && item2.children.length > 0) {
|
|
66
|
+
processAttrList(item2.children, item2);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
108
70
|
} catch (error) {
|
|
109
71
|
}
|
|
110
72
|
};
|
|
73
|
+
const handleDealValue = (attrItem, formValue) => {
|
|
74
|
+
var _a, _b, _c, _d;
|
|
75
|
+
const inputType = (_a = attrItem.json) == null ? void 0 : _a.input;
|
|
76
|
+
const format = (_b = attrItem.json) == null ? void 0 : _b["format"];
|
|
77
|
+
switch (inputType) {
|
|
78
|
+
case "image":
|
|
79
|
+
case "file":
|
|
80
|
+
case "video":
|
|
81
|
+
case "audio":
|
|
82
|
+
const parsedValue = typeof formValue === "string" ? JSON.parse(formValue) : formValue;
|
|
83
|
+
if (!Array.isArray(parsedValue)) {
|
|
84
|
+
attrItem.attrvalue = JSON.stringify([]);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const existingFiles = parsedValue.filter((file) => file.FileId);
|
|
88
|
+
const uploadedFileList = parsedValue.filter((file) => {
|
|
89
|
+
var _a2;
|
|
90
|
+
return file.status === "done" && ((_a2 = file.response) == null ? void 0 : _a2.data);
|
|
91
|
+
}).map((file) => file.response.data);
|
|
92
|
+
const allFiles = [...existingFiles, ...uploadedFileList];
|
|
93
|
+
uploadedFiles = [...uploadedFiles, ...uploadedFileList];
|
|
94
|
+
attrItem.attrvalue = JSON.stringify(allFiles);
|
|
95
|
+
break;
|
|
96
|
+
case "cascader":
|
|
97
|
+
if (Array.isArray(formValue) && formValue.length > 0) {
|
|
98
|
+
const delimiter = ((_c = attrItem.json) == null ? void 0 : _c["cascader-delimiter"]) || "/";
|
|
99
|
+
attrItem.attrvalue = formValue.join(delimiter);
|
|
100
|
+
} else {
|
|
101
|
+
attrItem.attrvalue = "";
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
case "range-picker":
|
|
105
|
+
if (Array.isArray(formValue) && formValue.length > 0) {
|
|
106
|
+
attrItem.attrvalue = formValue.join("~");
|
|
107
|
+
} else {
|
|
108
|
+
attrItem.attrvalue = "";
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
case "multiple-date-picker":
|
|
112
|
+
if (Array.isArray(formValue) && formValue.length > 0) {
|
|
113
|
+
attrItem.attrvalue = formValue.join(",");
|
|
114
|
+
} else {
|
|
115
|
+
attrItem.attrvalue = formValue;
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case "checkbox":
|
|
119
|
+
case "mult-select":
|
|
120
|
+
if (Array.isArray(formValue) && formValue.length > 0) {
|
|
121
|
+
attrItem.attrvalue = formValue.join(",");
|
|
122
|
+
} else {
|
|
123
|
+
attrItem.attrvalue = formValue;
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case "date-picker":
|
|
127
|
+
if (formValue) {
|
|
128
|
+
attrItem.attrvalue = dayjs(formValue).format(format || "YYYY-MM-DD");
|
|
129
|
+
} else {
|
|
130
|
+
attrItem.attrvalue = "";
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case "time-picker":
|
|
134
|
+
if (formValue) {
|
|
135
|
+
attrItem.attrvalue = dayjs(formValue).format(format || "YYYY-MM-DD HH:mm:ss");
|
|
136
|
+
} else {
|
|
137
|
+
attrItem.attrvalue = "";
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
if (!((_d = attrItem == null ? void 0 : attrItem.json) == null ? void 0 : _d["properties-multiple"])) {
|
|
142
|
+
attrItem.attrvalue = formValue;
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
111
147
|
if (updatedData.attr_list && Array.isArray(updatedData.attr_list)) {
|
|
112
148
|
processAttrList(updatedData.attr_list);
|
|
113
149
|
}
|
|
@@ -116,19 +152,76 @@ const handleSubmitForm = (originalData, allValues) => {
|
|
|
116
152
|
uploadedFiles
|
|
117
153
|
};
|
|
118
154
|
};
|
|
119
|
-
const
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
item.json = json;
|
|
125
|
-
} catch (error) {
|
|
126
|
-
item.json = {};
|
|
127
|
-
}
|
|
155
|
+
const processChildren = (items, extraAttrs) => {
|
|
156
|
+
return items.map((item) => {
|
|
157
|
+
const processedItem = processItem(item, extraAttrs);
|
|
158
|
+
if (processedItem.children && Array.isArray(processedItem.children)) {
|
|
159
|
+
processedItem.children = processChildren(processedItem.children);
|
|
128
160
|
}
|
|
129
|
-
return
|
|
161
|
+
return processedItem;
|
|
130
162
|
});
|
|
131
163
|
};
|
|
164
|
+
const processItem = (item, extraAttrs) => {
|
|
165
|
+
if (!item.json && item.info) {
|
|
166
|
+
try {
|
|
167
|
+
const infoStr = item.info_base64 === 1 ? base64ToString(item.info) : item.info;
|
|
168
|
+
const json = getJson(infoStr);
|
|
169
|
+
return { ...item, json, ...extraAttrs };
|
|
170
|
+
} catch (error) {
|
|
171
|
+
return { ...item, json: {}, ...extraAttrs };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return { ...item, ...extraAttrs };
|
|
175
|
+
};
|
|
176
|
+
const handleBaseAttrList = (attrList, extraAttrs) => {
|
|
177
|
+
return processChildren(attrList, extraAttrs);
|
|
178
|
+
};
|
|
179
|
+
const handleAttrList = (attrList, extraAttrs) => {
|
|
180
|
+
const parsedAttrList = processChildren(attrList, extraAttrs);
|
|
181
|
+
const combinationGroups = parsedAttrList.filter((item) => {
|
|
182
|
+
var _a;
|
|
183
|
+
return (_a = item.json) == null ? void 0 : _a.combination;
|
|
184
|
+
}).reduce((groups, item) => {
|
|
185
|
+
const combinationId = item.json["combination-id"];
|
|
186
|
+
if (!combinationId)
|
|
187
|
+
return groups;
|
|
188
|
+
if (!groups[combinationId]) {
|
|
189
|
+
groups[combinationId] = [];
|
|
190
|
+
}
|
|
191
|
+
groups[combinationId].push(item);
|
|
192
|
+
return groups;
|
|
193
|
+
}, {});
|
|
194
|
+
const excludeAttrIds = /* @__PURE__ */ new Set();
|
|
195
|
+
Object.values(combinationGroups).forEach((group) => {
|
|
196
|
+
if ((group == null ? void 0 : group.length) === 0)
|
|
197
|
+
return;
|
|
198
|
+
group.slice(1).forEach((item) => excludeAttrIds.add(item.attrid));
|
|
199
|
+
});
|
|
200
|
+
const filterAndCombine = (items) => {
|
|
201
|
+
return items.filter((item) => !excludeAttrIds.has(item.attrid)).map((item) => {
|
|
202
|
+
var _a;
|
|
203
|
+
const combinationId = (_a = item.json) == null ? void 0 : _a["combination-id"];
|
|
204
|
+
if (combinationId && combinationGroups[combinationId]) {
|
|
205
|
+
const processedItem = {
|
|
206
|
+
...item,
|
|
207
|
+
json: {
|
|
208
|
+
...item.json,
|
|
209
|
+
combinations: combinationGroups[combinationId]
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
if (processedItem.children && Array.isArray(processedItem.children)) {
|
|
213
|
+
processedItem.children = filterAndCombine(processedItem.children);
|
|
214
|
+
}
|
|
215
|
+
return processedItem;
|
|
216
|
+
}
|
|
217
|
+
if (item.children && Array.isArray(item.children)) {
|
|
218
|
+
item.children = filterAndCombine(item.children);
|
|
219
|
+
}
|
|
220
|
+
return item;
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
return filterAndCombine(parsedAttrList);
|
|
224
|
+
};
|
|
132
225
|
const handleFormConfig = async ({
|
|
133
226
|
number,
|
|
134
227
|
key,
|
|
@@ -202,10 +295,17 @@ const handleOperationFile = async (params, data, commonRequestWidthParams) => {
|
|
|
202
295
|
const response = await commonRequestWidthParams(params, data);
|
|
203
296
|
return response;
|
|
204
297
|
};
|
|
298
|
+
function handleKebabToCamel(str) {
|
|
299
|
+
return str.replace(/-([a-z])/g, function(match, letter) {
|
|
300
|
+
return letter.toUpperCase();
|
|
301
|
+
});
|
|
302
|
+
}
|
|
205
303
|
exports.base64ToString = base64ToString;
|
|
206
304
|
exports.getJson = getJson;
|
|
207
305
|
exports.handleAttrList = handleAttrList;
|
|
306
|
+
exports.handleBaseAttrList = handleBaseAttrList;
|
|
208
307
|
exports.handleFormConfig = handleFormConfig;
|
|
308
|
+
exports.handleKebabToCamel = handleKebabToCamel;
|
|
209
309
|
exports.handleOperationFile = handleOperationFile;
|
|
210
310
|
exports.handleSubmitForm = handleSubmitForm;
|
|
211
311
|
exports.isBase64 = isBase64;
|