From 8523afd512ccb8154e1422cd628612a54f6f2497 Mon Sep 17 00:00:00 2001
From: zuihou <244387066@qq.com>
Date: Fri, 10 Dec 2021 22:12:57 +0800
Subject: [PATCH] =?UTF-8?q?fix(BasicTree):=20=E4=BF=AE=E5=A4=8D=E5=8D=87?=
=?UTF-8?q?=E7=BA=A7antdv3.x=E5=90=8E=E4=BA=A7=E7=94=9F=E7=9A=84=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
1. BasicTree组件无法正确使用插槽的问题
2. 无法递归遍历的问题
Closes #1453
---
src/components/Tree/src/Tree.vue | 9 ++++-----
src/utils/helper/treeHelper.ts | 15 +++++++++++++++
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/components/Tree/src/Tree.vue b/src/components/Tree/src/Tree.vue
index 9c36373d..52fc3759 100644
--- a/src/components/Tree/src/Tree.vue
+++ b/src/components/Tree/src/Tree.vue
@@ -20,7 +20,7 @@
import { omit, get, difference, cloneDeep } from 'lodash-es';
import { isArray, isBoolean, isEmpty, isFunction } from '/@/utils/is';
import { extendSlots, getSlot } from '/@/utils/helper/tsxHelper';
- import { filter, treeToList } from '/@/utils/helper/treeHelper';
+ import { filter, treeToList, eachTree } from '/@/utils/helper/treeHelper';
import { useTree } from './useTree';
import { useContextMenu } from '/@/hooks/web/useContextMenu';
import { CreateContextOptions } from '/@/components/ContextMenu';
@@ -355,7 +355,7 @@
const treeData = computed(() => {
const data = cloneDeep(getTreeData.value);
- data.forEach((item) => {
+ eachTree(data, (item, _parent) => {
const searchText = searchState.searchText;
const { highlight } = unref(props);
const {
@@ -397,6 +397,7 @@
)}
);
+ return item;
});
return data;
});
@@ -426,9 +427,7 @@
)}
-
- {extendSlots(slots)}
-
+
diff --git a/src/utils/helper/treeHelper.ts b/src/utils/helper/treeHelper.ts
index 0535af7b..352008ff 100644
--- a/src/utils/helper/treeHelper.ts
+++ b/src/utils/helper/treeHelper.ts
@@ -187,3 +187,18 @@ export function treeMapEach(
};
}
}
+
+/**
+ * 递归遍历树结构
+ * @param treeDatas 树
+ * @param callBack 回调
+ * @param parentNode 父节点
+ */
+export function eachTree(treeDatas: any[], callBack: Fn, parentNode = {}) {
+ treeDatas.forEach((element) => {
+ const newNode = callBack(element, parentNode) || element;
+ if (element.children) {
+ eachTree(element.children, callBack, newNode);
+ }
+ });
+}