wujingjing
2024-04-22 f106e4dffb8279cb90726e83e7edd631f4c77699
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import type { ElTree } from 'element-plus';
import type { Ref } from 'vue';
import { ref, watch } from 'vue';
import { debounce } from '/@/utils/util';
interface Tree {
    [key: string]: any;
}
/**
 * 过滤 el-tree 节点
 * @param treeRef
 * @param label
 */
export const useFilterTree = (treeRef: Ref<InstanceType<typeof ElTree>>, label = 'Name') => {
    const filterText = ref('');
 
    watch(
        filterText,
        debounce(function (...args) {
            treeRef.value!.filter(args[0]);
        })
    );
 
    const filterNode = (value: string, data: Tree) => {
        if (!value) return true;
        return data[label].includes(value.trim().toLowerCase());
    };
 
    return {
        filterText,
        filterNode,
    };
};