tree.d.ts 7.5 KB

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