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