提交 8523afd5 作者: zuihou

fix(BasicTree): 修复升级antdv3.x后产生的问题

1. BasicTree组件无法正确使用插槽的问题
2. 无法递归遍历的问题

Closes #1453
上级 8480454b
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
import { omit, get, difference, cloneDeep } from 'lodash-es'; import { omit, get, difference, cloneDeep } from 'lodash-es';
import { isArray, isBoolean, isEmpty, isFunction } from '/@/utils/is'; import { isArray, isBoolean, isEmpty, isFunction } from '/@/utils/is';
import { extendSlots, getSlot } from '/@/utils/helper/tsxHelper'; 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 { useTree } from './useTree';
import { useContextMenu } from '/@/hooks/web/useContextMenu'; import { useContextMenu } from '/@/hooks/web/useContextMenu';
import { CreateContextOptions } from '/@/components/ContextMenu'; import { CreateContextOptions } from '/@/components/ContextMenu';
...@@ -355,7 +355,7 @@ ...@@ -355,7 +355,7 @@
const treeData = computed(() => { const treeData = computed(() => {
const data = cloneDeep(getTreeData.value); const data = cloneDeep(getTreeData.value);
data.forEach((item) => { eachTree(data, (item, _parent) => {
const searchText = searchState.searchText; const searchText = searchState.searchText;
const { highlight } = unref(props); const { highlight } = unref(props);
const { const {
...@@ -397,6 +397,7 @@ ...@@ -397,6 +397,7 @@
)} )}
</span> </span>
); );
return item;
}); });
return data; return data;
}); });
...@@ -426,9 +427,7 @@ ...@@ -426,9 +427,7 @@
</TreeHeader> </TreeHeader>
)} )}
<ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}> <ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}>
<Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value}> <Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value} />
{extendSlots(slots)}
</Tree>
</ScrollContainer> </ScrollContainer>
<Empty v-show={unref(getNotFound)} image={Empty.PRESENTED_IMAGE_SIMPLE} class="!mt-4" /> <Empty v-show={unref(getNotFound)} image={Empty.PRESENTED_IMAGE_SIMPLE} class="!mt-4" />
</div> </div>
......
...@@ -187,3 +187,18 @@ export function treeMapEach( ...@@ -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);
}
});
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论