stk-table-vue 0.0.1-beta.1 → 0.0.1-beta.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.
Files changed (34) hide show
  1. package/README.md +152 -71
  2. package/lib/{StkTable → src/StkTable}/StkTable.vue.d.ts +91 -30
  3. package/lib/{StkTable → src/StkTable}/types/index.d.ts +46 -8
  4. package/lib/src/StkTable/useHighlight.d.ts +19 -0
  5. package/lib/src/StkTable/utils.d.ts +23 -0
  6. package/lib/stk-table-vue.js +205 -155
  7. package/lib/style.css +79 -64
  8. package/lib/test/StkTable.browser.test.d.ts +1 -0
  9. package/lib/test/insertToOrderedArray.test.d.ts +1 -0
  10. package/package.json +59 -55
  11. package/src/StkTable/StkTable.vue +830 -775
  12. package/src/StkTable/const.ts +7 -7
  13. package/src/StkTable/types/index.ts +106 -74
  14. package/src/StkTable/useColResize.ts +151 -151
  15. package/src/StkTable/useHighlight.ts +126 -128
  16. package/src/StkTable/useThDrag.ts +29 -29
  17. package/src/StkTable/useVirtualScroll.ts +166 -173
  18. package/src/StkTable/utils.ts +99 -104
  19. package/src/VirtualTree.vue +591 -586
  20. package/src/VirtualTreeSelect.vue +296 -301
  21. package/src/vite-env.d.ts +3 -3
  22. package/lib/StkTable/utils.d.ts +0 -23
  23. package/lib/StkTableC/store.d.ts +0 -12
  24. package/src/StkTable.d.ts +0 -17
  25. package/src/StkTable.vue +0 -1686
  26. package/src/StkTableC/index.vue +0 -193
  27. package/src/StkTableC/store.js +0 -6
  28. package/src/StkTable_compatible.vue +0 -590
  29. package/src/images/sort-btn.svg +0 -7
  30. /package/lib/{StkTable → src/StkTable}/const.d.ts +0 -0
  31. /package/lib/{StkTable → src/StkTable}/index.d.ts +0 -0
  32. /package/lib/{StkTable → src/StkTable}/useColResize.d.ts +0 -0
  33. /package/lib/{StkTable → src/StkTable}/useThDrag.d.ts +0 -0
  34. /package/lib/{StkTable → src/StkTable}/useVirtualScroll.d.ts +0 -0
package/README.md CHANGED
@@ -10,6 +10,8 @@ js体积(38kb)
10
10
  * [x] 表头拖动更改顺序。
11
11
  * [x] 表头列宽拖动。
12
12
  * [x] 多级表头。(不支持横向虚拟滚动)
13
+ * [x] 支持table-layout: fixed 配置。
14
+ * [] 鼠标点击后,键盘上下滚动表格
13
15
 
14
16
  ## Usage
15
17
  > npm install stk-table-vue
@@ -33,104 +35,183 @@ const stkTable = ref<InstanceType<typeof StkTable>>();
33
35
  ### StkTable Component Props
