tree.d.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. /** Tree Component */
  30. export declare class ElTree extends ElementUIComponent {
  31. /** Tree data */
  32. data: TreeNode[]
  33. /** Text displayed when data is void */
  34. emptyText: string
  35. /** Unique identity key name for nodes, its value should be unique across the whole tree */
  36. nodeKey: string
  37. /** Configuration options, see the following table */
  38. props: object
  39. /** Method for loading subtree data */
  40. load: (node: TreeNode, resolve: Function) => void
  41. /** Render function for tree node */
  42. renderContent: RenderContent
  43. /** Whether current node is highlighted */
  44. highlightCurrent: boolean
  45. /** Whether to expand all nodes by default */
  46. defaultExpandAll: boolean
  47. /** 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. */
  48. expandOnClickNode: boolean
  49. /** Whether to expand father node when a child node is expanded */
  50. autoExpandParent: boolean
  51. /** Array of keys of initially expanded nodes */
  52. defaultExpandedKeys: any[]
  53. /** Whether node is selectable */
  54. showCheckbox: boolean
  55. /** Whether checked state of a node not affects its father and child nodes when show-checkbox is true */
  56. checkStrictly: boolean
  57. /** Array of keys of initially checked nodes */
  58. defaultCheckedKeys: any[]
  59. /** This function will be executed on each node when use filter method. If return false, tree node will be hidden. */
  60. filterNodeMethod: FilterNodeMethod
  61. /** Whether only one node among the same level can be expanded at one time */
  62. accordion: boolean
  63. /** Horizontal indentation of nodes in adjacent levels in pixels */
  64. indent: number
  65. /**
  66. * Filter all tree nodes. Filtered nodes will be hidden
  67. *
  68. * @param value The value to be used as first parameter for `filter-node-method`
  69. */
  70. filter (value: any): void
  71. /**
  72. * Update the children of the node which specified by the key
  73. *
  74. * @param key the key of the node which children will be updated
  75. * @param data the children data
  76. */
  77. updateKeyChildren (key: any, data: TreeNode[]): void
  78. /**
  79. * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes
  80. *
  81. * @param subnodes If the `subnodes` is `true`, it only returns the currently selected array of sub-nodes
  82. */
  83. getCheckedNodes (leafOnly?: boolean): TreeNode[]
  84. /**
  85. * Set certain nodes to be checked. Only works when `node-key` is assigned
  86. *
  87. * @param nodes An array of nodes to be checked
  88. * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
  89. */
  90. setCheckedNodes (nodes: TreeNode[], leafOnly?: boolean): void
  91. /**
  92. * If the node can be selected (`show-checkbox` is `true`), it returns the currently selected array of nodes' keys
  93. *
  94. * @param subnodes If the `subnodes` is `true`, it only returns the currently selected array of sub-nodes
  95. */
  96. getCheckedKeys (leafOnly?: boolean): any[]
  97. /**
  98. * Set certain nodes to be checked. Only works when `node-key` is assigned
  99. *
  100. * @param keys An array of node's keys to be checked
  101. * @param leafOnly If the parameter is true, it only returns the currently selected array of sub-nodes
  102. */
  103. setCheckedKeys (keys: any[], leafOnly?: boolean): void
  104. /**
  105. * Set node to be checked or not. Only works when `node-key` is assigned
  106. *
  107. * @param data Node's key or data to be checked
  108. * @param checked Indicating the node checked or not
  109. * @param deep Indicating whether to checked state deeply or not
  110. */
  111. setChecked (data: TreeNode | any, checked: boolean, deep: boolean): void
  112. /**
  113. * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes
  114. */
  115. getHalfCheckedNodes (): void
  116. /**
  117. * If the node can be selected (`show-checkbox` is `true`), it returns the currently half selected array of nodes' keys
  118. */
  119. getHalfCheckedKeys (): void;
  120. /**
  121. * Return the highlight node's key (null if no node is highlighted)
  122. */
  123. getCurrentKey (): any
  124. /**
  125. * Set highlighted node by key, only works when node-key is assigned
  126. *
  127. * @param key The node's key to be highlighted
  128. */
  129. setCurrentKey (key: any): void
  130. /**
  131. * Return the highlight node (null if no node is highlighted)
  132. */
  133. getCurrentNode (): TreeNode
  134. /**
  135. * Set highlighted node, only works when node-key is assigned
  136. *
  137. * @param node The node to be highlighted
  138. */
  139. setCurrentNode (node: TreeNode): void
  140. /**
  141. * Get node by node key or node data
  142. *
  143. * @param by node key or node data
  144. */
  145. getNode (by: TreeNode | any): TreeNode
  146. /**
  147. * Remove node by key or node data or node instance
  148. *
  149. * @param by key or node data or node instance
  150. */
  151. remove (by: TreeNode | any): void
  152. /**
  153. * Append a child node to specified node
  154. *
  155. * @param childData the data of appended node
  156. * @param parent key or node data or node instance of the parent node
  157. */
  158. append (childData: TreeNode, parent: TreeNode | any): void
  159. /**
  160. * insert a node before specified node
  161. *
  162. * @param data the data of inserted node
  163. * @param ref key or node data or node instance of the reference node
  164. */
  165. insertBefore (data: TreeNode, ref: TreeNode | any): void
  166. /**
  167. * insert a node after specified node
  168. *
  169. * @param data the data of inserted node
  170. * @param ref key or node data or node instance of the reference node
  171. */
  172. insertAfter (data: TreeNode, ref: TreeNode | any): void
  173. }