szld-libs 0.3.1 → 0.3.2

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/es/index.js CHANGED
@@ -22,7 +22,6 @@ const Demo = () => {
22
22
  /* @__PURE__ */ jsx(
23
23
  DynamicFormMobile,
24
24
  {
25
- interfaceTypeChildren: "YLFWLRDetailAttrlist",
26
25
  formConfig: handleAttrList(attrList),
27
26
  readonly: false,
28
27
  relatedid: "guid",
@@ -13,7 +13,9 @@ export declare function isBase64(str: string): boolean;
13
13
  export declare const handleSubmitForm: (originalData: {
14
14
  attr_list: any[];
15
15
  isMobile?: boolean;
16
- }, allValues: any, isListToObj?: boolean) => {
16
+ guid?: string;
17
+ isListToObj?: boolean;
18
+ }, allValues: any) => {
17
19
  updatedData: any;
18
20
  uploadedFiles: any[];
19
21
  };
@@ -27,32 +27,36 @@ function isBase64(str) {
27
27
  const base64Regex = /^[A-Za-z0-9+/]+(?:=?=?)$/;
28
28
  return base64Regex.test(str);
29
29
  }
30
- const handleSubmitForm = (originalData, allValues, isListToObj) => {
30
+ const handleSubmitForm = (originalData, allValues) => {
31
+ var _a;
31
32
  let updatedData = _.cloneDeep(originalData);
32
- const { isMobile = false } = originalData;
33
+ const { attr_list = [] } = updatedData;
34
+ const { isMobile = false, guid, isListToObj = false } = originalData;
33
35
  let uploadedFiles = [];
34
- const processAttrList = (attrList) => {
36
+ const processAttrList = (attrList, values) => {
35
37
  try {
36
38
  const attrMap = new Map(attrList.map((item, index) => [item.attrid, index]));
37
- for (const [fieldName, formValue] of Object.entries(allValues)) {
39
+ for (const [fieldName, formValue] of Object.entries(values)) {
38
40
  const index = attrMap.get(fieldName);
39
- if (index === void 0)
41
+ if (index === void 0) {
40
42
  continue;
41
- const attrItem = attrList[index];
43
+ }
44
+ let attrItem = attrList[index];
42
45
  if (!formValue && formValue !== 0) {
43
46
  attrItem.attrvalue = "";
44
47
  continue;
45
48
  }
46
- handleDealValue(attrItem, formValue, isMobile);
49
+ attrItem = handleDealValue(attrItem, formValue, isMobile);
47
50
  }
48
51
  attrList.forEach((item) => {
49
52
  if (item.children && Array.isArray(item.children) && item.children.length > 0 && !Array.isArray(item.children[0])) {
50
- processAttrList(item.children);
53
+ processAttrList(item.children, values[item.attrid]);
51
54
  }
52
55
  if (item.children && Array.isArray(item.children) && item.children.length > 0 && Array.isArray(item.children[0])) {
53
- item.children.forEach((v) => {
54
- if (v.children && Array.isArray(v.children)) {
55
- processAttrList(v.children);
56
+ item.children.forEach((v, i) => {
57
+ var _a2;
58
+ if (v && Array.isArray(v)) {
59
+ processAttrList(v, (_a2 = values == null ? void 0 : values[item.attrid]) == null ? void 0 : _a2[i]);
56
60
  }
57
61
  });
58
62
  }
@@ -61,8 +65,8 @@ const handleSubmitForm = (originalData, allValues, isListToObj) => {
61
65
  }
62
66
  };
63
67
  const handleDealValue = (attrItem, formValue, isMobile2) => {
64
- var _a, _b, _c, _d;
65
- const inputType = (_a = attrItem.json) == null ? void 0 : _a.input;
68
+ var _a2, _b, _c, _d;
69
+ const inputType = (_a2 = attrItem.json) == null ? void 0 : _a2.input;
66
70
  const format = (_b = attrItem.json) == null ? void 0 : _b["format"];
67
71
  switch (inputType) {
68
72
  case "image":
@@ -76,8 +80,8 @@ const handleSubmitForm = (originalData, allValues, isListToObj) => {
76
80
  }
77
81
  const existingFiles = parsedValue.filter((file) => file.FileId);
78
82
  const uploadedFileList = parsedValue.filter((file) => {
79
- var _a2;
80
- return file.status === "done" && ((_a2 = file.response) == null ? void 0 : _a2.data);
83
+ var _a3;
84
+ return file.status === "done" && ((_a3 = file.response) == null ? void 0 : _a3.data);
81
85
  }).map((file) => file.response.data);
82
86
  const allFiles = [...existingFiles, ...uploadedFileList];
83
87
  uploadedFiles = [...uploadedFiles, ...uploadedFileList];
@@ -149,10 +153,25 @@ const handleSubmitForm = (originalData, allValues, isListToObj) => {
149
153
  }
150
154
  break;
151
155
  }
156
+ return attrItem;
152
157
  };
153
158
  if (updatedData.attr_list && Array.isArray(updatedData.attr_list)) {
154
- processAttrList(updatedData.attr_list);
159
+ processAttrList(attr_list, allValues);
155
160
  }
161
+ (_a = updatedData == null ? void 0 : updatedData.attr_list) == null ? void 0 : _a.forEach((v) => {
162
+ var _a2, _b, _c, _d, _e, _f;
163
+ if (((_a2 = v == null ? void 0 : v.json) == null ? void 0 : _a2["auto-generate"]) && ((_b = v == null ? void 0 : v.json) == null ? void 0 : _b["auto-generate-type"])) {
164
+ if (((_c = v == null ? void 0 : v.json) == null ? void 0 : _c["auto-generate-type"]) === "currenttime") {
165
+ v.attrvalue = dayjs().format("YYYY-MM-DD HH:mm:ss");
166
+ }
167
+ if (((_d = v == null ? void 0 : v.json) == null ? void 0 : _d["auto-generate-type"]) === "guid") {
168
+ v.attrvalue = guid || "";
169
+ }
170
+ }
171
+ if ((_e = v == null ? void 0 : v.json) == null ? void 0 : _e["default"]) {
172
+ v.attrvalue = (_f = v == null ? void 0 : v.json) == null ? void 0 : _f["default"];
173
+ }
174
+ });
156
175
  return {
157
176
  updatedData: isListToObj ? handleAttrListToObj(updatedData.attr_list || []) : updatedData,
158
177
  uploadedFiles
@@ -330,12 +349,8 @@ const handleAttrListToObj = (attrList) => {
330
349
  data_list: [processLevel(item.children)]
331
350
  };
332
351
  } else if (item.attrtype === 1 && item.children.length > 0 && Array.isArray(item.children)) {
333
- let { attrvalue = [], children = [] } = item || {};
334
- attrvalue = Array.isArray(attrvalue) ? attrvalue : [attrvalue];
335
- if (Array.isArray(attrvalue) && (attrvalue == null ? void 0 : attrvalue.length)) {
336
- item.children = attrvalue.map((v) => {
337
- return handleObjDetailToSignleAttrList((children == null ? void 0 : children[0]) || [], v);
338
- });
352
+ const { children = [] } = item || {};
353
+ if ((children == null ? void 0 : children.length) && Array.isArray(children == null ? void 0 : children[0])) {
339
354
  result[key] = {
340
355
  asid: ((_e = (_d = (_c = item.children) == null ? void 0 : _c[0]) == null ? void 0 : _d[0]) == null ? void 0 : _e.asid) || "",
341
356
  data_list: item.children.map((child) => {
@@ -488,12 +503,6 @@ const handleSelectOptions = async ({
488
503
  }
489
504
  return options;
490
505
  };
491
- const handleObjDetailToSignleAttrList = (attrList, detail) => {
492
- return attrList.map((item) => ({
493
- ...item,
494
- attrvalue: detail[item.attrid] || ""
495
- }));
496
- };
497
506
  export {
498
507
  base64ToString,
499
508
  getJson,
package/lib/index.js CHANGED
@@ -23,7 +23,6 @@ const Demo = () => {
23
23
  /* @__PURE__ */ jsxRuntime.jsx(
24
24
  main.DynamicFormMobile,
25
25
  {
26
- interfaceTypeChildren: "YLFWLRDetailAttrlist",
27
26
  formConfig: method.handleAttrList(mock.attrList),
28
27
  readonly: false,
29
28
  relatedid: "guid",
@@ -13,7 +13,9 @@ export declare function isBase64(str: string): boolean;
13
13
  export declare const handleSubmitForm: (originalData: {
14
14
  attr_list: any[];
15
15
  isMobile?: boolean;
16
- }, allValues: any, isListToObj?: boolean) => {
16
+ guid?: string;
17
+ isListToObj?: boolean;
18
+ }, allValues: any) => {
17
19
  updatedData: any;
18
20
  uploadedFiles: any[];
19
21
  };
@@ -29,32 +29,36 @@ function isBase64(str) {
29
29
  const base64Regex = /^[A-Za-z0-9+/]+(?:=?=?)$/;
30
30
  return base64Regex.test(str);
31
31
  }
32
- const handleSubmitForm = (originalData, allValues, isListToObj) => {
32
+ const handleSubmitForm = (originalData, allValues) => {
33
+ var _a;
33
34
  let updatedData = _.cloneDeep(originalData);
34
- const { isMobile = false } = originalData;
35
+ const { attr_list = [] } = updatedData;
36
+ const { isMobile = false, guid, isListToObj = false } = originalData;
35
37
  let uploadedFiles = [];
36
- const processAttrList = (attrList) => {
38
+ const processAttrList = (attrList, values) => {
37
39
  try {
38
40
  const attrMap = new Map(attrList.map((item, index) => [item.attrid, index]));
39
- for (const [fieldName, formValue] of Object.entries(allValues)) {
41
+ for (const [fieldName, formValue] of Object.entries(values)) {
40
42
  const index = attrMap.get(fieldName);
41
- if (index === void 0)
43
+ if (index === void 0) {
42
44
  continue;
43
- const attrItem = attrList[index];
45
+ }
46
+ let attrItem = attrList[index];
44
47
  if (!formValue && formValue !== 0) {
45
48
  attrItem.attrvalue = "";
46
49
  continue;
47
50
  }
48
- handleDealValue(attrItem, formValue, isMobile);
51
+ attrItem = handleDealValue(attrItem, formValue, isMobile);
49
52
  }
50
53
  attrList.forEach((item) => {
51
54
  if (item.children && Array.isArray(item.children) && item.children.length > 0 && !Array.isArray(item.children[0])) {
52
- processAttrList(item.children);
55
+ processAttrList(item.children, values[item.attrid]);
53
56
  }
54
57
  if (item.children && Array.isArray(item.children) && item.children.length > 0 && Array.isArray(item.children[0])) {
55
- item.children.forEach((v) => {
56
- if (v.children && Array.isArray(v.children)) {
57
- processAttrList(v.children);
58
+ item.children.forEach((v, i) => {
59
+ var _a2;
60
+ if (v && Array.isArray(v)) {
61
+ processAttrList(v, (_a2 = values == null ? void 0 : values[item.attrid]) == null ? void 0 : _a2[i]);
58
62
  }
59
63
  });
60
64
  }
@@ -63,8 +67,8 @@ const handleSubmitForm = (originalData, allValues, isListToObj) => {
63
67
  }
64
68
  };
65
69
  const handleDealValue = (attrItem, formValue, isMobile2) => {
66
- var _a, _b, _c, _d;
67
- const inputType = (_a = attrItem.json) == null ? void 0 : _a.input;
70
+ var _a2, _b, _c, _d;
71
+ const inputType = (_a2 = attrItem.json) == null ? void 0 : _a2.input;
68
72
  const format = (_b = attrItem.json) == null ? void 0 : _b["format"];
69
73
  switch (inputType) {
70
74
  case "image":
@@ -78,8 +82,8 @@ const handleSubmitForm = (originalData, allValues, isListToObj) => {
78
82
  }
79
83
  const existingFiles = parsedValue.filter((file) => file.FileId);
80
84
  const uploadedFileList = parsedValue.filter((file) => {
81
- var _a2;
82
- return file.status === "done" && ((_a2 = file.response) == null ? void 0 : _a2.data);
85
+ var _a3;
86
+ return file.status === "done" && ((_a3 = file.response) == null ? void 0 : _a3.data);
83
87
  }).map((file) => file.response.data);
84
88
  const allFiles = [...existingFiles, ...uploadedFileList];
85
89
  uploadedFiles = [...uploadedFiles, ...uploadedFileList];
@@ -151,10 +155,25 @@ const handleSubmitForm = (originalData, allValues, isListToObj) => {
151
155
  }
152
156
  break;
153
157
  }
158
+ return attrItem;
154
159
  };
155
160
  if (updatedData.attr_list && Array.isArray(updatedData.attr_list)) {
156
- processAttrList(updatedData.attr_list);
161
+ processAttrList(attr_list, allValues);
157
162
  }
163
+ (_a = updatedData == null ? void 0 : updatedData.attr_list) == null ? void 0 : _a.forEach((v) => {
164
+ var _a2, _b, _c, _d, _e, _f;
165
+ if (((_a2 = v == null ? void 0 : v.json) == null ? void 0 : _a2["auto-generate"]) && ((_b = v == null ? void 0 : v.json) == null ? void 0 : _b["auto-generate-type"])) {
166
+ if (((_c = v == null ? void 0 : v.json) == null ? void 0 : _c["auto-generate-type"]) === "currenttime") {
167
+ v.attrvalue = dayjs().format("YYYY-MM-DD HH:mm:ss");
168
+ }
169
+ if (((_d = v == null ? void 0 : v.json) == null ? void 0 : _d["auto-generate-type"]) === "guid") {
170
+ v.attrvalue = guid || "";
171
+ }
172
+ }
173
+ if ((_e = v == null ? void 0 : v.json) == null ? void 0 : _e["default"]) {
174
+ v.attrvalue = (_f = v == null ? void 0 : v.json) == null ? void 0 : _f["default"];
175
+ }
176
+ });
158
177
  return {
159
178
  updatedData: isListToObj ? handleAttrListToObj(updatedData.attr_list || []) : updatedData,
160
179
  uploadedFiles
@@ -332,12 +351,8 @@ const handleAttrListToObj = (attrList) => {
332
351
  data_list: [processLevel(item.children)]
333
352
  };
334
353
  } else if (item.attrtype === 1 && item.children.length > 0 && Array.isArray(item.children)) {
335
- let { attrvalue = [], children = [] } = item || {};
336
- attrvalue = Array.isArray(attrvalue) ? attrvalue : [attrvalue];
337
- if (Array.isArray(attrvalue) && (attrvalue == null ? void 0 : attrvalue.length)) {
338
- item.children = attrvalue.map((v) => {
339
- return handleObjDetailToSignleAttrList((children == null ? void 0 : children[0]) || [], v);
340
- });
354
+ const { children = [] } = item || {};
355
+ if ((children == null ? void 0 : children.length) && Array.isArray(children == null ? void 0 : children[0])) {
341
356
  result[key] = {
342
357
  asid: ((_e = (_d = (_c = item.children) == null ? void 0 : _c[0]) == null ? void 0 : _d[0]) == null ? void 0 : _e.asid) || "",
343
358
  data_list: item.children.map((child) => {
@@ -490,12 +505,6 @@ const handleSelectOptions = async ({
490
505
  }
491
506
  return options;
492
507
  };
493
- const handleObjDetailToSignleAttrList = (attrList, detail) => {
494
- return attrList.map((item) => ({
495
- ...item,
496
- attrvalue: detail[item.attrid] || ""
497
- }));
498
- };
499
508
  exports.base64ToString = base64ToString;
500
509
  exports.getJson = getJson;
501
510
  exports.handleAttrList = handleAttrList;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "szld-libs",
3
3
  "private": false,
4
- "version": "0.3.1",
4
+ "version": "0.3.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",