34
36
  ```ts
35
37
  export type StkProps = Partial<{
36
- width: string;
38
+ width: string;
37
39
 
38
- /** 最小表格宽度 */
39
- minWidth: string;
40
+ /** 最小表格宽度 */
41
+ minWidth: string;
40
42
 
41
- /** 表格最大宽度*/
42
- maxWidth: string;
43
+ /** 表格最大宽度*/
44
+ maxWidth: string;
43
45
 
44
- /** 是否隐藏表头 */
45
- headless: boolean;
46
+ /** 是否使用 table-layout:fixed */
47
+ fixedMode: boolean;
46
48
 
47
- /** 主题,亮、暗 */
48
- theme: 'light' | 'dark';
49
+ /** 是否隐藏表头 */
50
+ headless: boolean;
49
51
 
50
- /** 虚拟滚动 */
51
- virtual: boolean;
52
+ /** 主题,亮、暗 */
53
+ theme: 'light' | 'dark';
52
54
 
53
- /** x轴虚拟滚动 */
54
- virtualX: boolean;
55
+ /** 虚拟滚动 */
56
+ virtual: boolean;
55
57
 
56
- /** 表格列配置 */
57
- columns: StkTableColumn<any>[];
58
+ /** x轴虚拟滚动 */
59
+ virtualX: boolean;
58
60
 
59
- /** 表格数据源 */
60
- dataSource: any[];
61
+ /** 表格列配置 */
62
+ columns: StkTableColumn<any>[];
61
63
 
62
- /** 行唯一键 */
63
- rowKey: UniqKey;
64
+ /** 表格数据源 */
65
+ dataSource: any[];
64
66
 
65
- /** 列唯一键 */
66
- colKey: UniqKey;
67
+ /** 行唯一键 */
68
+ rowKey: UniqKey;
67
69
 
68
- /** 空值展示文字 */
69
- emptyCellText: string;
70
+ /** 列唯一键 */
71
+ colKey: UniqKey;
70
72
 
71
- /** 暂无数据兜底高度是否撑满 */
72
- noDataFull: boolean;
73
+ /** 空值展示文字 */
74
+ emptyCellText: string;
73
75
 
74
- /** 是否展示暂无数据 */
75
- showNoData: boolean;
76
+ /** 暂无数据兜底高度是否撑满 */
77
+ noDataFull: boolean;
76
78
 
77
- /** 是否服务端排序,true则不排序数据 */
78
- sortRemote: boolean;
79
+ /** 是否展示暂无数据 */
80
+ showNoData: boolean;
79
81
 
80
- /** 表头是否溢出展示... */
81
- showHeaderOverflow: boolean;
82
+ /** 是否服务端排序,true则不排序数据 */
83
+ sortRemote: boolean;
82
84
 
83
- /** 表体溢出是否展示... */
84
- showOverflow: boolean;
85
+ /** 表头是否溢出展示... */
86
+ showHeaderOverflow: boolean;
85
87
 
86
- /** 是否增加行hover class */
87
- showTrHoverClass: boolean;
88
+ /** 表体溢出是否展示... */
89
+ showOverflow: boolean;
88
90
 
89
- /** 表头是否可拖动 */
90
- headerDrag: boolean;
91
+ /** 是否增加行hover class */
92
+ showTrHoverClass: boolean;
91
93
 
92
- /**
93
- * 给行附加className<br>
94
- * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
95
- */
96
- rowClassName: (row: any, i: number) => string;
94
+ /** 表头是否可拖动 */
95
+ headerDrag: boolean;
97
96
 
98
- /**
99
- * 列宽是否可拖动<br>
100
- * **不要设置**列minWidth,**必须**设置width<br>
101
- * 列宽拖动时,每一列都必须要有width,且minWidth/maxWidth不生效。table width会变为"fit-content"。
102
- */
103
- colResizable: boolean;
97
+ /**
98
+ * 给行附加className<br>
99
+ * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
100
+ */
101
+ rowClassName: (row: any, i: number) => string;
104
102
 
105
- /** 可拖动至最小的列宽 */
106
- colMinWidth: number;
103
+ /**
104
+ * 列宽是否可拖动<br>
105
+ * **不要设置**列minWidth,**必须**设置width<br>
106
+ * 列宽拖动时,每一列都必须要有width,且minWidth/maxWidth不生效。table width会变为"fit-content"。
107
+ */
108
+ colResizable: boolean;
109
+
110
+ /** 可拖动至最小的列宽 */
111
+ colMinWidth: number;
107
112
  }>;
108
113
  ```
109
114
 
