@yidun/antd-super-table 0.0.1 → 0.0.3

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
@@ -9,6 +9,9 @@ Antd Super Table 是一个基于 Ant Design Vue 的高级表格组件,提供
9
9
  - 🎯 场景管理功能
10
10
  - ⚡️ 高性能渲染
11
11
  - 🛠 可定制的表格配置
12
+ - 🔄 表格拖拽排序
13
+ - 📱 响应式设计
14
+ - 🎨 主题定制
12
15
 
13
16
  ## 安装
14
17
 
@@ -20,40 +23,68 @@ npm install @yidun/antd-super-table
20
23
 
21
24
  ```vue
22
25
  <template>
23
- <SuperTable
24
- :form-items="formItems"
25
- :columns="columns"
26
- :request="onRequest"
27
- />
26
+ <SuperTable :form-items="formItems" :columns="columns" :request="onRequest" scene-type="user-list" />
28
27
  </template>
29
28
 
30
29
  <script setup lang="ts">
31
- import SuperTable from 'antd-super-table'
32
- import type { SuperTableFormItem, SuperTableColumn } from 'antd-super-table'
30
+ import SuperTable from '@yidun/antd-super-table'
31
+ import type { SuperTableFormItem, SuperTableColumn } from '@yidun/antd-super-table'
33
32
 
34
33
  // 定义查询条件
35
34
  const formItems: SuperTableFormItem[] = [
36
35
  {
37
36
  type: 'input',
38
- key: 'name',
37
+ name: 'name',
39
38
  label: '姓名',
39
+ fixed: true,
40
+ },
41
+ {
42
+ type: 'select',
43
+ name: 'status',
44
+ label: '状态',
45
+ props: {
46
+ options: [
47
+ { label: '启用', value: 1 },
48
+ { label: '禁用', value: 0 },
49
+ ],
50
+ },
40
51
  },
41
52
  ]
42
53
 
43
54
  // 定义表格列
44
55
  const columns: SuperTableColumn[] = [
45
56
  {
46
- type: 'text',
47
57
  key: 'name',
48
58
  title: '姓名',
59
+ content: 'name',
60
+ width: 150,
61
+ },
62
+ {
63
+ key: 'status',
64
+ title: '状态',
65
+ type: 'tag',
66
+ content: record => ({
67
+ label: record.status === 1 ? '启用' : '禁用',
68
+ color: record.status === 1 ? 'green' : 'red',
69
+ }),
70
+ },
71
+ {
72
+ key: 'actions',
73
+ title: '操作',
74
+ type: 'button',
75
+ fixed: 'right',
76
+ content: () => [
77
+ { label: '编辑', onClick: () => console.log('编辑') },
78
+ { label: '删除', onClick: () => console.log('删除') },
79
+ ],
49
80
  },
50
81
  ]
51
82
 
52
83
  // 定义请求函数
53
- const onRequest = async (params: Record<string, any>) => {
54
- const res = await api.getList(params)
84
+ const onRequest = async (options: { params: Record<string, any>; pageSize: number; pageNum: number }) => {
85
+ const res = await api.getList(options.params, options.pageNum, options.pageSize)
55
86
  return {
56
- list: res.data,
87
+ data: res.data,
57
88
  total: res.total,
58
89
  }
59
90
  }
@@ -64,13 +95,26 @@ const onRequest = async (params: Record<string, any>) => {
64
95
 
65
96
  默认启用场景,场景相关的配置存储在localStorage中
66
97
 
67
- | 属性名 | 类型 | 默认值 | 说明 |
68
- | ---------------- | ------- | ------- | ----------------------------------- |
69
- | sceneType | string | '' | 场景对应的标识 |
70
- | enableScene | boolean | `true` | 是否启用场景管理 |
71
- | sceneStorageType | string | `local` | 场景存储位置,可选 `local` 或 `api` |
72
- | sceneRequestUrl | string | `''` | 场景存储的api地址 |
73
- | defaultScene | array | | 默认场景配置 |
98
+ | 属性名 | 类型 | 默认值 | 说明 |
99
+ | ---------------- | ------------ | ----------- | ----------------------------------- |
100
+ | sceneType | string | '' | 场景对应的标识 |
101
+ | enableScene | boolean | `true` | 是否启用场景管理 |
102
+ | sceneStorageType | string | `local` | 场景存储位置,可选 `local` 或 `api` |
103
+ | sceneRequestUrls | object | 内置API地址 | 场景存储的API地址配置 |
104
+ | defaultScene | object/array | | 默认场景配置 |
105
+ | maxSceneCount | number | `100` | 最大场景数量 |
106
+
107
+ ### 场景存储配置
108
+
109
+ ```typescript
110
+ // 场景API地址配置
111
+ const sceneRequestUrls = {
112
+ query: 'https://api.example.com/scene/query',
113
+ create: 'https://api.example.com/scene/create',
114
+ update: 'https://api.example.com/scene/update',
115
+ delete: 'https://api.example.com/scene/delete',
116
+ }
117
+ ```
74
118
 
75
119
  ## 查询条件配置
76
120
 
@@ -85,7 +129,25 @@ const onRequest = async (params: Record<string, any>) => {
85
129
  - 日期范围选择器 (rangePicker)
86
130
  - 级联选择 (cascader)
87
131
  - 树形选择 (treeSelect)
88
- - 自定义组件 (custom)
132
+ - 自定义组件 (component)
133
+
134
+ ### 查询条件属性
135
+
136
+ | 属性名 | 类型 | 默认值 | 说明 |
137
+ | ------------- | --------- | ------- | ----------------------------------- |
138
+ | type | string | - | 查询条件类型 |
139
+ | name | string | - | 字段名称 |
140
+ | label | string | - | 显示标签 |
141
+ | value | any | - | 默认值 |
142
+ | props | object | {} | 传递给组件的属性 |
143
+ | component | Component | - | 自定义组件(type为component时必填) |
144
+ | modelPropName | string | 'value' | 自定义组件的v-model属性名 |
145
+ | span | number | 1 | 列宽系数 |
146
+ | visible | boolean | true | 是否显示 |
147
+ | fixed | boolean | false | 是否固定(不可删除) |
148
+ | selected | boolean | false | 是否默认选中 |
149
+ | quiet | boolean | false | 是否静默更新(不触发搜索) |
150
+ | showLabel | boolean | true | 是否显示标签 |
89
151
 
90
152
  ### 完整示例
91
153
 
@@ -221,6 +283,46 @@ export const createFormItems = () => {
221
283
  modelPropName: 'checked', // 默认通过v-model:value绑定数据,可通过modelPropName自定义修改,最终效果为v-model:[modelPropName]
222
284
  showLabel: false, // 是否显示label,默认为true
223
285
  },
286
+ {
287
+ key: 'cascader',
288
+ type: 'cascader',
289
+ label: '级联选择',
290
+ name: 'cascader',
291
+ props: {
292
+ options: [
293
+ {
294
+ value: 'zhejiang',
295
+ label: 'Zhejiang',
296
+ children: [
297
+ {
298
+ value: 'hangzhou',
299
+ label: 'Hangzhou',
300
+ },
301
+ ],
302
+ },
303
+ ],
304
+ },
305
+ },
306
+ {
307
+ key: 'treeSelect',
308
+ type: 'treeSelect',
309
+ label: '树形选择',
310
+ name: 'treeSelect',
311
+ props: {
312
+ treeData: [
313
+ {
314
+ title: 'Node1',
315
+ value: '0-0',
316
+ children: [
317
+ {
318
+ title: 'Child Node1',
319
+ value: '0-0-0',
320
+ },
321
+ ],
322
+ },
323
+ ],
324
+ },
325
+ },
224
326
  ]
225
327
  }
226
328
  ```
