Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(BasicTree): 组件外部获取treeData不必通过treeDataRef.value或许更好些 #3353

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/components/Tree/src/BasicTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@
return omit(propsData, 'treeData', 'class') as TreeProps;
});

const getTreeData = computed((): TreeItem[] =>
const getTreeSearchData = computed((): TreeItem[] =>
searchState.startSearch ? searchState.searchData : unref(treeDataRef),
);

const getNotFound = computed((): boolean => {
return !getTreeData.value || getTreeData.value.length === 0;
return !getTreeSearchData.value || getTreeSearchData.value.length === 0;
});

const {
Expand Down Expand Up @@ -158,6 +158,10 @@
createContextMenu(contextMenuOptions);
}

function getTreeData() {
return unref(treeDataRef);
}

function setExpandedKeys(keys: KeyType[]) {
state.expandedKeys = keys;
}
Expand Down Expand Up @@ -320,7 +324,7 @@
});

const instance: TreeActionType = {
getTreeData: () => treeDataRef,
getTreeData,
setExpandedKeys,
getExpandedKeys,
setSelectedKeys,
Expand Down Expand Up @@ -367,7 +371,7 @@
}

const treeData = computed(() => {
const data = cloneDeep(getTreeData.value);
const data = cloneDeep(getTreeSearchData.value);
eachTree(data, (item, _parent) => {
const searchText = searchState.searchText;
const { highlight } = unref(props);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Tree/src/types/tree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ExtractPropTypes, Ref } from 'vue';
import type { ExtractPropTypes } from 'vue';
import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree';

import { buildProps } from '@/utils/props';
Expand Down Expand Up @@ -171,7 +171,7 @@ export interface InsertNodeParams {
}

export interface TreeActionType {
getTreeData: () => Ref<TreeDataItem[]>;
getTreeData: () => TreeDataItem[];
checkAll: (checkAll: boolean) => void;
expandAll: (expandAll: boolean) => void;
setExpandedKeys: (keys: KeyType[]) => void;
Expand Down
3 changes: 1 addition & 2 deletions src/views/demo/tree/ActionTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
}

function handleGetTreeData() {
const treeDataRef = getTree().getTreeData();
createMessage.success(JSON.stringify(treeDataRef.value));
createMessage.success(JSON.stringify(getTree().getTreeData()));
}
</script>