110
- #### StkTableColumn
115
+ ### StkTableColumn
111
116
  ``` ts
112
117
  type Sorter = boolean | Function;
113
-
118
+ /** 表格列配置 */
114
119
  export type StkTableColumn<T extends Record<string, any>> = {
115
- dataIndex: keyof T & string;
116
- title?: string;
117
- align?: 'right' | 'left' | 'center';
118
- headerAlign?: 'right' | 'left' | 'center';
119
- sorter?: Sorter;
120
- width?: string;
121
- minWidth?: string;
122
- maxWidth?: string;
123
- headerClassName?: string;
124
- className?: string;
125
- sortField?: keyof T;
126
- sortType?: 'number' | 'string';
127
- fixed?: 'left' | 'right' | null;
128
-
129
- /** private */ rowSpan?: number;
130
- /** private */ colSpan?: number;
131
- customCell?: Component | VNode;
132
- customHeaderCell?: Component | VNode;
133
- children?: StkTableColumn<T>[];
120
+ /** 取值id */
121
+ dataIndex: keyof T & string;
122
+ /** 表头文字 */
123
+ title?: string;
124
+ /** 列内容对齐方式 */
125
+ align?: 'right' | 'left' | 'center';
126
+ /** 表头内容对齐方式 */
127
+ headerAlign?: 'right' | 'left' | 'center';
128
+ /** 筛选 */
129
+ sorter?: Sorter;
130
+ /** 列宽。横向虚拟滚动时必须设置。 */
131
+ width?: string;
132
+ /** 最小列宽。非x虚拟滚动生效。 */
133
+ minWidth?: string;
134
+ /** 最大列宽。非x虚拟滚动生效。 */
135
+ maxWidth?: string;
136
+ /**th class */
137
+ headerClassName?: string;
138
+ /** td class */
139
+ className?: string;
140
+ /** 排序字段。default: dataIndex */
141
+ sortField?: keyof T;
142
+ /** 排序方式。按数字/字符串 */
143
+ sortType?: 'number' | 'string';
144
+ /** 固定列 */
145
+ fixed?: 'left' | 'right' | null;
146
+ /** private */ rowSpan?: number;
147
+ /** private */ colSpan?: number;
148
+ /**自定义 td 渲染内容 */
149
+ customCell?: Component | VNode | CustomCellFunc<T>;
150
+ /** 自定义 th 渲染内容 */
151
+ customHeaderCell?: Component | VNode | CustomHeaderCellFunc<T>;
152
+ /** 二级表头 */
153
+ children?: StkTableColumn<T>[];
134
154
  };
135
155
  ```
136
156
 
157
+
158
+ ### Example
159
+ ```vue
160
+ <template>
161
+ <StkTable
162
+ ref="stkTable"
163
+ row-key="name"
164
+ v-model:columns="columns"
165
+ :style="{height:props.height}"
166
+ theme='dark'
167
+ height='200px'
168
+ :show-overflow="false"
169
+ :show-header-overflow="false"
170
+ :sort-remote="false"
171
+ col-resizable
172
+ header-drag
173
+ virtual
174
+ virtual-x
175
+ no-data-full
176
+ :headless="false"
177
+ :data-source="dataSource"
178
+ @current-change="onCurrentChange"
179
+ @row-menu="onRowMenu"
180
+ @header-row-menu="onHeaderRowMenu"
181
+ @row-click="onRowClick"
182
+ @row-dblclick="onRowDblclick"
183
+ @sort-change="handleSortChange"
184
+ @cell-click="onCellClick"
185
+ @header-cell-click="onHeaderCellClick"
186
+ @scroll="onTableScroll"
187
+ @col-order-change="onColOrderChange"
188
+ />
189
+ </template>
190
+ <script setup>
191
+ import { h, defineComponent } from 'vue';
192
+ const columns = [
193
+ {
194
+ title: 'Name',
195
+ dataIndex: 'name',
196
+ fixed: 'left',
197
+ width: '200px',
198
+ headerClassName: 'my-th',
199
+ className: 'my-td',
200
+ sorter: true,
201
+ customHeaderCell: function FunctionalComponent(props){
202
+ return h(
203
+ 'span',
204
+ { style: 'overflow:hidden;text-overflow:ellipsis;white-space:nowrap' },
205
+ props.col.title + '(render) text-overflow,',
206
+ );
207
+ },
208
+ customCell: defineComponent({
209
+ setup(){
210
+ //...
211
+ return () => <div></div>
212
+ }
213
+ })
214
+ },
215
+ ]
216
+ </script>
217
+ ```
@@ -1,4 +1,12 @@
1
- import { SortOption, StkProps, StkTableColumn } from '../StkTable/types/index';
1
+ /**
2
+ * @author JA+
3
+ * 不支持低版本浏览器非虚拟滚动表格的表头固定,列固定,因为会卡。
4
+ * TODO:存在的问题:
5
+ * [] column.dataIndex 作为唯一键,不能重复
6
+ * [] 计算的高亮颜色,挂在数据源上对象上,若多个表格使用同一个数据源对象会有问题。需要深拷贝。(解决方案:获取组件uid)
7
+ * [] highlight-row 颜色不能恢复到active的颜色
8
+ */
9
+ import { SortOption, StkTableColumn } from '../StkTable/types/index';
2
10
  /**
3
11
  * 选中一行,
4
12
  * @param {string} rowKey
@@ -7,13 +15,6 @@ import { SortOption, StkProps, StkTableColumn } from '../StkTable/types/index';
7
15
  declare function setCurrentRow(rowKey: string, option?: {
8
16
  silent: boolean;
9
17
  }): void;
10
- /** 高亮一个单元格 */
11
- declare function setHighlightDimCell(rowKeyValue: string, dataIndex: string): void;
12
- /**
13
- * 高亮一行
14
- * @param rowKeyValues
15
- */
16
- declare function setHighlightDimRow(rowKeyValues: Array<string | number>): void;
17
18
  /**
18
19
  * 设置表头排序状态
19
20
  * @param {string} dataIndex 列字段
@@ -29,14 +30,44 @@ declare function setSorter(dataIndex: string, order: null | 'asc' | 'desc', opti
29
30
  }): any[];
30
31
  /** 重置排序 */
