fix: 组件MsTree搜索不显示不符合的子模块
--bug=1040934 --user=吕梦园 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001040934
This commit is contained in:
parent
0ad5eb7e64
commit
c951ecc9fb
|
@ -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,18 +227,21 @@
|
||||||
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]) {
|
||||||
|
filteredChildren = search(item[props.fieldNames.children]);
|
||||||
|
}
|
||||||
|
// 当前节点符合关键字,或有符合关键字的子节点
|
||||||
|
if (titleMatches || filteredChildren.length > 0) {
|
||||||
result.push({
|
result.push({
|
||||||
...item,
|
...item,
|
||||||
expanded: true,
|
expanded: titleMatches || filteredChildren.length > 0,
|
||||||
[props.fieldNames.children]: filterData,
|
[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>) {
|
||||||
|
|
Loading…
Reference in New Issue