holyes-table 1.0.12 → 1.0.14

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/README.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  这个基于Canvas计算行高的虚拟滚动表格组件。
4
4
 
5
+ ## 目录
6
+
7
+ - [优化](#优化)
8
+ - [注意事项](#注意事项)
9
+ - [组件依赖](#组件依赖)
10
+ - [基本用法](#基本用法)
11
+ - [安装](#安装)
12
+ - [简单示例](#简单示例)
13
+ - [Props 属性](#props-属性)
14
+ - [列配置说明 (columns)](#列配置说明-columns)
15
+ - [树形结构配置 (treeConfig)](#树形结构配置-treeconfig)
16
+ - [展开行配置 (expandConfig)](#展开行配置-expandconfig)
17
+ - [Emits 事件](#emits-事件)
18
+ - [Methods 方法](#methods-方法)
19
+ - [方法使用示例](#方法使用示例)
20
+ - [插槽使用](#插槽使用)
21
+ - [自定义插槽](#自定义插槽)
22
+ - [默认插槽类型](#默认插槽类型)
23
+
5
24
  ## 优化
6
25
 
7
26
  1. 用div+grid布局, 每一行的行高是通过Canvas计算的, 这样不会触发重排。
@@ -33,6 +52,26 @@
33
52
  - 按钮组
34
53
  - 开关
35
54
 
55
+ ## 注意事项
56
+
57
+ 1 **自定义插槽**
58
+
59
+ - 已经默认配置了一些单元格类型 defaultType,不一定都需要自定义插槽。
60
+ - 如果确实需要自定义插槽,必须填写插槽的高度defaultHeight,最好定死列宽度,因为整个表格的高度是根据 Canvas 计算的,能准确计算出每一行的行高。
61
+
62
+ 2 **性能优化**
63
+
64
+ - 大数据量时建议设置 `lazyLoadSlot=true` 延迟加载自定义插槽内容
65
+ - 避免在自定义插槽中执行复杂计算或频繁更新的操作
66
+ - 合理使用 `cellMinHeight` 控制最小行高,避免行高计算不准确
67
+
68
+ 3 **样式定制**
69
+
70
+ - 表格使用 CSS Grid 布局,可以通过 CSS 变量自定义样式
71
+ - 支持斑马纹、悬停高亮、当前行高亮等样式配置
72
+ - 表头支持固定定位,滚动时保持可见
73
+ - 暂不支持自定义文字大小,会影响计算行高
74
+
36
75
  ## 组件依赖
37
76
 
38
77
  - vxe-pc-ui ^4.9.41
@@ -162,37 +201,39 @@ interface HolyesTableColumnPropsType {
162
201
  width?: number
163
202
  /** 列最小宽度 */
164
203
  minWidth?: number
165
- /** 固定位置:left/right */
166
- fixed?: 'left' | 'right' | ''
167
- /** 是否可排序 */
204
+ /** 列固定位置 */
205
+ fixed?: "left" | "right" | ""
206
+ /** 列是否可排序 */
168
207
  sortable?: boolean
169
- /** 列类型:seq(序号)/checkbox(多选) */
170
- type?: 'seq' | 'checkbox'
208
+ /** 列类型 */
209
+ type?: "seq" | "checkbox" | "expand"
171
210
  /** 列样式 */
172
211
  style?: any
173
- /** 筛选配置 */
212
+ /** 列是否可筛选 */
174
213
  isFilter?: {
214
+ /** 筛选的类型 */
175
215
  type: HolyesTableFilterType
216
+ /** 筛选type是listFilter时,筛选选项数组 */
176
217
  listOptions?: { label: string; value: HolyesTableFilterlistOptions }[]
177
218
  }
178
- /** 是否可调整宽度 */
219
+ /** 列是否可调整宽度 */
179
220
  resizable?: boolean
180
- /** 插槽配置 */
221
+ /** 列插槽 */
181
222
  slots?: {
182
- /** 自定义单元格插槽 */
223
+ /** 列自定义插槽 */
183
224
  default?: string
184
- /** 插槽高度(有插槽时必填) */
225
+ /** 列自定义插槽高度,有插槽的话必填,插槽单元格不自动换行 */
185
226
  defaultHeight?: number
186
- /** 默认插槽类型:a(链接)/tag(标签)/icon(图标)/buttons(按钮组)/switch(开关) */
187
- defaultType?: 'a' | 'tag' | 'icon' | 'buttons' | 'switch'
188
- /** 插槽属性 */
227
+ /** 列插槽类型 */
228
+ defaultType?: HolyesTableSlotDefaultType
229
+ /** 列插槽默认属性 */
189
230
  defaultProps?: {
190
- /** 标签插槽属性 */
231
+ /** 标签 插槽默认属性 */
191
232
  tag?: {
192
- /** 标签选项数组 */
233
+ /** 标签匹配规则 */
193
234
  options?: {
194
235
  /** 标签状态 */
195
- status?: 'primary' | 'success' | 'info' | 'warning' | 'error'
236
+ status?: "primary" | "success" | "info" | "warning" | "error"
196
237
  /** 标签颜色 */
197
238
  color?: any
198
239
  /** 标签显示的文本 */
@@ -201,34 +242,34 @@ interface HolyesTableColumnPropsType {
201
242
  value: any
202
243
  }[]
203
244
  }
204
- /** 图标插槽属性 */
245
+ /** 图标 插槽默认属性 */
205
246
  icon?: {
206
- /** 图标名称 */
207
- name?: string
247
+ /** 图标名称, 参考 vxe-icon 图标名称 https://vxeui.com/#/component/icon/base */
248
+ name?: VxeIconPropTypes.Name
208
249
  /** 图标样式 */
209
250
  style?: any
210
251
  }
211
- /** 按钮组插槽属性 */
252
+ /** 按钮 插槽默认属性 */
212
253
  buttons?: {
213
- /** 按钮组数组,每个元素是一行 div 的按钮数组 */
254
+ /** 按钮组数组, 每个元素是一行div的按钮数组 */
214
255
  options?: {
215
- /** 按钮内容 */
256
+ /** 按钮内容*/
216
257
  title?: string
217
258
  /** 按钮提示 */
218
259
  tip?: string
219
260
  /** 按钮前缀图标 */
220
261
  prefixIcon?: any
221
262
  /** 按钮大小 */
222
- size?: 'medium' | 'small' | 'mini'
263
+ size?: "medium" | "small" | "mini"
223
264
  /** 按钮类型 */
224
- type?: 'primary' | 'danger'
225
- /** 按钮样式 */
226
- mode?: 'text' | 'button'
227
- /** 按钮是否显示,取决于 row 的哪个字段 */
265
+ type?: "primary" | "danger"
266
+ /** 按钮样式, 默认button */
267
+ mode?: "text" | "button"
268
+ /** 按钮是否显示,取决于row的哪个字段 */
228
269
  showField?: string
229
- /** 按钮是否禁用,取决于 row 的哪个字段 */
270
+ /** 按钮是否禁用,取决于row的哪个字段 */
230
271
  disabledField?: string
231
- /** 按钮是否加载中,取决于 row 的哪个字段 */
272
+ /** 按钮是否加载中,取决于row的哪个字段 */
232
273
  loadingField?: string
233
274
  /** 按钮点击事件 */
234
275
  onClick?: (row: any, index: number) => void
@@ -236,7 +277,7 @@ interface HolyesTableColumnPropsType {
236
277
  params?: any
237
278
  }[][]
238
279
  }
239
- /** 开关插槽属性 */
280
+ /** 开关 插槽默认属性 */
240
281
  switch?: {
241
282
  /** 开关选中时显示的文本 */
242
283
  checkedChildren?: string
@@ -254,30 +295,62 @@ interface HolyesTableColumnPropsType {
254
295
  openValue?: any
255
296
  /** 开关未选中时的值 */
256
297
  closeValue?: any
257
- /** 按钮是否显示,取决于 row 的哪个字段 */
298
+ /** 按钮是否显示,取决于row的哪个字段 */
258
299
  showField?: string
259
- /** 按钮是否禁用,取决于 row 的哪个字段 */
300
+ /** 按钮是否禁用,取决于row的哪个字段 */
260
301
  disabledField?: string
261
- /** 按钮是否加载中,取决于 row 的哪个字段 */
302
+ /** 按钮是否加载中,取决于row的哪个字段 */
262
303
  loadingField?: string
263
304
  /** 开关点击事件 */
264
305
  onChange?: (row: any, index: number) => void
265
306
  }
307
+ checkbox?: {
308
+ /** 多选框是否半选,取决于row的哪个字段 */
309
+ checkedIndeterminateField?: string
310
+ /** 多选框点击事件 */
311
+ onChange?: (row: any, index: number) => void
312
+ }
266
313
  }
267
- /** 表头插槽 */
314
+ /** 列表头插槽 */
268
315
  header?: string
269
- /** 表头插槽类型 */
270
- headerType?: 'a'
316
+ /** 列表头插槽类型 */
317
+ headerType?: "a"
271
318
  /** 表尾插槽 */
272
319
  footer?: string
273
320
  }
274
- /** 表尾配置 */
275
- footer?: any[]
276
- /** 子列(表头分组) */
321
+ footer?: {
322
+ /** 表尾行高度 */
323
+ height?: number
324
+ /** 表尾类型 */
325
+ type?: HolyesTableFooterType
326
+ dataType?: "number0" | "number1" | "number2" | "string"
327
+ /** 表尾文本 */
328
+ text?: string
329
+ }[]
330
+ /** 表头分组 */
277
331
  children?: HolyesTableColumnPropsType[]
332
+ /** 只对 treeConfig 配置时有效,指定为树节点 */
333
+ treeNode?: boolean
278
334
  }
279
335
  ```
280
336
 
337
+ #### 筛选字段类型说明
338
+
339
+ `isFilter` 属性中的类型定义:
340
+
341
+ ```typescript
342
+ /** 筛选字段类型 */
343
+ type HolyesTableFilterType = "inputFilter" | "numberFilter" | "numberFilter%" | "listFilter" | ""
344
+
345
+ /** 筛选字段列表选项 */
346
+ type HolyesTableFilterlistOptions = string | number | boolean
347
+ ```
348
+
349
+ - **inputFilter**:输入筛选,模糊/精确匹配
350
+ - **numberFilter**:数字筛选,支持 >/≥/=/</≤
351
+ - **numberFilter%**:数字百分比筛选
352
+ - **listFilter**:列表筛选,多选匹配
353
+
281
354
  #### 列配置示例
282
355
 
283
356
  ```javascript
@@ -330,7 +403,7 @@ const columns = [
330
403
 
331
404
  ```typescript
332
405
  interface HolyesTableTreeConfig {
333
- /** 是否开启展开行功能 */
406
+ /** 是否开启树形结构功能 */
334
407
  isOpenTree: boolean
335
408
  /** 自动将列表转为树结构 */
336
409
  transform?: boolean
@@ -363,12 +436,15 @@ interface HolyesTableTreeConfig {
363
436
 
364
437
  ```javascript
365
438
  const treeConfig = {
439
+ isOpenTree: true, // 开启树形结构
366
440
  transform: true, // 自动将列表转为树结构
441
+ idField: 'id', // 节点id字段, 保留展开状态时必填
367
442
  parentField: 'parentId', // 父节点字段
368
443
  childrenField: 'children', // 子节点字段
369
444
  indent: 20, // 缩进像素
370
445
  trigger: 'default', // 点击按钮触发展开/收起
371
446
  showIcon: true // 显示树形图标
447
+ reserve: false // 保留展开状态
372
448
  }
373
449
  ```
374
450
 
@@ -402,6 +478,44 @@ const expandConfig = {
402
478
  }
403
479
  ```
404
480
 
481
+ ### 表尾行属性配置 (footerProps)
482
+
483
+ ```typescript
484
+ /** 表尾类型 */
485
+ type HolyesTableFooterType = "合计" | "文本"
486
+
487
+ /** 表尾行数据类型 */
488
+ type HolyesTableFooterDataType = "number0" | "number1" | "number2" | "string"
489
+
490
+ /** 表尾行字段类型 */
491
+ type HolyesTableFooterFieldTypes = {
492
+ /** 表尾行字段 */
493
+ field: string
494
+ /** 表尾行类型 */
495
+ type: HolyesTableFooterType
496
+ /** 表尾行文本(type为"文本"时使用) */
497
+ text?: string
498
+ /** 表尾行数据类型(type为"合计"时使用) */
499
+ dataType?: HolyesTableFooterDataType
500
+ }
501
+
502
+ /** 外面传入的表尾行属性 */
503
+ type HolyesTableFooterProps = {
504
+ /** 表尾行高度 */
505
+ height?: number
506
+ /** 表尾行字段类型数组 */
507
+ fieldTypes?: HolyesTableFooterFieldTypes[]
508
+ }
509
+ ```
510
+
511
+ - **合计**:自动计算该列的合计值,需指定 `dataType`
512
+ - **文本**:直接显示 `text` 属性的文本内容
513
+ - **dataType 说明**:
514
+ - `number0`:整数
515
+ - `number1`:保留1位小数
516
+ - `number2`:保留2位小数
517
+ - `string`:文本
518
+
405
519
  ## Emits 事件
406
520
 
407
521
  | 事件名 | 参数 | 说明 |
@@ -422,7 +536,7 @@ const expandConfig = {
422
536
  | -------- | ------ | -------- | -------- |
423
537
  | reloadData | `(data: any[])` | `Promise<void>` | 重新设置表格数据 |
424
538
  | getTableData | `()` | `{ fullData, visibleData }` | 获取表格数据(包含全部数据、当前可见数据) |
425
- | getCheckboxRecords | `()` | `any[]` | 获取所有选中的行数据 |
539
+ | getCheckboxRecords | `(isFull: boolean, field?: string)` | `any[]` | 获取所有选中的行数据,isFull 为false时, 只获取当前可见数据的选中行; field 为选中列字段, 默认第一个选中列字段 |
426
540
  | clearCheckboxRow | `()` | `void` | 清空多选列选中状态 |
427
541
  | updateFooter | `()` | `void` | 更新表尾行数据 |
428
542
  | updateFooterCellLabel | `(field: string, rowIndex: number, label: string)` | `void` | 更新表尾单元格文本 |
@@ -469,7 +583,7 @@ const getTableData = () => {
469
583
 
470
584
  /** 获取所有选中的行数据 */
471
585
  const getCheckboxRecords = () => {
472
- const selectedRows = pretextTableRef.value?.getCheckboxRecords() || []
586
+ const selectedRows = pretextTableRef.value?.getCheckboxRecords(true, 'checkbox') || []
473
587
  console.log('选中的行:', selectedRows)
474
588
  }
475
589
 
@@ -568,6 +682,7 @@ const columns = [
568
682
  3. **图标类型 (icon)**: 自动渲染为图标
569
683
  4. **按钮组类型 (buttons)**: 自动渲染为按钮组
570
684
  5. **开关类型 (switch)**: 自动渲染为开关
685
+ 6. **复选框类型 (checkbox)**: 自动渲染为多选框
571
686
 
572
687
  ```javascript
573
688
  const columns = [
@@ -661,26 +776,23 @@ const columns = [
661
776
  }
662
777
  }
663
778
  }
779
+ },
780
+
781
+ // 复选框类型
782
+ {
783
+ field: 'checkbox',
784
+ title: '多选',
785
+ slots: {
786
+ defaultType: 'checkbox',
787
+ defaultProps: {
788
+ checkbox: {
789
+ checkedIndeterminateField: 'halfChecked',
790
+ onChange: (row, index) => {
791
+ console.log('复选框变化', row)
792
+ }
793
+ }
794
+ }
795
+ }
664
796
  }
665
797
  ]
666
798
  ```
667
-
668
- ## 注意事项
669
-
670
- 1 **自定义插槽**
671
-
672
- - 已经默认配置了一些单元格类型 defaultType,不一定都需要自定义插槽。
673
- - 如果确实需要自定义插槽,必须填写插槽的高度defaultHeight,最好定死列宽度,因为整个表格的高度是根据 Canvas 计算的,能准确计算出每一行的行高。
674
-
675
- 2 **性能优化**
676
-
677
- - 大数据量时建议设置 `lazyLoadSlot=true` 延迟加载自定义插槽内容
678
- - 避免在自定义插槽中执行复杂计算或频繁更新的操作
679
- - 合理使用 `cellMinHeight` 控制最小行高,避免行高计算不准确
680
-
681
- 3 **样式定制**
682
-
683
- - 表格使用 CSS Grid 布局,可以通过 CSS 变量自定义样式
684
- - 支持斑马纹、悬停高亮、当前行高亮等样式配置
685
- - 表头支持固定定位,滚动时保持可见
686
- - 暂不支持自定义文字大小,会影响计算行高