qmwts 1.1.47 → 1.1.48

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.
@@ -25,18 +25,20 @@ exports.default = {
25
25
  if (parentKey === void 0) { parentKey = 'parentId'; }
26
26
  if (childrenKey === void 0) { childrenKey = 'children'; }
27
27
  var map = new Map(); // 先根据每项的parentId将该项放入Map
28
+ var ids = []; // 记录所有的id,parentId不在这个集合内则说明是最上级
28
29
  for (var i = array.length - 1; i >= 0; i--) {
29
- var _a = array, _b = i, e = _a[_b], _c = e, _d = parentKey, pid = _c[_d];
30
+ var _a = array, _b = i, e = _a[_b], _c = e, _d = idKey, id = _c[_d], _e = parentKey, pid = _c[_e];
30
31
  var children = map.get(pid) || [];
31
32
  children.unshift(__assign({}, e));
32
33
  map.set(pid, children);
34
+ ids.push(id);
33
35
  }
34
36
  var o = [];
35
37
  var values = Array.from(map.values()).flat();
36
38
  for (var i = values.length - 1; i >= 0; i--) {
37
- var _e = values, _f = i, e = _e[_f], _g = e, _h = idKey, id = _g[_h], _j = parentKey, pid = _g[_j];
39
+ var _f = values, _g = i, e = _f[_g], _h = e, _j = idKey, id = _h[_j], _k = parentKey, pid = _h[_k];
38
40
  e[childrenKey] = map.get(id); // 赋值children
39
- if (!pid) // 只返回最上级
41
+ if (!ids.includes(pid)) // 只返回最上级
40
42
  o.unshift(e);
41
43
  }
42
44
  return o;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmwts",
3
- "version": "1.1.47",
3
+ "version": "1.1.48",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",