index.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. import { ComponentPublicInstance } from 'vue';
  2. declare const CHECK_STATUS_MAP: {
  3. readonly checked: "checked";
  4. readonly unchecked: "unchecked";
  5. readonly indeterminate: "indeterminate";
  6. };
  7. type TreeKey = string | number;
  8. type CheckStatus = typeof CHECK_STATUS_MAP[keyof typeof CHECK_STATUS_MAP];
  9. type TreeModelValue = TreeKey | TreeKey[] | null;
  10. interface TreeDataItem {
  11. [key: string]: any;
  12. }
  13. interface TreeNode {
  14. id: TreeKey;
  15. label: string;
  16. append: string;
  17. icon: string;
  18. path: string[];
  19. source: TreeDataItem;
  20. parentId?: TreeKey;
  21. parentIds: TreeKey[];
  22. parents: TreeDataItem[];
  23. level: number;
  24. disabled: boolean;
  25. checked: CheckStatus;
  26. expanded: boolean;
  27. visible: boolean;
  28. isLeaf: boolean;
  29. loaded: boolean;
  30. loading: boolean;
  31. loadError: unknown;
  32. }
  33. interface TreeProps {
  34. id: string;
  35. label: string;
  36. children: string;
  37. disabled?: string;
  38. leaf?: string;
  39. append?: string;
  40. icon?: string;
  41. }
  42. interface TreeCheckChangePayload {
  43. value: TreeModelValue;
  44. keys: TreeKey[];
  45. nodes: TreeNode[];
  46. /** Current half-checked keys in linked multiple-selection mode. */
  47. halfCheckedKeys: TreeKey[];
  48. /** Current half-checked nodes in linked multiple-selection mode. */
  49. halfCheckedNodes: TreeNode[];
  50. node: TreeNode;
  51. }
  52. interface TreeLoadPayload {
  53. node: TreeNode;
  54. children: TreeDataItem[];
  55. }
  56. interface TreeLoadErrorPayload {
  57. node: TreeNode;
  58. error: unknown;
  59. }
  60. interface TreeScrollToOptions {
  61. /** Expand ancestors before locating the node. */
  62. expandParents?: boolean;
  63. }
  64. interface TreeExpandPayload {
  65. expanded: boolean;
  66. node: TreeNode;
  67. }
  68. interface TreeNodeClickPayload {
  69. id: TreeKey;
  70. node: TreeNode;
  71. path: TreeNode[];
  72. }
  73. interface TreeFilterPayload {
  74. value: string;
  75. /** Visible keys after filtering, including direct matches, ancestors and descendants. */
  76. keys: TreeKey[];
  77. /** Visible nodes after filtering, including direct matches, ancestors and descendants. */
  78. nodes: TreeNode[];
  79. /** Keys directly matched by the built-in or custom filter rule. */
  80. matchedKeys: TreeKey[];
  81. /** Nodes directly matched by the built-in or custom filter rule. */
  82. matchedNodes: TreeNode[];
  83. }
  84. interface TreeSlotProps {
  85. node: TreeNode;
  86. data: TreeDataItem;
  87. path: TreeNode[];
  88. }
  89. interface TreeEmptySlotProps {
  90. filterValue: string;
  91. }
  92. interface UniTreeViewSlots {
  93. default?: (props: TreeSlotProps) => unknown;
  94. label?: (props: TreeSlotProps) => unknown;
  95. icon?: (props: TreeSlotProps) => unknown;
  96. append?: (props: TreeSlotProps) => unknown;
  97. empty?: (props: TreeEmptySlotProps) => unknown;
  98. "empty-filter"?: (props: TreeEmptySlotProps) => unknown;
  99. }
  100. interface UniTreeViewProps {
  101. /** Current selected value. Single select uses one key, multiple select uses an array. */
  102. modelValue?: TreeModelValue;
  103. /** Tree data. */
  104. data?: TreeDataItem[];
  105. /** Filter keyword. Matching nodes and their related branch stay visible. */
  106. filterValue?: string;
  107. /** Custom node matcher used when filterValue is not empty. */
  108. filterMethod?: (value: string, node: TreeNode) => boolean;
  109. /** Highlight literal filter keyword matches in the built-in label. */
  110. highlightFilter?: boolean;
  111. /** Default checked keys for uncontrolled initial state. */
  112. defaultCheckedKeys?: TreeKey | TreeKey[] | null;
  113. /** Field mapping for id, label, children, disabled, leaf, append and icon. */
  114. treeProps?: Partial<TreeProps>;
  115. /** Theme color for active checkbox/radio. */
  116. themeColor?: string;
  117. /** Whether to enable and show the selection control. */
  118. selectable?: boolean;
  119. /** Whether to show radio UI in single-select mode. */
  120. showRadioIcon?: boolean;
  121. /** Whether to support multiple selection. */
  122. multiple?: boolean;
  123. /** Whether clicking a node row changes its selection state. */
  124. checkOnClickNode?: boolean;
  125. /** Whether clicking a leaf node row changes its selection state. */
  126. checkOnClickLeaf?: boolean;
  127. /** Whether clicking a node row expands or collapses it. */
  128. expandOnClickNode?: boolean;
  129. /** Whether expanding a node collapses its expanded siblings. */
  130. accordion?: boolean;
  131. /** Whether parent and child checked states are independent. */
  132. checkStrictly?: boolean;
  133. /** Single-select mode can only select leaf nodes. Ignored when `multiple` is true. */
  134. onlyRadioLeaf?: boolean;
  135. /** Whether all nodes are expanded initially. */
  136. defaultExpandAll?: boolean;
  137. /** Default expanded node keys. */
  138. defaultExpandedKeys?: TreeKey[];
  139. /** Whether default expanded keys also expand all their ancestors. */
  140. defaultExpandParent?: boolean;
  141. /** Expand ancestors of checked nodes initially. */
  142. expandChecked?: boolean;
  143. /** Preserve runtime expanded state when tree data is rebuilt. */
  144. cacheExpandedKeys?: boolean;
  145. /** Lazy load mode. Nodes can be expanded before children exist. */
  146. loadMode?: boolean;
  147. /** Lazy load function. */
  148. loadApi?: (node: TreeNode) => TreeDataItem[] | Promise<TreeDataItem[]>;
  149. /** Custom leaf resolver. */
  150. isLeafFn?: (item: TreeDataItem, node: TreeNode) => boolean;
  151. /** Load once on first expand even when static children exist. */
  152. alwaysFirstLoad?: boolean;
  153. /** Whether disabled nodes can participate in selection state changes. */
  154. checkedDisabled?: boolean;
  155. /** Whether checked disabled nodes are included in returned keys/nodes. */
  156. packDisabledKey?: boolean;
  157. /** @deprecated Use `packDisabledKey` instead. */
  158. packDisabledkey?: boolean;
  159. /** Custom class name added to every node row. */
  160. nodeClass?: string;
  161. /** Tree item indent in rpx. */
  162. indent?: number;
  163. /** Selection control placement. */
  164. selectionPlacement?: "left" | "right";
  165. /** Empty text shown when data is empty. */
  166. emptyText?: string;
  167. /** Show label path under the node label. */
  168. showPath?: boolean;
  169. /** Separator used by the built-in path display. */
  170. pathSeparator?: string;
  171. /** Enable fixed-height virtual rendering for very large visible node lists. */
  172. virtual?: boolean;
  173. /** Row height in px when virtual rendering is enabled. */
  174. virtualItemHeight?: number;
  175. /** Scroll container height in px when virtual rendering is enabled. */
  176. virtualHeight?: number;
  177. /** Extra rows rendered before and after the viewport in virtual mode. */
  178. virtualOverscan?: number;
  179. }
  180. interface UniTreeViewExposed {
  181. setCheckedKeys: (keys: TreeKey | TreeKey[], checked?: boolean) => TreeModelValue;
  182. getCheckedKeys: () => TreeKey[];
  183. getHalfCheckedKeys: () => TreeKey[];
  184. getUncheckedKeys: () => TreeKey[];
  185. getCheckedNodes: () => TreeNode[];
  186. getHalfCheckedNodes: () => TreeNode[];
  187. getUncheckedNodes: () => TreeNode[];
  188. setExpandedKeys: (keys: TreeKey[] | "all", expanded?: boolean) => void;
  189. getExpandedKeys: () => TreeKey[];
  190. getUnexpandedKeys: () => TreeKey[];
  191. getVisibleKeys: () => TreeKey[];
  192. getMatchedKeys: () => TreeKey[];
  193. getExpandedNodes: () => TreeNode[];
  194. getUnexpandedNodes: () => TreeNode[];
  195. getVisibleNodes: () => TreeNode[];
  196. getMatchedNodes: () => TreeNode[];
  197. getNode: (key: TreeKey) => TreeNode | undefined;
  198. getNodePath: (keyOrNode: TreeKey | TreeNode) => TreeNode[];
  199. expandAll: () => void;
  200. collapseAll: () => void;
  201. loadNode: (node: TreeNode) => Promise<TreeDataItem[]>;
  202. retryLoad: (keyOrNode: TreeKey | TreeNode) => Promise<TreeDataItem[]>;
  203. scrollToKey: (key: TreeKey, options?: TreeScrollToOptions) => Promise<boolean>;
  204. }
  205. /**
  206. * 事件表使用 Vue 3.3+ 的「具名元组」形态,且必须是 type 别名而非 interface:
  207. * `defineEmits<T>()` 的约束是 `Record<string, any[]>`,interface 没有隐式索引签名,无法满足。
  208. */
  209. type UniTreeViewEmits = {
  210. "update:modelValue": [value: TreeModelValue];
  211. "check-change": [payload: TreeCheckChangePayload];
  212. "expand-change": [payload: TreeExpandPayload];
  213. "load": [payload: TreeLoadPayload];
  214. "load-error": [payload: TreeLoadErrorPayload];
  215. "node-click": [payload: TreeNodeClickPayload];
  216. "filter-change": [payload: TreeFilterPayload];
  217. };
  218. declare function getIsPc(): boolean;
  219. interface IPlatform {
  220. APP: "APP";
  221. APP_ANDROID: "APP-ANDROID";
  222. APP_IOS: "APP-IOS";
  223. APP_HARMONY: "APP-HARMONY";
  224. WEB: "WEB";
  225. MP: "MP";
  226. MP_WEIXIN: "MP-WEIXIN";
  227. MP_ALIPAY: "MP-ALIPAY";
  228. MP_BAIDU: "MP-BAIDU";
  229. MP_TOUTIAO: "MP-TOUTIAO";
  230. MP_LARK: "MP-LARK";
  231. MP_QQ: "MP-QQ";
  232. MP_KUAISHOU: "MP-KUAISHOU";
  233. MP_JD: "MP-JD";
  234. MP_360: "MP-360";
  235. MP_XHS: "MP-XHS";
  236. MP_HARMONY: "MP-HARMONY";
  237. QUICKAPP_WEBVIEW: "QUICKAPP-WEBVIEW";
  238. QUICKAPP_WEBVIEW_UNION: "QUICKAPP-WEBVIEW-UNION";
  239. QUICKAPP_WEBVIEW_HUAWEI: "QUICKAPP-WEBVIEW-HUAWEI";
  240. OTHER: "OTHER";
  241. }
  242. declare const Platform: IPlatform;
  243. declare function getPlatform(): IPlatform[keyof IPlatform];
  244. declare const platform: ReturnType<typeof getPlatform>;
  245. /** App */
  246. declare const isApp: boolean;
  247. /** App Android */
  248. declare const isAppAndroid: boolean;
  249. /** App iOS */
  250. declare const isAppIos: boolean;
  251. /** App HarmonyOS Next */
  252. declare const isAppHarmony: boolean;
  253. /** Web */
  254. declare const isWeb: boolean;
  255. /** 小程序 */
  256. declare const isMp: boolean;
  257. /** 微信小程序 */
  258. declare const isMpWeixin: boolean;
  259. /** 支付宝小程序 */
  260. declare const isMpAlipay: boolean;
  261. /** 百度小程序 */
  262. declare const isMpBaidu: boolean;
  263. /** 头条小程序 */
  264. declare const isMpToutiao: boolean;
  265. /** 飞书小程序 */
  266. declare const isMpLark: boolean;
  267. /** QQ小程序 */
  268. declare const isMpQq: boolean;
  269. /** 快手小程序 */
  270. declare const isMpKuaishou: boolean;
  271. /** 京东小程序 */
  272. declare const isMpJd: boolean;
  273. /** 360小程序 */
  274. declare const isMp360: boolean;
  275. /** 小红书小程序 */
  276. declare const isMpXhs: boolean;
  277. /** 鸿蒙元服务 */
  278. declare const isMpHarmony: boolean;
  279. /** 快应用 */
  280. declare const isQuickappWebview: boolean;
  281. /** 快应用联盟 */
  282. declare const isQuickappWebviewUnion: boolean;
  283. /** 快应用华为 */
  284. declare const isQuickappWebviewHuawei: boolean;
  285. /** 其他平台 */
  286. declare const isOtherPlatform: boolean;
  287. declare function isEmpty(value: unknown): boolean;
  288. declare function defaultTo(value: any, ...defaultValues: any[]): any;
  289. declare function sleep(timeout: number): Promise<void>;
  290. declare function upperFirst(value: string): string;
  291. declare function lowerFirst(value: string): string;
  292. type EventType = string | symbol;
  293. type Handler<T = unknown> = (event: T) => void;
  294. type WildcardHandler<T = Record<string, unknown>> = (
  295. type: keyof T,
  296. event: T[keyof T]
  297. ) => void;
  298. type EventHandlerList<T = unknown> = Array<Handler<T>>;
  299. type WildCardEventHandlerList<T = Record<string, unknown>> = Array<
  300. WildcardHandler<T>
  301. >;
  302. type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<
  303. keyof Events | "*",
  304. EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>
  305. >;
  306. interface Emitter<Events extends Record<EventType, unknown>> {
  307. events: EventHandlerMap<Events>;
  308. on: (<Key extends keyof Events>(
  309. type: Key,
  310. handler: Handler<Events[Key]>
  311. ) => void) & ((type: "*", handler: WildcardHandler<Events>) => void);
  312. off: (<Key extends keyof Events>(
  313. type: Key,
  314. handler?: Handler<Events[Key]>
  315. ) => void) & ((type: "*", handler?: WildcardHandler<Events>) => void);
  316. emit: (<Key extends keyof Events>(type: Key, event: Events[Key]) => void) & (<Key extends keyof Events>(
  317. type: undefined extends Events[Key] ? Key : never
  318. ) => void);
  319. }
  320. declare function mitt<Events extends Record<EventType, unknown>>(
  321. events?: EventHandlerMap<Events>
  322. ): Emitter<Events>;
  323. declare function getDeviceInfo(): UniApp.GetDeviceInfoResult | UniApp.GetSystemInfoResult;
  324. declare function getWindowInfo(): UniApp.GetWindowInfoResult | UniApp.GetSystemInfoResult;
  325. declare function getAppBaseInfo(): UniApp.GetAppBaseInfoResult | UniApp.GetSystemInfoResult;
  326. declare function getVersion(): string;
  327. declare function compareVersion(v1: string, v2: string): 0 | 1 | -1;
  328. declare function querySelect(
  329. component: ComponentPublicInstance,
  330. selector: string,
  331. fields: UniApp.NodeField
  332. ): Promise<UniApp.NodeInfo>;
  333. export { Platform, compareVersion, defaultTo, getAppBaseInfo, getDeviceInfo, getIsPc, getPlatform, getVersion, getWindowInfo, isApp, isAppAndroid, isAppHarmony, isAppIos, isEmpty, isMp, isMp360, isMpAlipay, isMpBaidu, isMpHarmony, isMpJd, isMpKuaishou, isMpLark, isMpQq, isMpToutiao, isMpWeixin, isMpXhs, isOtherPlatform, isQuickappWebview, isQuickappWebviewHuawei, isQuickappWebviewUnion, isWeb, lowerFirst, mitt, platform, querySelect, sleep, upperFirst };
  334. export type { CheckStatus, Emitter, EventHandlerList, EventHandlerMap, EventType, Handler, IPlatform, TreeCheckChangePayload, TreeDataItem, TreeEmptySlotProps, TreeExpandPayload, TreeFilterPayload, TreeKey, TreeLoadErrorPayload, TreeLoadPayload, TreeModelValue, TreeNode, TreeNodeClickPayload, TreeProps, TreeScrollToOptions, TreeSlotProps, UniTreeViewEmits, UniTreeViewExposed, UniTreeViewProps, UniTreeViewSlots, WildCardEventHandlerList, WildcardHandler };