stk-table-vue 0.0.1-beta.1 → 0.0.1-beta.2

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
@@ -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,77 +35,80 @@ 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
 
@@ -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 列字段
@@ -33,8 +34,34 @@ declare function resetSorter(): void;
33
34
  declare function scrollTo(top?: number, left?: number): void;
34
35
  /** 获取当前状态的表格数据 */
35
36
  declare function getTableData(): any[];
36
- declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<StkProps>, {
37
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Partial<{
38
+ width: string;
39
+ minWidth: string;
40
+ maxWidth: string;
41
+ fixedMode: boolean;
42
+ headless: boolean;
43
+ theme: "light" | "dark";
44
+ virtual: boolean;
45
+ virtualX: boolean;
46
+ columns: StkTableColumn<any>[];
47
+ dataSource: any[];
48
+ rowKey: import('../StkTable/types/index').UniqKey;
49
+ colKey: import('../StkTable/types/index').UniqKey;
50
+ emptyCellText: string;
51
+ noDataFull: boolean;
52
+ showNoData: boolean;
53
+ sortRemote: boolean;
54
+ showHeaderOverflow: boolean;
55
+ showOverflow: boolean;
56
+ showTrHoverClass: boolean;
57
+ headerDrag: boolean;
58
+ rowClassName: (row: any, i: number) => string;
59
+ /** rowKey缓存 */
60
+ colResizable: boolean;
61
+ colMinWidth: number;
62
+ }>>, {
37
63
  width: string;
64
+ fixedMode: boolean;
38
65
  minWidth: string;
39
66
  maxWidth: string;
40
67
  headless: boolean;
@@ -58,28 +85,54 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
58
85
  colMinWidth: number;
59
86
  }>, {
60
87
  setCurrentRow: typeof setCurrentRow;
61
- setHighlightDimCell: typeof setHighlightDimCell;
62
- setHighlightDimRow: typeof setHighlightDimRow;
88
+ setHighlightDimCell: (rowKeyValue: string, dataIndex: string) => void;
89
+ setHighlightDimRow: (rowKeyValues: (string | number)[]) => void;
63
90
  setSorter: typeof setSorter;
64
91
  resetSorter: typeof resetSorter;
65
92
  scrollTo: typeof scrollTo;
66
93
  getTableData: typeof getTableData;
67
94
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
68
- "row-click": (...args: any[]) => void;
95
+ scroll: (...args: any[]) => void;
96
+ "th-drag-start": (...args: any[]) => void;
97
+ "col-order-change": (...args: any[]) => void;
98
+ "th-drop": (...args: any[]) => void;
99
+ columns: (...args: any[]) => void;
69
100
  "sort-change": (...args: any[]) => void;
101
+ "row-click": (...args: any[]) => void;
70
102
  "current-change": (...args: any[]) => void;
71
103
  "row-dblclick": (...args: any[]) => void;
72
104
  "header-row-menu": (...args: any[]) => void;
73
105
  "row-menu": (...args: any[]) => void;
74
106
  "cell-click": (...args: any[]) => void;
75
107
  "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>, {
108
+ }, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Partial<{
109
+ width: string;
110
+ minWidth: string;
111
+ maxWidth: string;
112
+ fixedMode: boolean;
113
+ headless: boolean;
114
+ theme: "light" | "dark";
115
+ virtual: boolean;
116
+ virtualX: boolean;
117
+ columns: StkTableColumn<any>[];
118
+ dataSource: any[];
119
+ rowKey: import('../StkTable/types/index').UniqKey;
120
+ colKey: import('../StkTable/types/index').UniqKey;
121
+ emptyCellText: string;
122
+ noDataFull: boolean;
123
+ showNoData: boolean;
124
+ sortRemote: boolean;
125
+ showHeaderOverflow: boolean;
126
+ showOverflow: boolean;
127
+ showTrHoverClass: boolean;
128
+ headerDrag: boolean;
129
+ rowClassName: (row: any, i: number) => string;
130
+ /** rowKey缓存 */
131
+ colResizable: boolean;
132
+ colMinWidth: number;
133
+ }>>, {
82
134
  width: string;
135
+ fixedMode: boolean;
83
136
  minWidth: string;
84
137
  maxWidth: string;
85
138
  headless: boolean;
@@ -102,31 +155,32 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
102
155
  colResizable: boolean;
103
156
  colMinWidth: number;
104
157
  }>>> & {
105
- "onRow-click"?: ((...args: any[]) => any) | undefined;
158
+ onScroll?: ((...args: any[]) => any) | undefined;
159
+ "onTh-drag-start"?: ((...args: any[]) => any) | undefined;
160
+ "onCol-order-change"?: ((...args: any[]) => any) | undefined;
161
+ "onTh-drop"?: ((...args: any[]) => any) | undefined;
162
+ onColumns?: ((...args: any[]) => any) | undefined;
106
163
  "onSort-change"?: ((...args: any[]) => any) | undefined;
164
+ "onRow-click"?: ((...args: any[]) => any) | undefined;
107
165
  "onCurrent-change"?: ((...args: any[]) => any) | undefined;
108
166
  "onRow-dblclick"?: ((...args: any[]) => any) | undefined;
109
167
  "onHeader-row-menu"?: ((...args: any[]) => any) | undefined;
110
168
  "onRow-menu"?: ((...args: any[]) => any) | undefined;
111
169
  "onCell-click"?: ((...args: any[]) => any) | undefined;
112
170
  "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
171
  }, {
119
- columns: StkTableColumn<any>[];
120
- dataSource: any[];
121
172
  width: string;
122
173
  minWidth: string;
123
174
  maxWidth: string;
175
+ colKey: import('../StkTable/types/index').UniqKey;
176
+ fixedMode: boolean;
124
177
  headless: boolean;
125
178
  theme: "light" | "dark";
126
179
  virtual: boolean;
127
180
  virtualX: boolean;
181
+ columns: StkTableColumn<any>[];
182
+ dataSource: any[];
128
183
  rowKey: import('../StkTable/types/index').UniqKey;
129
- colKey: import('../StkTable/types/index').UniqKey;
130
184
  emptyCellText: string;
131
185
  noDataFull: boolean;
132
186
  showNoData: boolean;
@@ -135,7 +189,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
135
189
  showOverflow: boolean;
136
190
  showTrHoverClass: boolean;
137
191
  headerDrag: boolean;
138
- rowClassName: Function;
192
+ rowClassName: (row: any, i: number) => string;
139
193
  colResizable: boolean;
140
194
  colMinWidth: number;
141
195
  }, {}>, {
@@ -1,5 +1,13 @@
1
1
  import { Component, VNode } from 'vue';
2
2
  type Sorter = boolean | Function;
3
+ export type CustomCellFunc<T extends Record<string, any>> = (props: {
4
+ row: T;
5
+ col: StkTableColumn<T>;
6
+ cellValue: any;
7
+ }) => VNode;
8
+ export type CustomHeaderCellFunc<T extends Record<string, any>> = (props: {
9
+ col: StkTableColumn<T>;
10
+ }) => VNode;
3
11
  export type StkTableColumn<T extends Record<string, any>> = {
4
12
  dataIndex: keyof T & string;
5
13
  title?: string;
@@ -16,8 +24,8 @@ export type StkTableColumn<T extends Record<string, any>> = {
16
24
  fixed?: 'left' | 'right' | null;
17
25
  /** private */ rowSpan?: number;
18
26
  /** private */ colSpan?: number;
19
- customCell?: Component | VNode;
20
- customHeaderCell?: Component | VNode;
27
+ customCell?: Component | VNode | CustomCellFunc<T>;
28
+ customHeaderCell?: Component | VNode | CustomHeaderCellFunc<T>;
21
29
  children?: StkTableColumn<T>[];
22
30
  };
23
31
  export type SortOption = Pick<StkTableColumn<any>, 'sorter' | 'dataIndex' | 'sortField' | 'sortType'>;
@@ -27,12 +35,14 @@ export type SortState = {
27
35
  sortType?: 'number' | 'string';
28
36
  };
29
37
  export type UniqKey = string | ((param: any) => string);
30
- export type StkProps = {
38
+ export type StkProps = Partial<{
31
39
  width: string;
32
40
  /** 最小表格宽度 */
33
41
  minWidth: string;
34
42
  /** 表格最大宽度*/
35
43
  maxWidth: string;
44
+ /** 是否使用 table-layout:fixed */
45
+ fixedMode: boolean;
36
46
  /** 是否隐藏表头 */
37
47
  headless: boolean;
38
48
  /** 主题,亮、暗 */
@@ -69,7 +79,7 @@ export type StkProps = {
69
79
  * 给行附加className<br>
70
80
  * FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
71
81
  */
72
- rowClassName: Function;
82
+ rowClassName: (row: any, i: number) => string;
73
83
  /**
74
84
  * 列宽是否可拖动<br>
75
85
  * **不要设置**列minWidth,**必须**设置width<br>
@@ -78,5 +88,5 @@ export type StkProps = {
78
88
  colResizable: boolean;
79
89
  /** 可拖动至最小的列宽 */
80
90
  colMinWidth: number;
81
- };
91
+ }>;
82
92
  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 {};