Commit 8523afd512ccb8154e1422cd628612a54f6f2497
1 parent
8480454b
fix(BasicTree): 修复升级antdv3.x后产生的问题
1. BasicTree组件无法正确使用插槽的问题 2. 无法递归遍历的问题 Closes #1453
Showing
2 changed files
with
19 additions
and
5 deletions
src/components/Tree/src/Tree.vue
@@ -20,7 +20,7 @@ | @@ -20,7 +20,7 @@ | ||
20 | import { omit, get, difference, cloneDeep } from 'lodash-es'; | 20 | import { omit, get, difference, cloneDeep } from 'lodash-es'; |
21 | import { isArray, isBoolean, isEmpty, isFunction } from '/@/utils/is'; | 21 | import { isArray, isBoolean, isEmpty, isFunction } from '/@/utils/is'; |
22 | import { extendSlots, getSlot } from '/@/utils/helper/tsxHelper'; | 22 | import { extendSlots, getSlot } from '/@/utils/helper/tsxHelper'; |
23 | - import { filter, treeToList } from '/@/utils/helper/treeHelper'; | 23 | + import { filter, treeToList, eachTree } from '/@/utils/helper/treeHelper'; |
24 | import { useTree } from './useTree'; | 24 | import { useTree } from './useTree'; |
25 | import { useContextMenu } from '/@/hooks/web/useContextMenu'; | 25 | import { useContextMenu } from '/@/hooks/web/useContextMenu'; |
26 | import { CreateContextOptions } from '/@/components/ContextMenu'; | 26 | import { CreateContextOptions } from '/@/components/ContextMenu'; |
@@ -355,7 +355,7 @@ | @@ -355,7 +355,7 @@ | ||
355 | 355 | ||
356 | const treeData = computed(() => { | 356 | const treeData = computed(() => { |
357 | const data = cloneDeep(getTreeData.value); | 357 | const data = cloneDeep(getTreeData.value); |
358 | - data.forEach((item) => { | 358 | + eachTree(data, (item, _parent) => { |
359 | const searchText = searchState.searchText; | 359 | const searchText = searchState.searchText; |
360 | const { highlight } = unref(props); | 360 | const { highlight } = unref(props); |
361 | const { | 361 | const { |
@@ -397,6 +397,7 @@ | @@ -397,6 +397,7 @@ | ||
397 | )} | 397 | )} |
398 | </span> | 398 | </span> |
399 | ); | 399 | ); |
400 | + return item; | ||
400 | }); | 401 | }); |
401 | return data; | 402 | return data; |
402 | }); | 403 | }); |
@@ -426,9 +427,7 @@ | @@ -426,9 +427,7 @@ | ||
426 | </TreeHeader> | 427 | </TreeHeader> |
427 | )} | 428 | )} |
428 | <ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}> | 429 | <ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}> |
429 | - <Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value}> | ||
430 | - {extendSlots(slots)} | ||
431 | - </Tree> | 430 | + <Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value} /> |
432 | </ScrollContainer> | 431 | </ScrollContainer> |
433 | <Empty v-show={unref(getNotFound)} image={Empty.PRESENTED_IMAGE_SIMPLE} class="!mt-4" /> | 432 | <Empty v-show={unref(getNotFound)} image={Empty.PRESENTED_IMAGE_SIMPLE} class="!mt-4" /> |
434 | </div> | 433 | </div> |
src/utils/helper/treeHelper.ts
@@ -187,3 +187,18 @@ export function treeMapEach( | @@ -187,3 +187,18 @@ export function treeMapEach( | ||
187 | }; | 187 | }; |
188 | } | 188 | } |
189 | } | 189 | } |
190 | + | ||
191 | +/** | ||
192 | + * 递归遍历树结构 | ||
193 | + * @param treeDatas 树 | ||
194 | + * @param callBack 回调 | ||
195 | + * @param parentNode 父节点 | ||
196 | + */ | ||
197 | +export function eachTree(treeDatas: any[], callBack: Fn, parentNode = {}) { | ||
198 | + treeDatas.forEach((element) => { | ||
199 | + const newNode = callBack(element, parentNode) || element; | ||
200 | + if (element.children) { | ||
201 | + eachTree(element.children, callBack, newNode); | ||
202 | + } | ||
203 | + }); | ||
204 | +} |