fix: 组件MsTree搜索不显示不符合的子模块

--bug=1040934 --user=吕梦园
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001040934
This commit is contained in:
teukkk 2024-05-27 18:23:58 +08:00 committed by Craftsman
parent 0ad5eb7e64
commit c951ecc9fb
1 changed files with 20 additions and 13 deletions

View File

@ -92,7 +92,7 @@
<script setup lang="ts">
import { nextTick, onBeforeMount, Ref, ref, watch } from 'vue';
import { TreeInstance } from '@arco-design/web-vue';
import { debounce } from 'lodash-es';
import { cloneDeep, debounce } from 'lodash-es';
import MsTableMoreAction from '@/components/pure/ms-table-more-action/index.vue';
import type { ActionsItem } from '@/components/pure/ms-table-more-action/types';
@ -227,18 +227,21 @@
const search = (_data: MsTreeNodeData[]) => {
const result: MsTreeNodeData[] = [];
_data.forEach((item) => {
if (item[props.fieldNames.title].toLowerCase().includes(keyword.toLowerCase())) {
result.push({ ...item, expanded: true });
} else if (item[props.fieldNames.children]) {
const filterData = search(item[props.fieldNames.children]);
if (filterData.length) {
//
const titleMatches = item[props.fieldNames.title].toLowerCase().includes(keyword.toLowerCase());
//
let filteredChildren: MsTreeNodeData[] = [];
if (item[props.fieldNames.children]) {
filteredChildren = search(item[props.fieldNames.children]);
}
//
if (titleMatches || filteredChildren.length > 0) {
result.push({
...item,
expanded: true,
[props.fieldNames.children]: filterData,
expanded: titleMatches || filteredChildren.length > 0,
[props.fieldNames.children]: filteredChildren,
});
}
}
});
return result;
};
@ -356,7 +359,11 @@
* 处理树节点选中非复选框
*/
function select(_selectedKeys: Array<string | number>, _data: MsTreeSelectedData) {
emit('select', _selectedKeys, _data.selectedNodes[0]);
const selectNode: MsTreeNodeData = cloneDeep(_data.selectedNodes[0]);
loop(data.value, selectNode[props.fieldNames.key], (item) => {
selectNode.children = item.children;
});
emit('select', _selectedKeys, selectNode);
}
function checked(_checkedKeys: Array<string | number>) {