tree.d.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import { CreateElement, VNode } from 'vue';
  2. import { ElementUIComponent } from './component';
  3. export interface TreeData {
  4. id?: any;
  5. label?: string;
  6. isLeaf?: boolean;
  7. children?: TreeData[];
  8. }
  9. export interface TreeNode<K, D> {
  10. checked: boolean;
  11. childNodes: TreeNode<K, D>[];
  12. data: D;
  13. expanded: boolean;
  14. id: number;
  15. indeterminate: boolean;
  16. isLeaf: boolean;
  17. level: number;
  18. loaded: boolean;
  19. loading: boolean;
  20. parent: TreeNode<K, D> | null;
  21. store: any;
  22. visible: boolean;
  23. disabled: boolean;
  24. icon: string;
  25. key: K;
  26. nextSibling: TreeNode<K, D> | null;
  27. previousSibling: TreeNode<K, D> | null;
  28. }
  29. /** incomplete, you can convert to any to use other properties */
  30. export interface TreeStore<K, D> {
  31. _getAllNodes: () => TreeNode<K, D>[];
  32. }
  33. /** Tree Component */
  34. export declare class ElTree<K = any, D = TreeData> extends ElementUIComponent {
  35. /** TreeStore */
  36. store: TreeStore<K, D>;
  37. /** Tree data */
  38. data: D[];
  39. /** Text displayed when data is void */
  40. emptyText: string;
  41. /** Unique identity key name for nodes, its value should be unique across the whole tree */
  42. nodeKey: string;
  43. /** Configuration options, see the following table */
  44. props: object;
  45. /** Method for loading subtree data */
  46. load: (data: D, resolve: Function) => void;
  47. /**
  48. * Render function for a specific node
  49. *
  50. * @param h The render function
  51. */
  52. renderContent: (h: CreateElement, context: { node: TreeNode<K, D>; data: D; store: TreeStore<K, D> }) => VNode;
  53. /** Whether current node is highlighted */
  54. highlightCurrent: boolean;
  55. /** Whether to expand all nodes by default */
  56. defaultExpandAll: boolean;
  57. /** Whether to expand or collapse node when clicking on the node. If false, then expand or collapse node only when clicking on the arrow icon. */
  58. expandOnClickNode: boolean;
  59. /** Whether to check or uncheck node when clicking on the node, if false, the node can only be checked or unchecked by clicking on the checkbox. */
  60. checkOnClickNode: boolean;
  61. /** Whether to expand father node when a child node is expanded */
  62. autoExpandParent: boolean;
  63. /** Array of keys of initially expanded nodes */
  64. defaultExpandedKeys: K[];
  65. /** Whether node is selectable */
  66. showCheckbox: boolean;
  67. /** Whether checked state of a node not affects its father and child nodes when show-checkbox is true */
  68. checkStrictly: boolean;
  69. /** Array of keys of initially checked nodes */
  70. defaultCheckedKeys: K[];
  71. /**
  72. * This function will be executed on each node when use filter method. If return false, tree node will be hidden.
  73. *
  74. * @param value The query string
  75. * @param data The original data object
  76. * @param node Tree node
  77. */
  78. filterNodeMethod: (value: string, data: D, node: TreeNode<K, D>) => boolean;
  79. /** Whether only one node among the same level can be expanded at one time */
  80. accordion: boolean;
  81. /** Horizontal indentation of nodes in adjacent levels in pixels */
  82. indent: number;
  83. /** Whether enable tree nodes drag and drop */
  84. draggable: boolean;
  85. /**
  86. * Function to be executed before dragging a node
  87. *
  88. * @param node The node to be dragged
  89. */
  90. allowDrag: (node: TreeNode<K, D>) => boolean;
  91. /**
  92. * Function to be executed before the dragging node is dropped
  93. *
  94. * @param draggingNode The dragging node
  95. * @param dropNode The target node
  96. * @param type Drop type
  97. */
  98. allowDrop: (draggingNode: TreeNode<K, D>, dropNode: TreeNode<K, D>, type: 'prev' | 'inner' | 'next') => boolean;
  99. /**
  100. * Filter all tree nodes. Filtered nodes will be hidden
  101. *
  102. * @param value The value to be used as first parameter for `filter-node-method`
  103. */
  104. filter(value: any): void;
  105. /**
  106. * Update the children of the node which specified by the key
  107. *
  108. * @param key the key of the node which children will be updated
  109. * @param data the children data
  110. */
  111. updateKeyChildren(key: K, data: D[]): void;
  112. /**
  113. * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes
  114. *
  115. * @param leafOnly If the `leafOnly` is `true`, it only returns the currently selected array of sub-nodes
  116. * @param includeHalfChecked If the `includeHalfChecked` is `true`, the return value contains halfchecked nodes
  117. */
  118. getCheckedNodes(leafOnly?: boolean, includeHalfChecked?: boolean): D[];
  119. /**
  120. * Set certain nodes to be checked. Only works when `node-key` is assigned
  121. *
  122. * @param nodes An array of nodes to be checked
  123. * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
  124. */
  125. setCheckedNodes(data: D[], leafOnly?: boolean): void;
  126. /**
  127. * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes' keys
  128. *
  129. * @param leafOnly If the `leafOnly` is `true`, it only returns the currently selected array of sub-nodes
  130. */
  131. getCheckedKeys(leafOnly?: boolean): K[];
  132. /**
  133. * Set certain nodes to be checked. Only works when `node-key` is assigned
  134. *
  135. * @param keys An array of node's keys to be checked
  136. * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
  137. */
  138. setCheckedKeys(keys: K[], leafOnly?: boolean): void;
  139. /**
  140. * Set node to be checked or not. Only works when `node-key` is assigned
  141. *
  142. * @param data Node's key or data to be checked
  143. * @param checked Indicating the node checked or not
  144. * @param deep Indicating whether to checked state deeply or not
  145. */
  146. setChecked(data: D | K, checked: boolean, deep: boolean): void;
  147. /**
  148. * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes
  149. */
  150. getHalfCheckedNodes(): D[];
  151. /**
  152. * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes' keys
  153. */
  154. getHalfCheckedKeys(): K[];
  155. /**
  156. * Return the highlight node's key (null if no node is highlighted)
  157. */
  158. getCurrentKey(): K;
  159. /**
  160. * Set highlighted node by key, only works when node-key is assigned
  161. *
  162. * @param key The node's key to be highlighted
  163. */
  164. setCurrentKey(key: K): void;
  165. /**
  166. * Return the highlight node (null if no node is highlighted)
  167. */
  168. getCurrentNode(): D;
  169. /**
  170. * Set highlighted node, only works when node-key is assigned
  171. *
  172. * @param node The node to be highlighted
  173. */
  174. setCurrentNode(data: D): void;
  175. /**
  176. * Get node by node key or node data
  177. *
  178. * @param by node key or node data
  179. */
  180. getNode(by: D | K): D;
  181. /**
  182. * Remove node by key or node data or node instance
  183. *
  184. * @param by key or node data or node instance
  185. */
  186. remove(by: D | K): void;
  187. /**
  188. * Append a child node to specified node
  189. *
  190. * @param childData the data of appended node
  191. * @param parent key or node data or node instance of the parent node
  192. */
  193. append(childData: D, parent: D | K): void;
  194. /**
  195. * insert a node before specified node
  196. *
  197. * @param data the data of inserted node
  198. * @param ref key or node data or node instance of the reference node
  199. */
  200. insertBefore(data: D, ref: D | K): void;
  201. /**
  202. * insert a node after specified node
  203. *
  204. * @param data the data of inserted node
  205. * @param ref key or node data or node instance of the reference node
  206. */
  207. insertAfter(data: D, ref: D | K): void;
  208. }