stk-table-vue 0.0.2 → 0.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.
@@ -8,6 +8,7 @@
8
8
  .stk-table {
9
9
  /* contain: strict;*/
10
10
  --row-height: 28px;
11
+ --header-row-height: var(--row-height);
11
12
  --cell-padding-x: 8px;
12
13
  --resize-handle-width: 4px;
13
14
  --border-color: #e8e8f4;
@@ -32,6 +33,10 @@
32
33
  /** 列宽拖动指示器颜色 */
33
34
  --col-resize-indicator-color: #87879c;
34
35
 
36
+ /** 固定列阴影颜色 */
37
+ --fixed-col-shadow-color-from: rgba(0, 0, 0, 0.1);
38
+ --fixed-col-shadow-color-to: rgba(0, 0, 0, 0);
39
+
35
40
  position: relative;
36
41
  overflow: auto;
37
42
  display: flex;
@@ -58,20 +63,14 @@
58
63
 
59
64
  --col-resize-indicator-color: #5d6064;
60
65
 
66
+ --fixed-col-shadow-color-from: rgba(135, 135, 156, 0.1);
67
+ --fixed-col-shadow-color-to: rgba(135, 135, 156, 0);
68
+
61
69
  /* background-color: var(--table-bgc); */
62
70
  /* ⭐这里加background-color会导致表格出滚动白屏*/
63
71
  color: #d1d1e0;
64
72
  }
65
73
 
66
- /*.stk-table-fixed-left-col-box-shadow {
67
- position: sticky;
68
- left: 0;
69
- top: 0;
70
- height: 100%;
71
- box-shadow: 0 0 10px;
72
- z-index: 1;
73
- pointer-events: none;
74
- }*/
75
74
  &.headless {
76
75
  border-top: 1px solid var(--border-color);
77
76
  }
