init
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user