tree.d.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 expand father node when a child node is expanded */
  68. autoExpandParent: boolean
  69. /** Array of keys of initially expanded nodes */
  70. defaultExpandedKeys: any[]
  71. /** Whether node is selectable */
  72. showCheckbox: boolean
  73. /** Whether checked state of a node not affects its father and child nodes when show-checkbox is true */
  74. checkStrictly: boolean
  75. /** Array of keys of initially checked nodes */
  76. defaultCheckedKeys: any[]
  77. /** This function will be executed on each node when use filter method. If return false, tree node will be hidden. */
  78. filterNodeMethod: FilterNodeMethod
  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. /** Function to be executed before dragging a node */
  86. allowDrag: AllowDragMethod
  87. /** Function to be executed before the dragging node is dropped */
  88. allowDrop: AllowDropMethod
  89. /**
  90. * Filter all tree nodes. Filtered nodes will be hidden
  91. *
  92. * @param value The value to be used as first parameter for `filter-node-method`
  93. */
  94. filter (value: any): void
  95. /**
  96. * Update the children of the node which specified by the key
  97. *
  98. * @param key the key of the node which children will be updated
  99. * @param data the children data
  100. */
  101. updateKeyChildren (key: any, data: TreeNode[]): void
  102. /**
  103. * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes
  104. *
  105. * @param subnodes If the `subnodes` is `true`, it only returns the currently selected array of sub-nodes
  106. */
  107. getCheckedNodes (leafOnly?: boolean): TreeNode[]
  108. /**
  109. * Set certain nodes to be checked. Only works when `node-key` is assigned
  110. *
  111. * @param nodes An array of nodes to be checked
  112. * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
  113. */
  114. setCheckedNodes (nodes: TreeNode[], leafOnly?: boolean): void
  115. /**
  116. * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes' keys
  117. *
  118. * @param subnodes If the `subnodes` is `true`, it only returns the currently selected array of sub-nodes
  119. */
  120. getCheckedKeys (leafOnly?: boolean): any[]
  121. /**
  122. * Set certain nodes to be checked. Only works when `node-key` is assigned
  123. *
  124. * @param keys An array of node's keys to be checked
  125. * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
  126. */
  127. setCheckedKeys (keys: any[], leafOnly?: boolean): void
  128. /**
  129. * Set node to be checked or not. Only works when `node-key` is assigned
  130. *
  131. * @param data Node's key or data to be checked
  132. * @param checked Indicating the node checked or not
  133. * @param deep Indicating whether to checked state deeply or not
  134. */
  135. setChecked (data: TreeNode | any, checked: boolean, deep: boolean): void
  136. /**
  137. * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes
  138. */
  139. getHalfCheckedNodes (): void
  140. /**
  141. * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes' keys
  142. */
  143. getHalfCheckedKeys (): void;
  144. /**
  145. * Return the highlight node's key (null if no node is highlighted)
  146. */
  147. getCurrentKey (): any
  148. /**
  149. * Set highlighted node by key, only works when node-key is assigned
  150. *
  151. * @param key The node's key to be highlighted
  152. */
  153. setCurrentKey (key: any): void
  154. /**
  155. * Return the highlight node (null if no node is highlighted)
  156. */
  157. getCurrentNode (): TreeNode
  158. /**
  159. * Set highlighted node, only works when node-key is assigned
  160. *
  161. * @param node The node to be highlighted
  162. */
  163. setCurrentNode (node: TreeNode): void
  164. /**
  165. * Get node by node key or node data
  166. *
  167. * @param by node key or node data
  168. */
  169. getNode (by: TreeNode | any): TreeNode
  170. /**
  171. * Remove node by key or node data or node instance
  172. *
  173. * @param by key or node data or node instance
  174. */
  175. remove (by: TreeNode | any): void
  176. /**
  177. * Append a child node to specified node
  178. *
  179. * @param childData the data of appended node
  180. * @param parent key or node data or node instance of the parent node
  181. */
  182. append (childData: TreeNode, parent: TreeNode | any): void
  183. /**
  184. * insert a node before specified node
  185. *
  186. * @param data the data of inserted node
  187. * @param ref key or node data or node instance of the reference node
  188. */
  189. insertBefore (data: TreeNode, ref: TreeNode | any): void
  190. /**
  191. * insert a node after specified node
  192. *
  193. * @param data the data of inserted node
  194. * @param ref key or node data or node instance of the reference node
  195. */
  196. insertAfter (data: TreeNode, ref: TreeNode | any): void
  197. }