tree.d.ts 6.9 KB

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