31
32
  declare function resetSorter(): void;
32
- /** 滚动 */
33
- declare function scrollTo(top?: number, left?: number): void;
33
+ /**
34
+ * 设置滚动条位置
35
+ * @param top 传null 则不变动位置
36
+ * @param left 传null 则不变动位置
37
+ */
38
+ declare function scrollTo(top?: number | null, left?: number | null): void;
34
39
  /** 获取当前状态的表格数据 */
35
40
  declare function getTableData(): any[];
36
- declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<StkProps>, {
41
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Partial<{
37
42
  width: string;
38
43
  minWidth: string;
39
44
  maxWidth: string;
45
+ fixedMode: boolean;
46
+ headless: boolean;
47
+ theme: "light" | "dark";
48
+ virtual: boolean;
49
+ virtualX: boolean;
50
+ columns: StkTableColumn<any>[];
51
+ dataSource: any[];
52
+ rowKey: import('../StkTable/types/index').UniqKey;
53
+ colKey: import('../StkTable/types/index').UniqKey;
54
+ emptyCellText: string;
55
+ noDataFull: boolean;
56
+ showNoData: boolean;
57
+ sortRemote: boolean;
58
+ showHeaderOverflow: boolean;
59
+ showOverflow: boolean;
60
+ showTrHoverClass: boolean;
61
+ headerDrag: boolean;
62
+ rowClassName: (row: any, i: number) => string;
63
+ colResizable: boolean;
64
+ colMinWidth: number;
65
+ border: boolean | "horizontal";
66
+ }>>, {
67
+ width: string;
68
+ fixedMode: boolean;
69
+ minWidth: string;
70
+ maxWidth: string;
40
71
  headless: boolean;
41
72
  theme: string;
42
73
  virtual: boolean;
@@ -56,32 +87,59 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
56
87
  rowClassName: () => "";
57
88
  colResizable: boolean;
58
89
  colMinWidth: number;
90
+ border: boolean;
59
91
  }>, {
60
92
  setCurrentRow: typeof setCurrentRow;
61
- setHighlightDimCell: typeof setHighlightDimCell;
62
- setHighlightDimRow: typeof setHighlightDimRow;
93
+ setHighlightDimCell: (rowKeyValue: string, dataIndex: string) => void;
94
+ setHighlightDimRow: (rowKeyValues: (string | number)[]) => void;
63
95
  setSorter: typeof setSorter;
64
96
  resetSorter: typeof resetSorter;
65
97
  scrollTo: typeof scrollTo;
66
98
  getTableData: typeof getTableData;
67
99
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
68
- "row-click": (...args: any[]) => void;
100
+ scroll: (...args: any[]) => void;
101
+ "th-drag-start": (...args: any[]) => void;
102
+ "col-order-change": (...args: any[]) => void;
103
+ "th-drop": (...args: any[]) => void;
104
+ columns: (...args: any[]) => void;
69
105
  "sort-change": (...args: any[]) => void;
106
+ "row-click": (...args: any[]) => void;
70
107
  "current-change": (...args: any[]) => void;
71
108
  "row-dblclick": (...args: any[]) => void;
72
109
  "header-row-menu": (...args: any[]) => void;
73
110
  "row-menu": (...args: any[]) => void;
74
111
  "cell-click": (...args: any[]) => void;
75
112
  "header-cell-click": (...args: any[]) => void;
76
- "col-order-change": (...args: any[]) => void;
77
- "th-drop": (...args: any[]) => void;
78
- "th-drag-start": (...args: any[]) => void;
79
- scroll: (...args: any[]) => void;
80
- columns: (...args: any[]) => void;
81
- }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<StkProps>, {
113
+ }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Partial<{
82
114
  width: string;
83
115
  minWidth: string;
84
116
  maxWidth: string;
117
+ fixedMode: boolean;
118
+ headless: boolean;
119
+ theme: "light" | "dark";
120
+ virtual: boolean;
121
+ virtualX: boolean;
122
+ columns: StkTableColumn<any>[];
123
+ dataSource: any[];
124
+ rowKey: import('../StkTable/types/index').UniqKey;
125
+ colKey: import('../StkTable/types/index').UniqKey;
126
+ emptyCellText: string;
127
+ noDataFull: boolean;
128
+ showNoData: boolean;
129
+ sortRemote: boolean;
130
+ showHeaderOverflow: boolean;
131
+ showOverflow: boolean;
132
+ showTrHoverClass: boolean;
133
+ headerDrag: boolean;
134
+ rowClassName: (row: any, i: number) => string;
135
+ colResizable: boolean;
136
+ colMinWidth: number;
137
+ border: boolean | "horizontal";
138
+ }>>, {
139
+ width: string;
140
+ fixedMode: boolean;
141
+ minWidth: string;
142
+ maxWidth: string;
85
143
  headless: boolean;
86
144
  theme: string;
87
145
  virtual: boolean;
@@ -101,32 +159,34 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
101
159
  rowClassName: () => "";
102
160
  colResizable: boolean;
103
161
  colMinWidth: number;
162
+ border: boolean;
104
163
  }>>> & {
105
- "onRow-click"?: ((...args: any[]) => any) | undefined;
164
+ onScroll?: ((...args: any[]) => any) | undefined;
165
+ "onTh-drag-start"?: ((...args: any[]) => any) | undefined;
166
+ "onCol-order-change"?: ((...args: any[]) => any) | undefined;
167
+ "onTh-drop"?: ((...args: any[]) => any) | undefined;
168
+ onColumns?: ((...args: any[]) => any) | undefined;
106
169
  "onSort-change"?: ((...args: any[]) => any) | undefined;
170
+ "onRow-click"?: ((...args: any[]) => any) | undefined;
107
171
  "onCurrent-change"?: ((...args: any[]) => any) | undefined;
108
172
  "onRow-dblclick"?: ((...args: any[]) => any) | undefined;
109
173
  "onHeader-row-menu"?: ((...args: any[]) => any) | undefined;
110
174
  "onRow-menu"?: ((...args: any[]) => any) | undefined;
111
175
  "onCell-click"?: ((...args: any[]) => any) | undefined;
112
176
  "onHeader-cell-click"?: ((...args: any[]) => any) | undefined;
113
- "onCol-order-change"?: ((...args: any[]) => any) | undefined;
114
- "onTh-drop"?: ((...args: any[]) => any) | undefined;
115
- "onTh-drag-start"?: ((...args: any[]) => any) | undefined;
116
- onScroll?: ((...args: any[]) => any) | undefined;
117
- onColumns?: ((...args: any[]) => any) | undefined;
118
177
  }, {
119
- columns: StkTableColumn<any>[];
120
- dataSource: any[];
121
178
  width: string;
122
179
  minWidth: string;
123
180
  maxWidth: string;
181
+ colKey: import('../StkTable/types/index').UniqKey;
182
+ fixedMode: boolean;
124
183
  headless: boolean;
125
184
  theme: "light" | "dark";
126
185
  virtual: boolean;
127
186
  virtualX: boolean;
187
+ columns: StkTableColumn<any>[];
188
+ dataSource: any[];
128
189
  rowKey: import('../StkTable/types/index').UniqKey;
129
- colKey: import('../StkTable/types/index').UniqKey;
130
190
  emptyCellText: string;
131
191
  noDataFull: boolean;
132
192
  showNoData: boolean;
@@ -135,9 +195,10 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
135
195
  showOverflow: boolean;
136
196
  showTrHoverClass: boolean;
137
197
  headerDrag: boolean;
138
- rowClassName: Function;
198
+ rowClassName: (row: any, i: number) => string;
139
199
  colResizable: boolean;
140
200
  colMinWidth: number;
201
+ border: boolean | "horizontal";
141
202
  }, {}>, {
142
203
  tableHeader?(_: {
143
204
  column: StkTableColumn<any>;
@@ -1,38 +1,70 @@
1
1
  import { Component, VNode } from 'vue';
2
- type Sorter = boolean | Function;
2
+ /** 排序方式,asc-正序,desc-倒序,null-默认顺序 */
3
+ export type Order = null | 'asc' | 'desc';
4
+ type Sorter = boolean | ((data: any[], option: {
5
+ order: Order;
6
+ column: any;
7
+ }) => any[]);
8
+ export type CustomCellFunc<T extends Record<string, any>> = (props: {
9
+ row: T;
10
+ col: StkTableColumn<T>;
11
+ cellValue: any;
12
+ }) => VNode;
13
+ export type CustomHeaderCellFunc<T extends Record<string, any>> = (props: {
14
+ col: StkTableColumn<T>;
15
+ }) => VNode;
16
+ /** 表格列配置 */
3
17
  export type StkTableColumn<T extends Record<string, any>> = {
18
+ /** 取值id */
4
19
  dataIndex: keyof T & string;
20
+ /** 表头文字 */
5
21
  title?: string;
22
+ /** 列内容对齐方式 */
6
23
  align?: 'right' | 'left' | 'center';
24
+ /** 表头内容对齐方式 */
7
25
  headerAlign?: 'right' | 'left' | 'center';
26
+ /** 筛选 */
8
27
  sorter?: Sorter;
28
+ /** 列宽。横向虚拟滚动时必须设置。 */
9
29
  width?: string;
30
+ /** 最小列宽。非x虚拟滚动生效。 */
10
31
  minWidth?: string;
32
+ /** 最大列宽。非x虚拟滚动生效。 */
11
33
  maxWidth?: string;
34
+ /**th class */
12
35
  headerClassName?: string;
36
+ /** td class */
13
37
  className?: string;
38
+ /** 排序字段。default: dataIndex */
14
39
  sortField?: keyof T;
40
+ /** 排序方式。按数字/字符串 */
15
41
  sortType?: 'number' | 'string';
42
+ /** 固定列 */
16
43
  fixed?: 'left' | 'right' | null;
17
44
  /** private */ rowSpan?: number;
18
45
  /** private */ colSpan?: number;
19
- customCell?: Component | VNode;
20
- customHeaderCell?: Component | VNode;
46
+ /**自定义 td 渲染内容 */
47
+ customCell?: Component | VNode | CustomCellFunc<T>;
48
+ /** 自定义 th 渲染内容 */
49
+ customHeaderCell?: Component | VNode | CustomHeaderCellFunc<T>;
50
+ /** 二级表头 */
21
51
  children?: StkTableColumn<T>[];
22
52
  };
23
53
  export type SortOption = Pick<StkTableColumn<any>, 'sorter' | 'dataIndex' | 'sortField' | 'sortType'>;
24
- export type SortState = {
25
- dataIndex: string;
54
+ export type SortState<T> = {
55
+ dataIndex: T;
26
56
  order: null | 'asc' | 'desc';
27
57
  sortType?: 'number' | 'string';
28
58
  };
29
59
  export type UniqKey = string | ((param: any) => string);
30
- export type StkProps = {
60
+ export type StkProps = Partial<{
31
61
  width: string;
32
62
  /** 最小表格宽度 */
33
63
  minWidth: string;
34
64
  /** 表格最大宽度*/
35
65
  maxWidth: string;
66
+ /** 是否使用 table-layout:fixed */
67
+ fixedMode: boolean;
36
68
  /** 是否隐藏表头 */
37
69
  headless: boolean;
38
70
  /** 主题,亮、暗 */
@@ -69,7 +101,7 @@ export type StkProps = {
69
101
  * 给行附加className<br>
70
102
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
71
103
  */
72
- rowClassName: Function;
104
+ rowClassName: (row: any, i: number) => string;
73
105
  /**
74
106
  * 列宽是否可拖动<br>
75
107
  * **不要设置**列minWidth,**必须**设置width<br>
@@ -78,5 +110,11 @@ export type StkProps = {
78
110
  colResizable: boolean;
79
111
  /** 可拖动至最小的列宽 */
80
112
  colMinWidth: number;
81
- };
113
+ /**
114
+ * 单元格分割线。
115
+ * 默认横竖都有
116
+ * horizontal - 仅展示横线
117
+ */
118
+ border: boolean | 'horizontal';
119
+ }>;
82
120
  export {};
@@ -0,0 +1,19 @@
1
+ import { Ref } from 'vue';
2
+ type Params = {
3
+ props: {
4
+ theme: 'light' | 'dark';
5
+ virtual: boolean;
6
+ dataSource: any[];
7
+ };
8
+ tableContainer: Ref<HTMLElement | undefined>;
9
+ rowKeyGen: (p: any) => string;
10
+ };
11
+ /**
12
+ * 高亮单元格,行
13
+ * row中新增_bgc_progress_ms 属性控制高亮状态,_bgc控制颜色
14
+ */
15
+ export declare function useHighlight({ props, tableContainer, rowKeyGen }: Params): {
16
+ setHighlightDimRow: (rowKeyValues: Array<string | number>) => void;
17
+ setHighlightDimCell: (rowKeyValue: string, dataIndex: string) => void;
18
+ };
19
+ export {};
@@ -0,0 +1,23 @@
1
+ import { Order, SortOption, SortState, StkTableColumn } from './types';
2
+ /**
3
+ * 对有序数组插入新数据
4
+ * @param sortState
5
+ * @param sortState.dataIndex 排序的列
6
+ * @param sortState.order 排序顺序
7
+ * @param sortState.sortType 排序方式
8
+ * @param newItem 要插入的数据
9
+ * @param targetArray 表格数据
10
+ */
11
+ export declare function insertToOrderedArray<T extends object>(sortState: SortState<keyof T>, newItem: any, targetArray: T[]): T[];
12
+ /**
13
+ * 表格排序抽离
14
+ * 可以在组件外部自己实现表格排序,组件配置remote,使表格不排序。
15
+ * 使用者在@sort-change事件中自行更改table props 'dataSource'完成排序。
16
+ * TODO: key 唯一值,排序字段相同时,根据唯一值排序。
17
+ * @param sortOption 列配置
18
+ * @param order 排序方式
19
+ * @param dataSource 排序的数组
20
+ */
21
+ export declare function tableSort(sortOption: SortOption, order: Order, dataSource: any[]): any[];
22
+ /** column 的层级 */
23
+ export declare function howDeepTheColumn(arr: StkTableColumn<any>[], level?: number): number;