qidian-shared 1.0.18 → 1.0.20

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.
@@ -7986,6 +7986,39 @@ function easyDownload(res, name) {
7986
7986
  }, 1e3);
7987
7987
  }
7988
7988
  }
7989
+ function buildTree(data, options = {}) {
7990
+ const { id = "id", parentId = "parentId", children = "children" } = options;
7991
+ const childrenListMap = {};
7992
+ const nodeIds = {};
7993
+ const tree = [];
7994
+ for (const d of data) {
7995
+ const pid = d[parentId];
7996
+ if (!childrenListMap[pid]) {
7997
+ childrenListMap[pid] = [];
7998
+ }
7999
+ nodeIds[d[id]] = d;
8000
+ childrenListMap[pid].push(d);
8001
+ }
8002
+ for (const d of data) {
8003
+ const pid = d[parentId];
8004
+ if (!nodeIds[pid]) {
8005
+ tree.push(d);
8006
+ }
8007
+ }
8008
+ for (const t of tree) {
8009
+ adaptToChildrenList(t);
8010
+ }
8011
+ function adaptToChildrenList(o) {
8012
+ const childNodes = childrenListMap[o[id]];
8013
+ if (childNodes) {
8014
+ o[children] = childNodes;
8015
+ for (const c of childNodes) {
8016
+ adaptToChildrenList(c);
8017
+ }
8018
+ }
8019
+ }
8020
+ return tree;
8021
+ }
7989
8022
  var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
7990
8023
  function int2char(n) {
7991
8024
  return BI_RM.charAt(n);
@@ -12380,6 +12413,7 @@ function useTimer(type = "timeout") {
12380
12413
  };
12381
12414
  }
12382
12415
  exports.MD5 = MD5;
12416
+ exports.buildTree = buildTree;
12383
12417
  exports.createEnum = createEnum;
12384
12418
  exports.decrypt = decrypt;
12385
12419
  exports.decryptBase64 = decryptBase64;