|
@@ -211,16 +211,32 @@
|
|
|
searchState.startSearch = false;
|
|
|
return;
|
|
|
}
|
|
|
+ const { filterFn, checkable, expandOnSearch, checkOnSearch } = unref(props);
|
|
|
searchState.startSearch = true;
|
|
|
- const { title: titleField } = unref(getReplaceFields);
|
|
|
+ const { title: titleField, key: keyField } = unref(getReplaceFields);
|
|
|
|
|
|
+ const searchKeys: string[] = [];
|
|
|
searchState.searchData = filter(
|
|
|
unref(treeDataRef),
|
|
|
(node) => {
|
|
|
- return node[titleField]?.includes(searchValue) ?? false;
|
|
|
+ const result = filterFn
|
|
|
+ ? filterFn(searchValue, node, unref(getReplaceFields))
|
|
|
+ : node[titleField]?.includes(searchValue) ?? false;
|
|
|
+ if (result) {
|
|
|
+ searchKeys.push(node[keyField]);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
},
|
|
|
unref(getReplaceFields),
|
|
|
);
|
|
|
+
|
|
|
+ if (expandOnSearch && searchKeys.length > 0) {
|
|
|
+ setExpandedKeys(searchKeys);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (checkOnSearch && checkable && searchKeys.length > 0) {
|
|
|
+ setCheckedKeys(searchKeys);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function handleClickNode(key: string, children: TreeItem[]) {
|
|
@@ -239,6 +255,7 @@
|
|
|
|
|
|
watchEffect(() => {
|
|
|
treeDataRef.value = props.treeData as TreeItem[];
|
|
|
+ handleSearch(unref(searchText));
|
|
|
});
|
|
|
|
|
|
onMounted(() => {
|