@aimerthyr/virtual-table 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -4,7 +4,6 @@ import { ColumnFiltersState } from '@tanstack/vue-table';
4
4
  import { ColumnPinningState } from '@tanstack/vue-table';
5
5
  import { ColumnSizingState } from '@tanstack/vue-table';
6
6
  import { ComponentCustomProps } from 'vue';
7
- import { CSSProperties } from 'vue';
8
7
  import { ExpandedState } from '@tanstack/vue-table';
9
8
  import { HTMLAttributes } from 'vue';
10
9
  import { PaginationState } from '@tanstack/vue-table';
@@ -43,7 +42,7 @@ declare const _default: <TData extends VTableData>(__VLS_props: NonNullable<Awai
43
42
  defaultColumnPinning?: ColumnPinningState;
44
43
  defaultColumnSizing?: ColumnSizingState;
45
44
  } & VTableProps<TData>) & Partial<{}>> & PublicProps;
46
- expose(exposed: ShallowUnwrapRef<VTableInstance>): void;
45
+ expose(exposed: ShallowUnwrapRef<VTableInstance<TData>>): void;
47
46
  attrs: any;
48
47
  slots: any;
49
48
  emit: ((evt: "update:defaultFilter", value: ColumnFiltersState) => void) & ((evt: "update:defaultSort", value: SortingState) => void) & ((evt: "update:defaultPagination", value: PaginationState) => void) & ((evt: "update:defaultExpanded", value: ExpandedState) => void) & ((evt: "update:defaultSelection", value: RowSelectionState) => void) & ((evt: "update:defaultColumnPinning", value: ColumnPinningState) => void) & ((evt: "update:defaultColumnSizing", value: ColumnSizingState) => void);
