tree.d.ts 7.4 KB

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