szld-libs 0.2.70 → 0.2.71
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 +12770 -12501
- package/dist/szld-components.umd.js +53 -53
- 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 +240 -56
- package/es/utils/method.d.ts +21 -1
- package/es/utils/method.js +173 -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 +237 -53
- package/lib/utils/method.d.ts +21 -1
- package/lib/utils/method.js +173 -80
- package/package.json +1 -1
package/lib/utils/method.js
CHANGED
|
@@ -31,83 +31,112 @@ 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 "checkbox":
|
|
112
|
+
case "mult-select":
|
|
113
|
+
if (Array.isArray(formValue) && formValue.length > 0) {
|
|
114
|
+
attrItem.attrvalue = formValue.join(",");
|
|
115
|
+
} else {
|
|
116
|
+
attrItem.attrvalue = formValue;
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
case "date-picker":
|
|
120
|
+
if (formValue) {
|
|
121
|
+
attrItem.attrvalue = dayjs(formValue).format(format || "YYYY-MM-DD");
|
|
122
|
+
} else {
|
|
123
|
+
attrItem.attrvalue = "";
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case "time-picker":
|
|
127
|
+
if (formValue) {
|
|
128
|
+
attrItem.attrvalue = dayjs(formValue).format(format || "YYYY-MM-DD HH:mm:ss");
|
|
129
|
+
} else {
|
|
130
|
+
attrItem.attrvalue = "";
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
if (!((_d = attrItem == null ? void 0 : attrItem.json) == null ? void 0 : _d["properties-multiple"])) {
|
|
135
|
+
attrItem.attrvalue = formValue;
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
111
140
|
if (updatedData.attr_list && Array.isArray(updatedData.attr_list)) {
|
|
112
141
|
processAttrList(updatedData.attr_list);
|
|
113
142
|
}
|
|
@@ -116,19 +145,76 @@ const handleSubmitForm = (originalData, allValues) => {
|
|
|
116
145
|
uploadedFiles
|
|
117
146
|
};
|
|
118
147
|
};
|
|
119
|
-
const
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
item.json = json;
|
|
125
|
-
} catch (error) {
|
|
126
|
-
item.json = {};
|
|
127
|
-
}
|
|
148
|
+
const processChildren = (items, extraAttrs) => {
|
|
149
|
+
return items.map((item) => {
|
|
150
|
+
const processedItem = processItem(item, extraAttrs);
|
|
151
|
+
if (processedItem.children && Array.isArray(processedItem.children)) {
|
|
152
|
+
processedItem.children = processChildren(processedItem.children);
|
|
128
153
|
}
|
|
129
|
-
return
|
|
154
|
+
return processedItem;
|
|
130
155
|
});
|
|
131
156
|
};
|
|
157
|
+
const processItem = (item, extraAttrs) => {
|
|
158
|
+
if (!item.json && item.info) {
|
|
159
|
+
try {
|
|
160
|
+
const infoStr = item.info_base64 === 1 ? base64ToString(item.info) : item.info;
|
|
161
|
+
const json = getJson(infoStr);
|
|
162
|
+
return { ...item, json, ...extraAttrs };
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return { ...item, json: {}, ...extraAttrs };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return { ...item, ...extraAttrs };
|
|
168
|
+
};
|
|
169
|
+
const handleBaseAttrList = (attrList, extraAttrs) => {
|
|
170
|
+
return processChildren(attrList, extraAttrs);
|
|
171
|
+
};
|
|
172
|
+
const handleAttrList = (attrList, extraAttrs) => {
|
|
173
|
+
const parsedAttrList = processChildren(attrList, extraAttrs);
|
|
174
|
+
const combinationGroups = parsedAttrList.filter((item) => {
|
|
175
|
+
var _a;
|
|
176
|
+
return (_a = item.json) == null ? void 0 : _a.combination;
|
|
177
|
+
}).reduce((groups, item) => {
|
|
178
|
+
const combinationId = item.json["combination-id"];
|
|
179
|
+
if (!combinationId)
|
|
180
|
+
return groups;
|
|
181
|
+
if (!groups[combinationId]) {
|
|
182
|
+
groups[combinationId] = [];
|
|
183
|
+
}
|
|
184
|
+
groups[combinationId].push(item);
|
|
185
|
+
return groups;
|
|
186
|
+
}, {});
|
|
187
|
+
const excludeAttrIds = /* @__PURE__ */ new Set();
|
|
188
|
+
Object.values(combinationGroups).forEach((group) => {
|
|
189
|
+
if ((group == null ? void 0 : group.length) === 0)
|
|
190
|
+
return;
|
|
191
|
+
group.slice(1).forEach((item) => excludeAttrIds.add(item.attrid));
|
|
192
|
+
});
|
|
193
|
+
const filterAndCombine = (items) => {
|
|
194
|
+
return items.filter((item) => !excludeAttrIds.has(item.attrid)).map((item) => {
|
|
195
|
+
var _a;
|
|
196
|
+
const combinationId = (_a = item.json) == null ? void 0 : _a["combination-id"];
|
|
197
|
+
if (combinationId && combinationGroups[combinationId]) {
|
|
198
|
+
const processedItem = {
|
|
199
|
+
...item,
|
|
200
|
+
json: {
|
|
201
|
+
...item.json,
|
|
202
|
+
combinations: combinationGroups[combinationId]
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
if (processedItem.children && Array.isArray(processedItem.children)) {
|
|
206
|
+
processedItem.children = filterAndCombine(processedItem.children);
|
|
207
|
+
}
|
|
208
|
+
return processedItem;
|
|
209
|
+
}
|
|
210
|
+
if (item.children && Array.isArray(item.children)) {
|
|
211
|
+
item.children = filterAndCombine(item.children);
|
|
212
|
+
}
|
|
213
|
+
return item;
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
return filterAndCombine(parsedAttrList);
|
|
217
|
+
};
|
|
132
218
|
const handleFormConfig = async ({
|
|
133
219
|
number,
|
|
134
220
|
key,
|
|
@@ -202,10 +288,17 @@ const handleOperationFile = async (params, data, commonRequestWidthParams) => {
|
|
|
202
288
|
const response = await commonRequestWidthParams(params, data);
|
|
203
289
|
return response;
|
|
204
290
|
};
|
|
291
|
+
function handleKebabToCamel(str) {
|
|
292
|
+
return str.replace(/-([a-z])/g, function(match, letter) {
|
|
293
|
+
return letter.toUpperCase();
|
|
294
|
+
});
|
|
295
|
+
}
|
|
205
296
|
exports.base64ToString = base64ToString;
|
|
206
297
|
exports.getJson = getJson;
|
|
207
298
|
exports.handleAttrList = handleAttrList;
|
|
299
|
+
exports.handleBaseAttrList = handleBaseAttrList;
|
|
208
300
|
exports.handleFormConfig = handleFormConfig;
|
|
301
|
+
exports.handleKebabToCamel = handleKebabToCamel;
|
|
209
302
|
exports.handleOperationFile = handleOperationFile;
|
|
210
303
|
exports.handleSubmitForm = handleSubmitForm;
|
|
211
304
|
exports.isBase64 = isBase64;
|