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

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

Closes #1453
This commit is contained in:
zuihou 2021-12-10 22:12:57 +08:00
parent 8480454b73
commit 8523afd512
2 changed files with 19 additions and 5 deletions

View File

@ -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 @@
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 @@
)} )}
</span> </span>
); );
return item;
}); });
return data; return data;
}); });
@ -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>

View File

@ -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);
}
});
}