@@ -53,6 +52,9 @@ declare const _default: <TData extends VTableData>(__VLS_props: NonNullable<Awai
53
52
  export { _default as VTable }
54
53
  export default _default;
55
54
 
55
+ /** 默认主题配置 */
56
+ export declare const defaultThemeConfig: VTableThemeConfig;
57
+
56
58
  /** 展开列 */
57
59
  export declare const EXPAND_COLUMN_KEY = "EXPAND_COLUMN_KEY";
58
60
 
@@ -62,8 +64,22 @@ export declare const EXPAND_ROW_DATA_INDEX = "_expandChildren";
62
64
  /** 是否是展开行 */
63
65
  export declare const EXPAND_ROW_KEY = "_isExpandRow";
64
66
 
65
- /** 表格默认样式 */
66
- export declare const TABLE_DEFAULT_STYLE: CSSProperties;
67
+ export declare type VTableBodyCellProps<TData = any> = {
68
+ columnKey: string;
69
+ column: VTableColumn;
70
+ row: TData;
71
+ rowIndex: number;
72
+ };
73
+
74
+ /** 表体样式配置 */
75
+ export declare interface VTableBodyStyle {
76
+ /** 表体字体颜色 */
77
+ color: string;
78
+ /** 表体背景颜色 */
79
+ backgroundColor: string;
80
+ /** 表体内边距 */
81
+ padding: number;
82
+ }
67
83
 
68
84
  export declare type VTableBorderConfig = {
69
85
  /** 是否显示边框 */
@@ -74,6 +90,14 @@ export declare type VTableBorderConfig = {
74
90
  borderColor?: string;
75
91
  };
76
92
 
93
+ /** 边框样式配置 */
94
+ export declare interface VTableBorderStyle {
95
+ /** 边框样式 */
96
+ borderStyle: 'solid' | 'dashed';
97
+ /** 边框颜色 */
98
+ borderColor: string;
99
+ }
100
+
77
101
  /** 表格状态(分页,排序,筛选) */
78
102
  export declare type VTableChangeState = {
79
103
  pagination: VTablePaginationState;
@@ -117,14 +141,21 @@ export declare interface VTableColumn<TData = any> {
117
141
  columnMaxWidth?: number;
118
142
  /** 列宽最小值 (默认 50px) */
119
143
  columnMinWidth?: number;
144
+ /** 子列(用于表头分组) */
145
+ columnChildren?: VTableColumn<TData>[];
120
146
  /** 可自行拓展字段 */
121
147
  [key: string]: any;
122
148
  }
123
149
 
150
+ /** 筛选状态 */
124
151
  export declare type VTableColumnFiltersState = ColumnFiltersState;
125
152
 
153
+ /** 固定列状态 */
126
154
  export declare type VTableColumnPinningState = ColumnPinningState;
127
155
 
156
+ /** 列宽状态 */
157
+ export declare type VTableColumnSizingState = ColumnSizingState;
158
+
128
159
  export declare type VTableData<T = Record<string, any>> = T & {
129
160
  /** 当前行是否展开 */
130
161
  [EXPAND_ROW_KEY]?: boolean;
@@ -141,7 +172,7 @@ export declare const vTableDefaultProps: {
141
172
  loading?: boolean | ((props: VTableProps<any>) => boolean) | undefined;
142
173
  fixedHeader?: boolean | ((props: VTableProps<any>) => boolean) | undefined;
143
174
  enableSortingRemoval?: boolean | ((props: VTableProps<any>) => boolean) | undefined;
144
- borderConfig?: ((props: VTableProps<any>) => VTableBorderConfig) | undefined;
175
+ bordered?: boolean | ((props: VTableProps<any>) => boolean) | undefined;
145
176
  rowSelectionConfig?: ((props: VTableProps<any>) => VTableRowSelectionConfig<any>) | undefined;
146
177
  loadMoreConfig?: ((props: VTableProps<any>) => VTableLoadMoreConfig) | undefined;
147
178
  paginationConfig?: ((props: VTableProps<any>) => VTablePaginationConfig) | undefined;
@@ -151,20 +182,50 @@ export declare const vTableDefaultProps: {
151
182
  adaptiveColumnWidth?: number | ((props: VTableProps<any>) => number) | undefined;
152
183
  defaultExpandAllRows?: boolean | ((props: VTableProps<any>) => boolean) | undefined;
153
184
  columnResizeMode?: "onChange" | "onEnd" | ((props: VTableProps<any>) => "onChange" | "onEnd") | undefined;
154
- customRow?: ((row: any, rowIndex: number) => HTMLAttributes) | ((props: VTableProps<any>) => (row: any, rowIndex: number) => HTMLAttributes) | undefined;
155
- customHeaderCell?: ((column: VTableColumn, colIndex: number) => ThHTMLAttributes) | ((props: VTableProps<any>) => (column: VTableColumn, colIndex: number) => ThHTMLAttributes) | undefined;
156
- customCell?: ((column: VTableColumn, colIndex: number) => TdHTMLAttributes) | ((props: VTableProps<any>) => (column: VTableColumn, colIndex: number) => TdHTMLAttributes) | undefined;
185
+ fixedFooter?: boolean | ((props: VTableProps<any>) => boolean) | undefined;
186
+ themeConfig?: ((props: VTableProps<any>) => VTableThemeConfig) | undefined;
187
+ defaultCheckboxColumnWidth?: number | ((props: VTableProps<any>) => number) | undefined;
188
+ defaultExpandColumnWidth?: number | ((props: VTableProps<any>) => number) | undefined;
189
+ customRowAttributes?: ((row: any, rowIndex: number) => HTMLAttributes) | ((props: VTableProps<any>) => (row: any, rowIndex: number) => HTMLAttributes) | undefined;
190
+ customHeaderCellAttributes?: ((column: VTableColumn, colIndex: number) => ThHTMLAttributes) | ((props: VTableProps<any>) => (column: VTableColumn, colIndex: number) => ThHTMLAttributes) | undefined;
191
+ customCellAttributes?: ((row: any, column: VTableColumn, rowIndex: number, colIndex: number) => TdHTMLAttributes | null) | ((props: VTableProps<any>) => (row: any, column: VTableColumn, rowIndex: number, colIndex: number) => TdHTMLAttributes | null) | undefined;
157
192
  onTableChange?: ((data: VTableChangeState) => void) | ((props: VTableProps<any>) => (data: VTableChangeState) => void) | undefined;
158
193
  onScrollToBottom?: (() => void) | ((props: VTableProps<any>) => () => void) | undefined;
159
194
  onExpandedRowsChange?: ((expandState: VTableExpandedState) => void) | ((props: VTableProps<any>) => (expandState: VTableExpandedState) => void) | undefined;
195
+ onColumnSizingChange?: ((columnSizing: VTableColumnSizingState) => void) | ((props: VTableProps<any>) => (columnSizing: VTableColumnSizingState) => void) | undefined;
160
196
  };
161
197
 
198
+ /** 展开状态 */
162
199
  export declare type VTableExpandedState = ExpandedState;
163
200
 
201
+ /** 展开图标自定义组件接口定义 */
202
+ export declare interface VTableExpandIconProps {
203
+ expand: boolean;
204
+ onExpandChange: () => void;
205
+ }
206
+
207
+ /** 表头样式配置 */
208
+ export declare interface VTableHeaderStyle {
209
+ /** 表头字体颜色 */
210
+ color: string;
211
+ /** 表头背景颜色 */
212
+ backgroundColor: string;
213
+ /** 表头圆角大小 */
214
+ borderRadius: number;
215
+ /** 表头分割线颜色 */
216
+ splitColor: string;
217
+ /** 表头图标颜色 */
218
+ headerIconColor: string;
219
+ /** 表头内边距 */
220
+ padding: number;
221
+ }
222
+
164
223
  /** VTable 实例类型定义 */
165
- export declare interface VTableInstance {
166
- /** 滚动到指定行 */
167
- scrollToIndex: (index: number) => void;
224
+ export declare interface VTableInstance<TData = any> {
225
+ /** tanstack 表格实例 */
226
+ tanstackTable: Table<TData>;
227
+ /** 滚动到指定下标(从 0 开始,默认是平滑滚动) */
228
+ scrollToIndex: (index: number, behavior?: 'auto' | 'smooth') => void;
168
229
  }
169
230
 
170
231
  export declare type VTableLoadMoreConfig = {
@@ -175,7 +236,7 @@ export declare type VTableLoadMoreConfig = {
175
236
  };
176
237
 
177
238
  export declare type VTablePaginationConfig = {
178
- /** 总数(必须要传) */
239
+ /** 总数(必须要传, 客户端分页可以不传,自动以传入的 data 长度作为总数) */
179
240
  total: number;
180
241
  /** 是否开启分页 */
181
242
  enabled?: boolean;
@@ -201,6 +262,7 @@ export declare interface VTablePaginationProps {
201
262
  onPageChange: (pageIndex: number, pageSize: number) => void;
202
263
  }
203
264
 
265
+ /** 分页状态 */
204
266
  export declare type VTablePaginationState = PaginationState;
205
267
 
206
268
  /**
@@ -233,8 +295,8 @@ export declare interface VTableProps<TData = any> {
233
295
  fixedHeader?: boolean;
234
296
  /** 是否允许取消排序 */
235
297
  enableSortingRemoval?: boolean;
236
- /** 边框样式配置 */
237
- borderConfig?: VTableBorderConfig;
298
+ /** 是否显示边框 */
299
+ bordered?: boolean;
238
300
  /** 选择行功能配置 */
239
301
  rowSelectionConfig?: VTableRowSelectionConfig<TData>;
240
302
  /** 加载更多配置 */
@@ -245,7 +307,7 @@ export declare interface VTableProps<TData = any> {
245
307
  treeConfig?: VTableTreeConfig;
246
308
  /** 是否启用展开行功能 */
247
309
  enableExpandRow?: boolean;
248
- /** 是否启用 hover 高亮 */
310
+ /** 是否启用行 hover 高亮 */
249
311
  enableRowHover?: boolean;
250
312
  /** 自适应列宽(当列数很多时,会出现横向滚动条,那么就需要设置自适应列的最小列宽) */
251
313
  adaptiveColumnWidth?: number;
@@ -253,18 +315,31 @@ export declare interface VTableProps<TData = any> {
253
315
  defaultExpandAllRows?: boolean;
254
316
  /** 列宽调整模式 */
255
317
  columnResizeMode?: 'onChange' | 'onEnd';
318
+ /** 是否固定表尾(表尾不随着滚动) */
319
+ fixedFooter?: boolean;
320
+ /** 自定义主题配置(可覆盖默认配置) */
321
+ themeConfig?: VTableThemeConfig;
322
+ /** 默认 checkbox 列宽 */
323
+ defaultCheckboxColumnWidth?: number;
324
+ /** 默认展开列的列宽 */
325
+ defaultExpandColumnWidth?: number;
256
326
  /** 自定义数据行属性 */
257
- customRow?: (row: TData, rowIndex: number) => HTMLAttributes;
327
+ customRowAttributes?: (row: TData, rowIndex: number) => HTMLAttributes;
258
328
  /** 自定义表头单元格属性 */
259
- customHeaderCell?: (column: VTableColumn, colIndex: number) => ThHTMLAttributes;
260
- /** 自定义表体单元格属性 */
261
- customCell?: (column: VTableColumn, colIndex: number) => TdHTMLAttributes;
329
+ customHeaderCellAttributes?: (column: VTableColumn, colIndex: number) => ThHTMLAttributes;
330
+ /**
331
+ * 自定义表体单元格属性(包括合并单元格)
332
+ * 当返回的属性中 colspan 或 rowspan 为 0 时,该单元格不会被渲染
333
+ */
334
+ customCellAttributes?: (row: TData, column: VTableColumn, rowIndex: number, colIndex: number) => TdHTMLAttributes | null;
262
335
  /** 表格状态变化(筛选,排序,分页) */
263
336
  onTableChange?: (data: VTableChangeState) => void;
264
337
  /** 滚动到表格底部 */
265
338
  onScrollToBottom?: () => void;
266
339
  /** 展开行变化回调 */
267
340
  onExpandedRowsChange?: (expandState: VTableExpandedState) => void;
341
+ /** 列宽调整回调 */
342
+ onColumnSizingChange?: (columnSizing: VTableColumnSizingState) => void;
268
343
  }
269
344
 
270
345
  export declare type VTableRowKey<TData> = string | number | ((row: TData) => string | number);
@@ -278,35 +353,31 @@ export declare type VTableRowSelectionConfig<TData> = {
278
353
  onChange?: (selectedRows: TData[]) => void;
279
354
  };
280
355
 
356
+ /** 选择状态 */
281
357
  export declare type VTableSelectionState = RowSelectionState;
282
358
 
283
359
  /** slots 类型定义 */
284
360
  export declare interface VTableSlots<TData = any> {
285
361
  /** 自定义头部渲染 */
286
- customHeader?: (data: {
362
+ customHeader?: (props: {
287
363
  columns: VTableColumn[];
288
364
  table: Table<TData>;
289
365
  }) => VNode_2;
290
366
  /** 自定义单元格 */
291
- bodyCell?: (data: {
292
- columnKey: string;
293
- column: VTableColumn;
294
- row: TData;
295
- rowIndex: number;
296
- }) => VNode_2;
367
+ bodyCell?: (props: VTableBodyCellProps<TData>) => VNode_2;
297
368
  /** 自定义列头 */
298
- headerCell?: (data: {
369
+ headerCell?: (props: {
299
370
  columnKey: string;
300
371
  column: VTableColumn;
301
372
  }) => VNode_2;
302
373
  /** 自定义筛选图标 */
303
- customFilterIcon?: (data: {
374
+ customFilterIcon?: (props: {
304
375
  columnKey: string;
305
376
  filtered: boolean;
306
377
  column: VTableColumn;
307
378
  }) => VNode_2;
308
379
  /** 自定义筛选下拉 */
309
- customFilterDropdown?: (data: {
380
+ customFilterDropdown?: (props: {
310
381
  confirm: () => void;
311
382
  reset: () => void;
312
383
  setFilterValue: (value: any) => void;
@@ -314,16 +385,11 @@ export declare interface VTableSlots<TData = any> {
314
385
  filterModelValue: any;
315
386
  }) => VNode_2;
316
387
  /** 自定义展开行 */
317
- expandedRowRender?: (data: {
388
+ expandedRowRender?: (props: {
318
389
  row: TData;
319
390
  }) => VNode_2;
320
391
  /** 自定义 Popover */
321
- customPopover?: (props: {
322
- open: boolean;
323
- onOpenChange: (value: boolean) => void;
324
- trigger: () => VNode_2;
325
- content: () => VNode_2;
326
- }) => VNode_2;
392
+ customPopover?: (props: VTablePopoverProps) => VNode_2;
327
393
  /** 自定义分页器 */
328
394
  customPagination?: (props: VTablePaginationProps) => VNode_2;
329
395
  /** 自定义 checkbox */
@@ -332,11 +398,41 @@ export declare interface VTableSlots<TData = any> {
332
398
  customEmpty?: () => VNode_2;
333
399
  /** 自定义 loading 图标 */
334
400
  customLoadingIcon?: () => VNode_2;
401
+ /** 自定义加载没有更多区域 */
402
+ customLoadNoMore?: () => VNode_2;
403
+ /** 自定义表尾 */
404
+ customFooter?: () => VNode_2;
405
+ /** 自定义展开图标 */
406
+ customExpandIcon?: (props: VTableExpandIconProps) => VNode_2;
407
+ /** 自定义组件图标 */
408
+ customSorterIcon?: (props: VTableSorterIconProps) => VNode_2;
335
409
  [key: string]: ((...args: any[]) => VNode_2) | undefined;
336
410
  }
337
411
 
412
+ /** 排序图标自定义组件接口定义 */
413
+ export declare interface VTableSorterIconProps {
414
+ sort: 'asc' | 'desc' | null;
415
+ }
416
+
417
+ /** 排序状态 */
338
418
  export declare type VTableSortingState = SortingState;
339
419
 
420
+ /** 表格主题配置 */
421
+ export declare interface VTableThemeConfig {
422
+ /** 主色 */
423
+ primaryColor?: string;
424
+ /** 表头样式 */
425
+ header?: Partial<VTableHeaderStyle>;
426
+ /** 表体样式 */
427
+ body?: Partial<VTableBodyStyle>;
428
+ /** 边框样式 */
429
+ border?: Partial<VTableBorderStyle>;
430
+ /** 行 hover 颜色 */
431
+ rowHoverColor?: string;
432
+ /** z-index 层级配置 */
433
+ zIndex?: VTableZIndexConfig;
434
+ }
435
+
340
436
  export declare type VTableTreeConfig = {
341
437
  /** 是否启用树形结构 */
342
438
  enabled?: boolean;
@@ -346,4 +442,14 @@ export declare type VTableTreeConfig = {
346
442
  indentSize?: number;
347
443
  };
348
444
 
445
+ /** z-index 层级配置 */
446
+ export declare interface VTableZIndexConfig {
447
+ /** 固定列(左右固定) */
448
+ pinnedColumn?: number;
449
+ /** 固定表头 */
450
+ fixedHeader?: number;
451
+ /** 固定表尾 */
452
+ fixedFooter?: number;
453
+ }
454
+
349
455
  export { }