@@ -139,13 +138,17 @@
139
138
  .stk-table-main {
140
139
  .virtual-x-left {
141
140
  background: none;
142
- pointer-events: none;;
141
+ pointer-events: none;
142
+ ;
143
143
  }
144
+
144
145
  .virtual-x-right {
145
146
  padding: 0;
146
147
  background: none;
147
- pointer-events: none;;
148
+ pointer-events: none;
149
+ ;
148
150
  }
151
+
149
152
  thead tr:first-child .virtual-x-left+th {
150
153
  /* 横向虚拟滚动时,左侧第一个单元格加上border-left*/
151
154
  background-image: var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom), var(--bg-border-left);
@@ -208,10 +211,36 @@
208
211
  th,
209
212
  td {
210
213
  z-index: 1;
211
- height: var(--row-height);
212
214
  font-size: 14px;
213
215
  box-sizing: border-box;
214
216
  padding: 0 var(--cell-padding-x);
217
+
218
+ /*固定列阴影*/
219
+ &.fixed-cell--left {
220
+ --shadow-rotate: 90deg;
221
+
222
+ &.fixed-cell--shadow::after {
223
+ right: -10px;
224
+ }
225
+ }
226
+
227
+ &.fixed-cell--right {
228
+ --shadow-rotate: -90deg;
229
+
230
+ &.fixed-cell--shadow::after {
231
+ left: -10px;
232
+ }
233
+ }
234
+
235
+ &.fixed-cell--shadow::after {
236
+ content: '';
237
+ width: 10px;
238
+ height: 100%;
239
+ top: 0px;
240
+ position: absolute;
241
+ pointer-events: none;
242
+ background-image: linear-gradient(var(--shadow-rotate), var(--fixed-col-shadow-color-from), var(--fixed-col-shadow-color-to)),
243
+ }
215
244
  }
216
245
 
217
246
  th {
@@ -219,7 +248,10 @@
219
248
  }
220
249
 
221
250
  thead {
251
+
222
252
  tr {
253
+ height: var(--header-row-height);
254
+
223
255
  &:first-child th {
224
256
  position: sticky;
225
257
  top: 0;
@@ -245,11 +277,11 @@
245
277
  }
246
278
 
247
279
  &:not(.sorter-desc):not(.sorter-asc):hover .table-header-cell-wrapper .table-header-sorter {
248
- #arrow-up {
280
+ .arrow-up {
249
281
  fill: var(--sort-arrow-hover-color);
250
282
  }
251
283
 
252
- #arrow-down {
284
+ .arrow-down {
253
285
  fill: var(--sort-arrow-hover-color);
254
286
  }
255
287
  }
@@ -257,11 +289,11 @@
257
289
  &.sorter-desc .table-header-cell-wrapper .table-header-sorter {
258
290
  display: initial;
259
291
 
260
- #arrow-up {
292
+ .arrow-up {
261
293
  fill: var(--sort-arrow-active-sub-color);
262
294
  }
263
295
 
264
- #arrow-down {
296
+ .arrow-down {
265
297
  fill: var(--sort-arrow-active-color);
266
298
  }
267
299
  }
@@ -269,11 +301,11 @@
269
301
  &.sorter-asc .table-header-cell-wrapper .table-header-sorter {
270
302
  display: initial;
271
303
 
272
- #arrow-up {
304
+ .arrow-up {
273
305
  fill: var(--sort-arrow-active-color);
274
306
  }
275
307
 
276
- #arrow-down {
308
+ .arrow-down {
277
309
  fill: var(--sort-arrow-active-sub-color);
278
310
  }
279
311
  }
@@ -296,8 +328,8 @@
296
328
  height: 16px;
297
329
  display: none;
298
330
 
299
- #arrow-up,
300
- #arrow-down {
331
+ .arrow-up,
332
+ .arrow-down {
301
333
  fill: var(--sort-arrow-color);
302
334
  }
303
335
  }
@@ -326,8 +358,9 @@
326
358
 
327
359
  tr {
328
360
  background-color: var(--td-bgc);
329
- /* td inherit tr bgc*/
361
+ height: var(--row-height);
330
362
 
363
+ /* td inherit tr bgc*/
331
364
  &.highlight-row {
332
365
  animation: stkTableDim 2s linear;
333
366
  }
@@ -435,7 +468,7 @@
435
468
  /* 为不影响布局,表头行高要定死*/
436
469
  .table-header-cell-wrapper {
437
470
  overflow: hidden;
438
- max-height: var(--row-height);
471
+ max-height: var(--header-row-height);
439
472
  }
440
473
  }
441
474
  }
@@ -38,12 +38,25 @@ export type StkTableColumn<T extends Record<string, any>> = {
38
38
  fixed?: 'left' | 'right' | null;
39
39
  /** private */ rowSpan?: number;
40
40
  /** private */ colSpan?: number;
41
- /**自定义 td 渲染内容 */
41
+ /**
42
+ * 自定义 td 渲染内容。
43
+ *
44
+ * 组件prop入参:
45
+ * - props.row 一行的记录。
46
+ * - props.col 列配置
47
+ */
42
48
  customCell?: Component | VNode | CustomCellFunc<T>;
43
- /** 自定义 th 渲染内容 */
49
+ /**
50
+ * 自定义 th 渲染内容
51
+ *
52
+ * 组件prop入参:
53
+ * - props.col 列配置
54
+ */
44
55
  customHeaderCell?: Component | VNode | CustomHeaderCellFunc<T>;
45
56
  /** 二级表头 */
46
57
  children?: StkTableColumn<T>[];
58
+ /** 父节点引用 */
59
+ __PARENT__?: StkTableColumn<T> | null;
47
60
  };
48
61
 
49
62
  export type SortOption = Pick<StkTableColumn<any>, 'sorter' | 'dataIndex' | 'sortField' | 'sortType'>;
@@ -1,19 +1,26 @@
1
1
  import { Ref, onBeforeUnmount, onMounted } from 'vue';
2
+ import { StkTableColumn } from './types';
2
3
  import { VirtualScrollStore, VirtualScrollXStore } from './useVirtualScroll';
3
4
 
4
- const ARROW_CODES = ['ArrowUp', 'ArrowRight', 'ArrowDown', 'ArrowLeft'];
5
+ /** 翻页按键 */
6
+ const SCROLL_CODES = ['ArrowUp', 'ArrowRight', 'ArrowDown', 'ArrowLeft', 'PageUp', 'PageDown'] as const;
5
7
 
6
- type Options = {
7
- scrollTo: (x: number | null, y: number | null) => void;
8
+ type Options<DT extends Record<string, any>> = {
9
+ props: any;
10
+ scrollTo: (y: number | null, x: number | null) => void;
8
11
  virtualScroll: Ref<VirtualScrollStore>;
9
12
  virtualScrollX: Ref<VirtualScrollXStore>;
13
+ tableHeaders: Ref<StkTableColumn<DT>[][]>;
10
14
  };
11
15
  /**
12
16
  * 按下键盘箭头滚动。只有悬浮在表体上才能生效键盘。
13
17
  *
14
18
  * 在低版本浏览器中,虚拟滚动时,使用键盘滚动,等选中的行消失在视口外时,滚动会失效。
15
19
  */
16
- export function useKeyboardArrowScroll(targetElement: Ref<HTMLElement | undefined>, { scrollTo, virtualScroll, virtualScrollX }: Options) {
20
+ export function useKeyboardArrowScroll<DT extends Record<string, any>>(
21
+ targetElement: Ref<HTMLElement | undefined>,
22
+ { props, scrollTo, virtualScroll, virtualScrollX, tableHeaders }: Options<DT>,
23
+ ) {
17
24
  /** 检测鼠标是否悬浮在表格体上 */
18
25
  let isMouseOver = false;
19
26
 
@@ -33,20 +40,27 @@ export function useKeyboardArrowScroll(targetElement: Ref<HTMLElement | undefine
33
40
 
34
41
  /** 键盘按下事件 */
35
42
  function handleKeydown(e: KeyboardEvent) {
36
- if (!ARROW_CODES.includes(e.code)) return;
43
+ if (!SCROLL_CODES.includes(e.code as any)) return;
37
44
  if (!isMouseOver) return; // 不悬浮还是要触发键盘事件的
38
45
  e.preventDefault(); // 不触发键盘默认的箭头事件
39
46
 
40
- const { scrollTop, rowHeight } = virtualScroll.value;
47
+ const { scrollTop, rowHeight, pageSize } = virtualScroll.value;
41
48
  const { scrollLeft } = virtualScrollX.value;
42
- if (e.code === ARROW_CODES[0]) {
49
+ const { headless, headerRowHeight } = props;
50
+ /**表头高度 */
51
+ const headerHeight = headless ? 0 : tableHeaders.value.length * (headerRowHeight || rowHeight);
52
+ if (e.code === SCROLL_CODES[0]) {
43
53
  scrollTo(scrollTop - rowHeight, null);
44
- } else if (e.code === ARROW_CODES[1]) {
54
+ } else if (e.code === SCROLL_CODES[1]) {
45
55
  scrollTo(null, scrollLeft + rowHeight);
46
- } else if (e.code === ARROW_CODES[2]) {
56
+ } else if (e.code === SCROLL_CODES[2]) {
47
57
  scrollTo(scrollTop + rowHeight, null);
48
- } else if (e.code === ARROW_CODES[3]) {
58
+ } else if (e.code === SCROLL_CODES[3]) {
49
59
  scrollTo(null, scrollLeft - rowHeight);
60
+ } else if (e.code === SCROLL_CODES[4]) {
61
+ scrollTo(scrollTop - rowHeight * pageSize - headerHeight, null);
62
+ } else if (e.code === SCROLL_CODES[5]) {
63
+ scrollTo(scrollTop + rowHeight * pageSize - headerHeight, null);
50
64
  }
51
65
  }
52
66
 
@@ -88,7 +88,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({ tableContaine
88
88
 
89
89
  const virtualX_on = computed(() => {
90
90
  return (
91
- props.virtualX && tableHeaderLast.value.reduce((sum, col) => (sum += getCalcWidth(col)), 0) > virtualScrollX.value.containerWidth * 1.5
91
+ props.virtualX && tableHeaderLast.value.reduce((sum, col) => (sum += getCalcWidth(col)), 0) > virtualScrollX.value.containerWidth + 100
92
92
  );
93
93
  });
94
94
 
package/src/vite-env.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="vite/client" />
1
2
  declare module '*.vue' {
2
3
  import { DefineComponent } from 'vue';
3
4
  const component: DefineComponent<object, object, any>;