layui/.svn/pristine/92/920dd37ef1acb3c5e0e826e5991fd40c45521d92.svn-base
2022-12-09 16:41:41 +08:00

41 lines
892 B
Plaintext

import { TreeEmits, TreeProps } from "./tree.type";
import { computed, ComputedRef, watch } from "vue";
import { Tree, TreeData } from "./tree";
export declare type UseTree = (
props: TreeProps,
emit: TreeEmits
) => {
tree: Tree;
nodeList: ComputedRef<TreeData[]>;
};
export const useTree: UseTree = (props: TreeProps, emit: TreeEmits) => {
const tree = new Tree(
{
nodeMap: new Map(),
originMap: new Map(),
replaceFields: {
id: "id",
title: "title",
children: "children",
},
showCheckbox: props.showCheckbox ?? false,
checkedKeys: props.checkedKeys ?? [],
expandKeys: props.expandKeys ?? [],
checkStrictly: props.checkStrictly ?? false,
},
props.data
);
const nodeList = computed(() => {
const nodes = tree.getData();
return nodes;
});
return {
tree,
nodeList,
};
};