@@ -239,6 +341,24 @@ export const createFormItems = () => {
239
341
 
240
342
  内置解析类型,均支持在一个单元格内展示多个节点,超出最大个数后会展示更多按钮,点击更多按钮可展开查看所有数据,所以可以扩展出文本列表、图片列表、按钮列表、标签列表等展示形式
241
343
 
344
+ ### 表格列属性
345
+
346
+ | 属性名 | 类型 | 默认值 | 说明 |
347
+ | ------------ | ----------------------- | ------ | ----------------------------------- |
348
+ | key | string | - | 列的唯一标识 |
349
+ | title | string | - | 列标题 |
350
+ | type | string/function | 'text' | 列类型 |
351
+ | content | string/function | - | 列内容 |
352
+ | titleTooltip | string/function | - | 标题提示信息 |
353
+ | tooltip | string/boolean/function | - | 内容提示信息 |
354
+ | component | Component | - | 自定义组件(type为component时必填) |
355
+ | props | object/function | {} | 传递给组件的属性 |
356
+ | width | number | 120 | 列宽度 |
357
+ | visible | boolean | true | 是否可见 |
358
+ | fixed | string | - | 固定列位置,可选 'left' 或 'right' |
359
+ | copyable | boolean | false | 是否可复制 |
360
+ | ellipsis | boolean | true | 是否超出显示省略号 |
361
+
242
362
  ### 完整示例
243
363
 
244
364
  ```typescript
@@ -249,9 +369,7 @@ import { Input } from 'ant-design-vue'
249
369
  * @param { object } options 一些提供给表格内置组件使用的扩展
250
370
  *
251
371
  * */
252
- export const createTableColumns = (options: {
253
- onDelete: (record: Record<string, any>) => void
254
- }) => {
372
+ export const createTableColumns = (options: { onDelete: (record: Record<string, any>) => void }) => {
255
373
  return [
256
374
  {
257
375
  key: 'text',
@@ -385,63 +503,178 @@ export const createTableColumns = (options: {
385
503
  }
386
504
  ```
387
505
 
388
- ###
506
+ ## 高级功能
507
+
508
+ ### 表格拖拽排序
509
+
510
+ ```vue
511
+ <template>
512
+ <SuperTable
513
+ :form-items="formItems"
514
+ :columns="columns"
515
+ :request="onRequest"
516
+ :sortable="true"
517
+ @row-sort-end="onRowSortEnd"
518
+ />
519
+ </template>
520
+
521
+ <script setup>
522
+ const onRowSortEnd = newData => {
523
+ console.log('排序后的数据:', newData)
524
+ // 处理排序后的数据
525
+ }
526
+ </script>
527
+ ```
528
+
529
+ ### 表格配置
530
+
531
+ ```vue
532
+ <template>
533
+ <SuperTable :form-items="formItems" :columns="columns" :request="onRequest" :enable-table-config="true" />
534
+ </template>
535
+ ```
536
+
537
+ ### 自定义查询参数
538
+
539
+ ```vue
540
+ <template>
541
+ <SuperTable
542
+ :form-items="formItems"
543
+ :columns="columns"
544
+ :request="onRequest"
545
+ :custom-query-params="{ status: 1, type: 'active' }"
546
+ />
547
+ </template>
548
+ ```
549
+
550
+ ### 插槽使用
389
551
 
390
- ## 对外提供的方法
552
+ ```vue
553
+ <template>
554
+ <SuperTable :form-items="formItems" :columns="columns" :request="onRequest">
555
+ <!-- 场景选择器前的内容 -->
556
+ <template #sceneAddonBefore>
557
+ <a-button type="primary">自定义按钮</a-button>
558
+ </template>
559
+
560
+ <!-- 场景选择器后的内容 -->
561
+ <template #sceneAddonAfter>
562
+ <a-button>导出</a-button>
563
+ </template>
564
+
565
+ <!-- 表格头部 -->
566
+ <template #tableHead>
567
+ <h3>用户列表</h3>
568
+ </template>
569
+
570
+ <!-- 工具栏 -->
571
+ <template #toolBar>
572
+ <a-button type="primary">新增用户</a-button>
573
+ </template>
574
+
575
+ <!-- 表格底部 -->
576
+ <template #tableFoot>
577
+ <div>总计: {{ total }} 条数据</div>
578
+ </template>
579
+
580
+ <!-- 展开行 -->
581
+ <template #expandedRowRender="{ record }">
582
+ <p>详细信息: {{ record.description }}</p>
583
+ </template>
584
+ </SuperTable>
585
+ </template>
586
+ ```
391
587
 
392
588
  ## API
393
589
 
394
590
  ### Props
395
591
 
396
- | 参数 | 说明 | 类型 | 默认值 |
397
- | ------------ | ------------ | -------------------------------------------------------------------------- | -------------------------- |
398
- | formItems | 查询条件配置 | `SuperTableFormItem[]` | `[]` |
399
- | columns | 表格列配置 | `SuperTableColumn[]` | `[]` |
400
- | request | 数据请求函数 | `(params: Record<string, any>) => Promise<{ list: any[], total: number }>` | - |
401
- | sceneType | 场景类型 | `string` | - |
402
- | loading | 加载状态 | `boolean` | `false` |
403
- | pagination | 分页配置 | `boolean | TablePaginationConfig` |
404
- | rowKey | 行数据的 key | `string | ((record: any) => string)` |
405
- | rowSelection | 行选择配置 | `TableRowSelection` | - |
592
+ | 参数 | 说明 | 类型 | 默认值 |
593
+ | ----------------- | ---------------- | -------------------------------------------- | ---------------- |
594
+ | formItems | 查询条件配置 | `SuperTableFormItem[]` | `[]` |
595
+ | columns | 表格列配置 | `SuperTableColumn[]` | `[]` |
596
+ | request | 数据请求函数 | `PropTableRequestFunction` | - |
597
+ | sceneType | 场景类型 | `string` | `''` |
598
+ | enableScene | 是否启用场景管理 | `boolean` | `true` |
599
+ | sceneStorageType | 场景存储位置 | `'local' \| 'api'` | `'local'` |
600
+ | sceneRequestUrls | 场景API地址配置 | `object` | 内置地址 |
601
+ | defaultScene | 默认场景配置 | `DefaultSceneConfig \| DefaultSceneConfig[]` | - |
602
+ | maxSceneCount | 最大场景数量 | `number` | `100` |
603
+ | formItemColSpan | 查询条件列数 | `number` | `6` |
604
+ | debounceWait | 查询防抖时间(ms) | `number` | `100` |
605
+ | refreshDeps | 依赖刷新选项 | `any[]` | `[]` |
606
+ | tableProps | 表格属性 | `TableProps` | `{}` |
607
+ | formatDataSource | 转换表格数据 | `(data: any[]) => any[]` | `(data) => data` |
608
+ | sortable | 是否可排序 | `boolean` | `false` |
609
+ | wrapperStyle | 容器样式 | `object` | `{}` |
610
+ | customQueryParams | 默认查询条件 | `object` | `{}` |
611
+ | showRefreshButton | 展示刷新按钮 | `boolean` | `false` |
612
+ | enableTableConfig | 开启表格设置 | `boolean` | `true` |
406
613
 
407
614
  ### Events
408
615
 
409
- | 事件名 | 说明 | 回调参数 |
410
- | ---------------- | -------------- | ---------------------------------------------------------- |
411
- | search | 搜索事件 | `(params: Record<string, any>) => void` |
412
- | reset | 重置事件 | `() => void` |
413
- | change | 表格变化事件 | `(pagination, filters, sorter) => void` |
414
- | selection-change | 选择项变化事件 | `(selectedRowKeys: string[], selectedRows: any[]) => void` |
616
+ | 事件名 | 说明 | 回调参数 |
617
+ | ---------------- | ------------ | ------------------------------------------------------------------ |
618
+ | form-item-change | 表单项值变更 | `(name: string, value: any, formItem: SuperTableFormItem) => void` |
619
+ | scene-change | 场景切换 | `(scene: SuperTableQueryScene) => void` |
620
+ | sort-change | 排序变化 | `(sorter: any) => void` |
621
+ | row-sort-end | 行排序结束 | `(newData: any[]) => void` |
415
622
 
416
623
  ### Methods
417
624
 
418
- | 方法名 | 说明 | 参数 |
419
- | -------------- | ------------ | ------------------------------- |
420
- | reload | 重新加载数据 | `(resetPage?: boolean) => void` |
421
- | reset | 重置查询条件 | `() => void` |
422
- | clearSelection | 清空选择项 | `() => void` |
625
+ | 方法名 | 说明 | 参数 |
626
+ | ---------------- | ---------------- | --------------------------------------------------------- |
627
+ | getFormItem | 获取表单项配置 | `(name: string) => SuperTableFormItem \| undefined` |
628
+ | setFormItem | 设置表单项配置 | `(name: string, keyPath: string, newConfig: any) => void` |
629
+ | getFormValue | 获取表单项值 | `(name: string) => any` |
630
+ | setFormValue | 设置表单项值 | `(name: string, value: any) => void` |
631
+ | getFormValues | 获取所有表单项值 | `(name?: string \| string[]) => Record<string, any>` |
632
+ | setFormValues | 批量设置表单项值 | `(values: Record<string, any>) => void` |
633
+ | getTableData | 获取表格数据 | `() => any[]` |
634
+ | setTableData | 设置表格数据 | `(data: any[]) => void` |
635
+ | setTableDataItem | 修改单条数据 | `(index: number, data: Record<string, any>) => void` |
636
+ | onRefresh | 刷新表格数据 | `() => void` |
423
637
 
424
- ## Interface
638
+ ## TypeScript 类型定义
425
639
 
426
- ### 表格列类型
640
+ ### 基础类型
427
641
 
428
642
  ```typescript
429
643
  /** 表格列对应的type类型 */
430
- export type SuperTableColumnType =
431
- | 'text'
432
- | 'link'
433
- | 'button'
434
- | 'tag'
435
- | 'image'
644
+ export type SuperTableColumnType = 'text' | 'link' | 'button' | 'tag' | 'image' | 'component' | 'sort'
645
+
646
+ /** 查询表单项对应的type类型 */
647
+ export type SuperTableFormItemType =
648
+ | 'input'
649
+ | 'inputGroup'
650
+ | 'inputNumber'
651
+ | 'inputNumberRange'
652
+ | 'select'
653
+ | 'treeSelect'
654
+ | 'cascader'
655
+ | 'datePicker'
656
+ | 'rangePicker'
436
657
  | 'component'
437
- | 'sort'
438
658
 
659
+ /** 表格单条数据 */
660
+ export type TableDataItem = Record<string, any>
661
+
662
+ /** 表格列吸附方式 */
663
+ export type TableColumnFixedType = 'left' | 'right'
664
+
665
+ /** 排序方式 */
666
+ export type SortOrders = 'ascending' | 'descending' | null
667
+ ```
668
+
669
+ ### 表格列配置
670
+
671
+ ```typescript
439
672
  /** 表格列配置 */
440
673
  export interface SuperTableColumn {
441
674
  /** 列对应key */
442
675
  key: string
443
676
 
444
- /** 展示类型 text: 文本 button: 按钮 link: 链接 tag: 标签 component:自定义组件 */
677
+ /** 展示类型 */
445
678
  type?: SuperTableColumnType | ((row: TableDataItem, index: number) => SuperTableColumnType)
446
679
 
447
680
  /** 标题 */
@@ -473,25 +706,17 @@ export interface SuperTableColumn {
473
706
 
474
707
  /** 宽度 */
475
708
  width?: number
709
+
710
+ /** 固定列位置 */
711
+ fixed?: TableColumnFixedType
712
+
713
+ [key: string]: any
476
714
  }
477
715
  ```
478
716
 
479
- ### 查询条件类型
717
+ ### 查询条件配置
480
718
 
481
719
  ```typescript
482
- /** 查询表单项对应的type类型 */
483
- export type SuperTableFormItemType =
484
- | 'input'
485
- | 'inputGroup'
486
- | 'inputNumber'
487
- | 'inputNumberRange'
488
- | 'select'
489
- | 'treeSelect'
490
- | 'cascader'
491
- | 'datePicker'
492
- | 'rangePicker'
493
- | 'component'
494
-
495
720
  /** 查询条件配置 */
496
721
  export interface SuperTableFormItem {
497
722
  /** 查询详类型 */
@@ -537,6 +762,21 @@ export interface SuperTableFormItem {
537
762
  * 1. 高级搜索弹窗打开时会默认选中对应的搜索项
538
763
  * 2. 没有配置默认场景时,会根据选中的项目生成一个默认场景 */
539
764
  selected?: boolean
765
+
766
+ // 以下为内置属性,不允许修改
767
+ /** 默认值 */
768
+ _defaultValue?: any
769
+
770
+ /** 排序 */
771
+ _order?: number
772
+
773
+ /** 是否选中 */
774
+ _selected?: boolean
775
+
776
+ /** 在选中场景中的排序 */
777
+ _orderInScene?: number
778
+
779
+ [key: string]: any
540
780
  }
541
781
  ```
542
782
 
@@ -595,11 +835,69 @@ export interface DefaultSceneConfig {
595
835
  value: any
596
836
  }[]
597
837
  }
