UNPKG

4.33 kBTypeScriptView Raw
1import { RenderFunction, SetupContext, ComponentPublicInstance, Ref } from 'vue'
2import { VXEComponent, VxeComponentBase, VxeEvent, SizeType, ValueOf } from './component'
3
4/* eslint-disable no-use-before-define */
5
6/**
7 * 组件 - 虚拟列表
8 * @example import { VxeList } from 'vxe-table'
9 */
10export const VxeList: VXEComponent<VxeListProps, VxeListEventProps, VxeListSlots>
11/**
12 * 组件 - 虚拟列表
13 */
14export const List: typeof VxeList
15
16export type VxeListInstance = ComponentPublicInstance<VxeListProps, VxeListConstructor>
17
18export interface VxeListConstructor extends VxeComponentBase, VxeListMethods {
19 props: VxeListProps
20 context: SetupContext<VxeListEmits>
21 reactData: ListReactData
22 internalData: ListInternalData
23 getRefMaps(): ListPrivateRef
24 renderVN: RenderFunction
25}
26
27export interface ListPrivateRef {
28 refElem: Ref<HTMLDivElement>
29}
30export interface VxeListPrivateRef extends ListPrivateRef { }
31
32export interface ListReactData {
33 scrollYLoad: boolean
34 bodyHeight: number
35 rowHeight: number
36 topSpaceHeight: number
37 items: any[]
38}
39
40export interface ListInternalData {
41 fullData: any[]
42 lastScrollLeft: number
43 lastScrollTop: number
44 scrollYStore: {
45 startIndex: number
46 endIndex: number
47 visibleSize: number
48 offsetSize: number
49 rowHeight: number
50 }
51}
52
53export interface ListMethods {
54 dispatchEvent(type: ValueOf<VxeListEmits>, params: any, evnt: Event): void
55 /**
56 * 加载数据
57 * @param data 列表数据
58 */
59 loadData(data: any[]): Promise<any>
60
61 /**
62 * 加载数据
63 * @param data 列表数据
64 */
65 reloadData(data: any[]): Promise<any>
66
67 /**
68 * 重新计算列表
69 */
70 recalculate(): Promise<void>
71
72 /**
73 * 如果有滚动条,则滚动到对应的位置
74 * @param scrollLeft 左边距离
75 * @param scrollTop 顶部距离
76 */
77 scrollTo(scrollLeft: number | null, scrollTop?: number | null): Promise<void>
78
79 /**
80 * 刷新滚动操作,手动同步滚动相关位置
81 */
82 refreshScroll(): Promise<void>
83
84 /**
85 * 手动清除滚动相关信息,还原到初始状态
86 */
87 clearScroll(): Promise<void>
88}
89export interface VxeListMethods extends ListMethods { }
90
91export interface ListPrivateMethods { }
92export interface VxeListPrivateMethods extends ListPrivateMethods { }
93
94export namespace VxeListPropTypes {
95 export type Size = SizeType
96 export type Data = any[]
97 export type Height = number | string
98 export type MaxHeight = number | string
99 export type Loading = boolean
100 export type AutoResize = boolean
101 export type ClassName = string | ((params: { $list: VxeListConstructor }) => string)
102 export type SyncResize = boolean | string | number
103 export interface ScrollY {
104 /**
105 * 指定大于指定行时自动启动纵向虚拟滚动,如果为 0 则总是启用,如果为 -1 则关闭
106 */
107 gt?: number
108 /**
109 * 指定每次渲染的数据偏移量,偏移量越大渲染次数就越少,但每次渲染耗时就越久
110 */
111 oSize?: number
112 /**
113 * 指定列表项的 className
114 */
115 sItem?: string
116 /**
117 * 是否启用
118 */
119 enabled?: boolean
120 }
121}
122
123export type VxeListProps<D = any> = {
124 size?: VxeListPropTypes.Size
125 data?: D[]
126 height?: VxeListPropTypes.Height
127 maxHeight?: VxeListPropTypes.MaxHeight
128 loading?: VxeListPropTypes.Loading
129 autoResize?: VxeListPropTypes.AutoResize
130 syncResize?: VxeListPropTypes.SyncResize
131 className?: VxeListPropTypes.ClassName
132 scrollY?: VxeListPropTypes.ScrollY
133}
134
135export type VxeListEmits = [
136 'scroll'
137]
138
139export namespace VxeListDefines {
140 interface ListEventParams extends VxeEvent {
141 $list: VxeListConstructor
142 }
143
144 export interface ScrollParams { }
145 export interface ScrollEventParams extends ListEventParams, ScrollParams { }
146}
147
148export type VxeListEventProps = {
149 onScroll?: VxeListEvents.Scroll
150}
151
152export interface VxeListListeners {
153 scroll?: VxeListEvents.Scroll
154}
155
156export namespace VxeListEvents {
157 export type Scroll = (params: VxeListDefines.ScrollEventParams) => void
158}
159
160export interface VxeListSlots {
161 /**
162 * 自定义插槽模板
163 */
164 [key: string]: ((params: {
165 [key: string]: any
166 }) => any) | undefined
167}