tree.d.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 leafOnly If the `leafOnly` is `true`, it only returns the currently selected array of sub-nodes
  108. * @param includeHalfChecked If the `includeHalfChecked` is `true`, the return value contains halfchecked nodes
  109. */
  110. getCheckedNodes (leafOnly?: boolean, includeHalfChecked?: boolean): TreeNode[]
  111. /**
  112. * Set certain nodes to be checked. Only works when `node-key` is assigned
  113. *
  114. * @param nodes An array of nodes to be checked
  115. * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
  116. */
  117. setCheckedNodes (nodes: TreeNode[], leafOnly?: boolean): void
  118. /**
  119. * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes' keys
  120. *
  121. * @param leafOnly If the `leafOnly` is `true`, it only returns the currently selected array of sub-nodes
  122. */
  123. getCheckedKeys (leafOnly?: boolean): any[]
  124. /**
  125. * Set certain nodes to be checked. Only works when `node-key` is assigned
  126. *
  127. * @param keys An array of node's keys to be checked
  128. * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
  129. */
  130. setCheckedKeys (keys: any[], leafOnly?: boolean): void
  131. /**
  132. * Set node to be checked or not. Only works when `node-key` is assigned
  133. *
  134. * @param data Node's key or data to be checked
  135. * @param checked Indicating the node checked or not
  136. * @param deep Indicating whether to checked state deeply or not
  137. */
  138. setChecked (data: TreeNode | any, checked: boolean, deep: boolean): void
  139. /**
  140. * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes
  141. */
  142. getHalfCheckedNodes (): void
  143. /**
  144. * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes' keys
  145. */
  146. getHalfCheckedKeys (): void;
  147. /**
  148. * Return the highlight node's key (null if no node is highlighted)
  149. */
  150. getCurrentKey (): any
  151. /**
  152. * Set highlighted node by key, only works when node-key is assigned
  153. *
  154. * @param key The node's key to be highlighted
  155. */
  156. setCurrentKey (key: any): void
  157. /**
  158. * Return the highlight node (null if no node is highlighted)
  159. */
  160. getCurrentNode (): TreeNode
  161. /**
  162. * Set highlighted node, only works when node-key is assigned
  163. *
  164. * @param node The node to be highlighted
  165. */
  166. setCurrentNode (node: TreeNode): void
  167. /**
  168. * Get node by node key or node data
  169. *
  170. * @param by node key or node data
  171. */
  172. getNode (by: TreeNode | any): TreeNode
  173. /**
  174. * Remove node by key or node data or node instance
  175. *
  176. * @param by key or node data or node instance
  177. */
  178. remove (by: TreeNode | any): void
  179. /**
  180. * Append a child node to specified node
  181. *
  182. * @param childData the data of appended node
  183. * @param parent key or node data or node instance of the parent node
  184. */
  185. append (childData: TreeNode, parent: TreeNode | any): void
  186. /**
  187. * insert a node before specified node
  188. *
  189. * @param data the data of inserted node
  190. * @param ref key or node data or node instance of the reference node
  191. */
  192. insertBefore (data: TreeNode, ref: TreeNode | any): void
  193. /**
  194. * insert a node after specified node
  195. *
  196. * @param data the data of inserted node
  197. * @param ref key or node data or node instance of the reference node
  198. */
  199. insertAfter (data: TreeNode, ref: TreeNode | any): void
  200. }