gis-common 5.1.29 → 5.1.31

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.
@@ -2864,15 +2864,35 @@ const TreeUtil = {
2864
2864
  * @param data 树形结构的节点数组
2865
2865
  * @returns 展平后的一维节点数组
2866
2866
  */
2867
- flatTree(data) {
2867
+ flatTree(data, leaf) {
2868
2868
  let result = [];
2869
2869
  data.forEach((node) => {
2870
- result.push(node);
2870
+ if (leaf) {
2871
+ if (!node.children || node.children.length === 0) {
2872
+ result.push(node);
2873
+ }
2874
+ } else {
2875
+ result.push(node);
2876
+ }
2871
2877
  if (node.children && node.children.length > 0) {
2872
- result = result.concat(this.flatTree(node.children));
2878
+ result = result.concat(this.flatTree(node.children, leaf));
2873
2879
  }
2874
2880
  });
2875
2881
  return result;
2882
+ },
2883
+ /**
2884
+ * 遍历树形结构的节点,执行指定的回调函数
2885
+ *
2886
+ * @param data 树形结构的节点数组
2887
+ * @param callback 回调函数,参数为当前遍历到的节点
2888
+ */
2889
+ forEachTree(data, callback) {
2890
+ data.forEach((node) => {
2891
+ callback(node);
2892
+ if (node.children && node.children.length > 0) {
2893
+ this.forEachTree(node.children, callback);
2894
+ }
2895
+ });
2876
2896
  }
2877
2897
  };
2878
2898
  const UrlUtil = {
@@ -3472,7 +3492,7 @@ class DateTime extends Date {
3472
3492
  return fmt;
3473
3493
  }
3474
3494
  addDate(interval, number) {
3475
- const date = new Date(this);
3495
+ const date = new DateTime(this);
3476
3496
  switch (interval) {
3477
3497
  case "y":
3478
3498
  date.setFullYear(this.getFullYear() + number);