838
+
839
+ /** 场景状态 */
840
+ export interface SuperTableSceneState {
841
+ /** 查询场景列表 */
842
+ list: SuperTableQueryScene[]
843
+
844
+ /** 是否正在加载场景 */
845
+ loading: boolean
846
+
847
+ /** 是否正在保存场景 */
848
+ submiting: boolean
849
+
850
+ /** 是否已经加载过场景 */
851
+ loaded: boolean
852
+ }
853
+ ```
854
+
855
+ ### 数据请求类型
856
+
857
+ ```typescript
858
+ /** 数据请求方法 */
859
+ export type PropTableRequestFunction = (options: {
860
+ /** 查询参数 */
861
+ params: Record<string, any>
862
+
863
+ /** 分页大小 */
864
+ pageSize?: number
865
+
866
+ /** 当前页码 */
867
+ pageNum?: number
868
+
869
+ [key: string]: any
870
+ }) => Promise<{ total: number; data: Record<string, any>[] }>
871
+
872
+ /** 表格属性扩展 */
873
+ export interface AntdTableProps extends TableProps {
874
+ pagination: PaginationProps
875
+ columns: SuperTableColumn[]
876
+ dataSource: Record<string, any>[]
877
+ }
598
878
  ```
599
879
 
600
880
  ## 注意事项
601
881
 
602
- 1. 组件依赖于 Ant Design Vue,请确保项目中已安装相关依赖
603
- 2. TypeScript 项目需要在 `tsconfig.json` 中配置类型声明文件路径
604
- 3. 自定义组件需要通过 `component` 属性传入,并确保组件已全局注册或局部引入
605
- 4. 场景管理功能需要配置 `sceneType` 属性,并实现相关的存储接口
882
+ 1. **依赖要求**:组件依赖于 Ant Design Vue,请确保项目中已安装相关依赖
883
+ 2. **TypeScript 支持**:TypeScript 项目需要在 `tsconfig.json` 中配置类型声明文件路径
884
+ 3. **自定义组件**:自定义组件需要通过 `component` 属性传入,并确保组件已全局注册或局部引入
885
+ 4. **场景管理**:场景管理功能需要配置 `sceneType` 属性,并实现相关的存储接口
886
+ 5. **性能优化**:组件内置了防抖、虚拟滚动等性能优化,大数据量场景下表现良好
887
+ 6. **响应式设计**:组件支持响应式布局,可根据屏幕尺寸自动调整
888
+ 7. **主题定制**:支持通过 CSS 变量或 Ant Design 主题系统进行样式定制
889
+
890
+ ## 更新日志
891
+
892
+ ### v0.0.2
893
+
894
+ - ✨ 新增表格拖拽排序功能
895
+ - ✨ 新增表格配置功能
896
+ - ✨ 新增自定义查询参数支持
897
+ - ✨ 新增多种插槽支持
898
+ - ✨ 新增级联选择和树形选择组件
899
+ - 🐛 修复场景管理相关问题
900
+ - 🐛 修复表格列配置缓存问题
901
+ - 💄 优化UI样式和交互体验
902
+ - 📚 完善TypeScript类型定义
903
+ - 📚 更新文档和示例代码