stk-table-vue 0.1.0 → 0.2.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.
@@ -41,6 +41,8 @@
41
41
  overflow: auto;
42
42
  display: flex;
43
43
  flex-direction: column;
44
+ /* border-left: 此方案用于减少cell 中border-left 的css选择。同时利于多级表头border-left问题。利于横向滚动border-left*/
45
+ border-left: 1px solid var(--border-color);
44
46
 
45
47
  /**深色模式 */
46
48
  &.dark {
@@ -100,87 +102,50 @@
100
102
  }
101
103
 
102
104
  &.border {
103
- .stk-table-main {
104
-
105
- th,
106
- td {
107
- background-image: var(--bg-border-right), var(--bg-border-bottom);
108
- }
109
105
 
110
- thead {
111
- tr {
112
- &:first-child th {
113
- background-image: var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom);
106
+ th,
107
+ td {
108
+ background-image: var(--bg-border-right), var(--bg-border-bottom);
109
+ }
114
110
 
115
- &:first-child {
116
- background-image: var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom), var(--bg-border-left);
117
- }
118
- }
111
+ thead {
112
+ tr {
113
+ &:first-child th {
114
+ background-image: var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom);
119
115
 
120
- th {
121
- &:first-child {
122
- background-image: var(--bg-border-right), var(--bg-border-bottom), var(--bg-border-left);
123
- }
124
- }
125
116
  }
126
- }
127
117
 
128
- tbody {
129
- td {
130
- &:first-child {
131
- background-image: var(--bg-border-right), var(--bg-border-bottom), var(--bg-border-left);
132
- }
133
- }
134
118
  }
135
119
  }
136
120
 
137
- &.virtual-x {
138
- .stk-table-main {
139
- .virtual-x-left {
140
- background: none;
141
- pointer-events: none;
142
- ;
143
- }
144
-
145
- .virtual-x-right {
146
- padding: 0;
147
- background: none;
148
- pointer-events: none;
149
- ;
150
- }
151
121
 
152
- thead tr:first-child .virtual-x-left+th {
153
- /* 横向虚拟滚动时,左侧第一个单元格加上border-left*/
154
- background-image: var(--bg-border-top), var(--bg-border-right), var(--bg-border-bottom), var(--bg-border-left);
155
- }
122
+ &.virtual-x {
123
+ .virtual-x-left {
124
+ background: none;
125
+ pointer-events: none;
126
+ }
156
127
 
157
- tr .virtual-x-left+th {
158
- background-image: var(--bg-border-right), var(--bg-border-bottom), var(--bg-border-left);
159
- }
128
+ .virtual-x-right {
129
+ padding: 0;
130
+ background: none;
131
+ pointer-events: none;
160
132
  }
133
+
161
134
  }
162
135
  }
163
136
 
164
137
  &.border-body-v {
165
- .stk-table-main {
166
- tbody {
167
- --bg-border-bottom: linear-gradient(transparent, transparent);
168
- }
138
+ tbody {
139
+ --bg-border-bottom: linear-gradient(transparent, transparent);
169
140
  }
170
141
  }
171
142
 
172
143
  &.stripe {
173
- .stk-table-main {
174
-
175
- /* 斑马纹*/
176
- tbody {
177
- tr:nth-child(odd) {
178
- background-color: var(--stripe-bgc);
179
- }
180
144
 
181
- tr:hover {
182
- background-color: var(--tr-hover-bgc);
183
- }
145
+ /* 斑马纹*/
146
+ tbody {
147
+ tr:nth-child(odd) {
148
+ background-color: var(--stripe-bgc);
184
149
  }
185
150
  }
186
151
  }
@@ -214,41 +179,78 @@
214
179
  font-size: 14px;
215
180
  box-sizing: border-box;
216
181
  padding: 0 var(--cell-padding-x);
182
+ }
217
183
 
218
- /*固定列阴影*/
219
- &.fixed-cell--left {
220
- --shadow-rotate: 90deg;
184
+ th {
185
+ color: var(--th-color);
186
+ background-color: var(--th-bgc);
187
+
188
+ &.sortable {
189
+ cursor: pointer;
190
+ }
221
191
 
222
- &.fixed-cell--shadow::after {
223
- right: -10px;
192
+ &.text-overflow {
193
+ .table-header-cell-wrapper {
194
+ white-space: nowrap;
195
+ overflow: hidden;
196
+ }
197
+
198
+ .table-header-title {
199
+ text-overflow: ellipsis;
200
+ overflow: hidden;
224
201
  }
225
202
  }
203
+ }
226
204
 
227
- &.fixed-cell--right {
228
- --shadow-rotate: -90deg;
205
+ td {
206
+ &.fixed-cell {
207
+ background-color: inherit;
208
+ /* 防止横向滚动后透明*/
209
+ }
210
+
211
+ &.highlight-cell {
212
+ animation: stkTableDim 2s linear;
213
+ }
229
214
 
230
- &.fixed-cell--shadow::after {
231
- left: -10px;
215
+ &.text-overflow {
216
+ .table-cell-wrapper {
217
+ white-space: nowrap;
218
+ overflow: hidden;
219
+ text-overflow: ellipsis;
232
220
  }
233
221
  }
222
+ }
223
+
224
+ /*固定列阴影-左*/
225
+ .fixed-cell--left {
226
+ --shadow-rotate: 90deg;
234
227
 
235
228
  &.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)),
229
+ right: -10px;
243
230
  }
244
231
  }
245
232
 
246
- th {
247
- color: var(--th-color);
233
+ /*固定列阴影-右*/
234
+ .fixed-cell--right {
235
+ --shadow-rotate: -90deg;
236
+
237
+ &.fixed-cell--shadow::after {
238
+ left: -10px;
239
+ }
248
240
  }
249
241
 
250
- thead {
242
+ /*固定列阴影*/
243
+ .fixed-cell--shadow::after {
244
+ content: '';
245
+ width: 10px;
246
+ height: 100%;
247
+ top: 0px;
248
+ position: absolute;
249
+ pointer-events: none;
250
+ background-image: linear-gradient(var(--shadow-rotate), var(--fixed-col-shadow-color-from), var(--fixed-col-shadow-color-to)),
251
+ }
251
252
 
253
+ thead {
252
254
  tr {
253
255
  height: var(--header-row-height);
254
256
 
@@ -256,101 +258,86 @@
256
258
  position: sticky;
257
259
  top: 0;
258
260
  }
261
+ }
262
+ }
259
263
 
260
- th {
261
- background-color: var(--th-bgc);
264
+ th {
262
265
 
263
- &.sortable {
264
- cursor: pointer;
265
- }
266
+ &:not(.sorter-desc):not(.sorter-asc):hover .table-header-sorter {
267
+ .arrow-up {
268
+ fill: var(--sort-arrow-hover-color);
269
+ }
266
270
 
267
- &.text-overflow {
268
- .table-header-cell-wrapper {
269
- white-space: nowrap;
270
- overflow: hidden;
271
+ .arrow-down {
272
+ fill: var(--sort-arrow-hover-color);
273
+ }
274
+ }
271
275
 
272
- .table-header-title {
273
- text-overflow: ellipsis;
274
- overflow: hidden;
275
- }
276
- }
277
- }
276
+ &.sorter-desc .table-header-sorter {
277
+ display: initial;
278
278
 
279
- &:not(.sorter-desc):not(.sorter-asc):hover .table-header-cell-wrapper .table-header-sorter {
280
- .arrow-up {
281
- fill: var(--sort-arrow-hover-color);
282
- }
279
+ .arrow-up {
280
+ fill: var(--sort-arrow-active-sub-color);
281
+ }
283
282
 
284
- .arrow-down {
285
- fill: var(--sort-arrow-hover-color);
286
- }
287
- }
283
+ .arrow-down {
284
+ fill: var(--sort-arrow-active-color);
285
+ }
286
+ }
287
+
288
+ &.sorter-asc .table-header-sorter {
289
+ display: initial;
288
290
 
289
- &.sorter-desc .table-header-cell-wrapper .table-header-sorter {
290
- display: initial;
291
+ .arrow-up {
292
+ fill: var(--sort-arrow-active-color);
293
+ }
291
294
 
292
- .arrow-up {
293
- fill: var(--sort-arrow-active-sub-color);
294
- }
295
+ .arrow-down {
296
+ fill: var(--sort-arrow-active-sub-color);
297
+ }
298
+ }
295
299
 
296
- .arrow-down {
297
- fill: var(--sort-arrow-active-color);
298
- }
299
- }
300
300
 
301
- &.sorter-asc .table-header-cell-wrapper .table-header-sorter {
302
- display: initial;
301
+ }
303
302
 
304
- .arrow-up {
305
- fill: var(--sort-arrow-active-color);
306
- }
303
+ .table-header-cell-wrapper {
304
+ max-width: 100%;
305
+ /*最大宽度不超过列宽*/
306
+ display: inline-flex;
307
+ align-items: center;
308
+ }
307
309
 
308
- .arrow-down {
309
- fill: var(--sort-arrow-active-sub-color);
310
- }
311
- }
310
+ .table-header-title {
311
+ overflow: hidden;
312
+ align-self: flex-start;
313
+ }
312
314
 
313
- .table-header-cell-wrapper {
314
- max-width: 100%;
315
- /*最大宽度不超过列宽*/
316
- display: inline-flex;
317
- align-items: center;
318
-
319
- .table-header-title {
320
- overflow: hidden;
321
- align-self: flex-start;
322
- }
323
-
324
- .table-header-sorter {
325
- flex-shrink: 0;
326
- margin-left: 4px;
327
- width: 16px;
328
- height: 16px;
329
- display: none;
330
-
331
- .arrow-up,
332
- .arrow-down {
333
- fill: var(--sort-arrow-color);
334
- }
335
- }
336
-
337
- .table-header-resizer {
338
- position: absolute;
339
- top: 0;
340
- bottom: 0;
341
- cursor: col-resize;
342
- width: var(--resize-handle-width);
343
-
344
- &.left {
345
- left: 0;
346
- }
347
-
348
- &.right {
349
- right: 0;
350
- }
351
- }
352
- }
353
- }
315
+ .table-header-sorter {
316
+ flex-shrink: 0;
317
+ margin-left: 4px;
318
+ width: 16px;
319
+ height: 16px;
320
+ display: none;
321
+
322
+ .arrow-up,
323
+ .arrow-down {
324
+ fill: var(--sort-arrow-color);
325
+ }
326
+ }
327
+
328
+ .table-header-resizer {
329
+ position: absolute;
330
+ top: 0;
331
+ bottom: 0;
332
+ cursor: col-resize;
333
+ width: var(--resize-handle-width);
334
+
335
+ &.left {
336
+ left: 0;
337
+ }
338
+
339
+ &.right {
340
+ right: 0;
354
341
  }
355
342
  }
356
343
 
@@ -377,65 +364,9 @@
377
364
  &.active {
378
365
  background-color: var(--tr-active-bgc);
379
366
  }
380
-
381
- td {
382
- &.fixed-cell {
383
- background-color: inherit;
384
- /* 防止横向滚动后透明*/
385
- }
386
-
387
- &.highlight-cell {
388
- animation: stkTableDim 2s linear;
389
- }
390
-
391
- &.text-overflow {
392
- .table-cell-wrapper {
393
- white-space: nowrap;
394
- overflow: hidden;
395
- text-overflow: ellipsis;
396
- }
397
- }
398
-
399
- /* &.perch-td {
400
- padding: 0;
401
- height: 0;
402
- &.top {
403
- background-image: repeating-linear-gradient(
404
- 180deg,
405
- transparent 0,
406
- transparent var(--row-height),
407
- var(--border-color) var(--row-height),
408
- var(--border-color) calc(var(--row-height) + 1px)
409
- ),
410
- var(--bg-border-right);
411
- }
412
- &.bottom {
413
- background-image: repeating-linear-gradient(
414
- 0deg,
415
- transparent 0,
416
- transparent var(--row-height),
417
- var(--border-color) var(--row-height),
418
- var(--border-color) calc(var(--row-height) + 1px)
419
- ),
420
- var(--bg-border-right);
421
- }
422
- }*/
423
- }
424
367
  }
425
368
 
426
369
  }
427
-
428
- /* tr .fixed-cell--left{
429
- border: 1px solid red;
430
- &::after{
431
- content: '';
432
- width: 20px;
433
- position: absolute;
434
- right: -20px;
435
- top: 0px;
436
- background: rgba(255,255,255,0.5);
437
- }
438
- } */
439
370
  }
440
371
 
441
372
  .stk-table-no-data {
@@ -445,7 +376,6 @@
445
376
  font-size: 14px;
446
377
  position: sticky;
447
378
  left: 0px;
448
- border-left: var(--border-width) solid var(--border-color);
449
379
  border-right: var(--border-width) solid var(--border-color);
450
380
  border-bottom: var(--border-width) solid var(--border-color);
451
381
  display: flex;
@@ -460,47 +390,38 @@
460
390
 
461
391
  /**虚拟滚动模式 */
462
392
  &.virtual {
463
- .stk-table-main {
464
- thead {
465
- tr {
466
- th {
467
-
468
- /* 为不影响布局,表头行高要定死*/
469
- .table-header-cell-wrapper {
470
- overflow: hidden;
471
- max-height: var(--header-row-height);
472
- }
473
- }
474
- }
475
- }
476
393
 
477
- tbody {
478
- position: relative;
394
+ /* 为不影响布局,表头行高要定死*/
395
+ .table-header-cell-wrapper {
396
+ overflow: hidden;
397
+ max-height: var(--header-row-height);
398
+ }
479
399
 
480
- tr {
481
- &.padding-top-tr td {
482
- height: 0;
483
- }
400
+ tbody {
401
+ position: relative;
402
+
403
+ tr {
484
404
 
485
- td {
486
- height: var(--row-height);
487
- line-height: 1;
405
+ td {
406
+ height: var(--row-height);
407
+ line-height: 1;
488
408
 
489
- .table-cell-wrapper {
490
- max-height: var(--row-height);
491
- overflow: hidden;
492
- }
409
+ .table-cell-wrapper {
410
+ max-height: var(--row-height);
411
+ overflow: hidden;
493
412
  }
494
413
  }
495
414
  }
496
415
  }
416
+
417
+ .padding-top-tr td {
418
+ height: 0;
419
+ }
497
420
  }
498
421
 
499
422
  &.virtual-x {
500
- .stk-table-main {
501
- .virtual-x-left {
502
- padding: 0;
503
- }
423
+ .virtual-x-left {
424
+ padding: 0;
504
425
  }
505
426
  }
506
427
  }
@@ -0,0 +1,91 @@
1
+ import { ref, Ref } from 'vue';
2
+ import { StkTableColumn } from './types';
3
+
4
+ type Params<T extends Record<string, any>> = {
5
+ props: any;
6
+ tableHeaderLast: Ref<StkTableColumn<T>[]>;
7
+ tableContainer: Ref<HTMLDivElement | undefined>;
8
+ };
9
+
10
+ /**
11
+ * 固定列处理
12
+ * @returns
13
+ */
14
+ export function useFixedCol<DT extends Record<string, any>>({ props, tableHeaderLast, tableContainer }: Params<DT>) {
15
+ /** 固定列阴影 */
16
+ const fixedShadow = ref<{
17
+ /** 是否展示左侧固定列阴影 */
18
+ showL: boolean;
19
+ /** 是否展示右侧固定列阴影 */
20
+ showR: boolean;
21
+ }>({
22
+ showL: false,
23
+ showR: false,
24
+ });
25
+ /** 保存需要出现阴影的列 */
26
+ let fixedShadowCols: StkTableColumn<DT>[] = [];
27
+
28
+ /** 处理固定列阴影 */
29
+ function dealFixedColShadow() {
30
+ if (!props.fixedColShadow) return;
31
+ fixedShadowCols = [];
32
+ // 找到最右边的固定列 findLast
33
+ let lastLeftCol = null;
34
+ for (let i = tableHeaderLast.value.length - 1; i > 0; i--) {
35
+ const col = tableHeaderLast.value[i];
36
+ if (col.fixed === 'left') {
37
+ lastLeftCol = col;
38
+ break;
39
+ }
40
+ }
41
+ // 处理多级表头列阴影
42
+ let node: any = { __PARENT__: lastLeftCol };
43
+ while ((node = node.__PARENT__)) {
44
+ if (node.fixed) {
45
+ fixedShadowCols.push(node);
46
+ }
47
+ }
48
+
49
+ // 找到最左边的固定列
50
+ const lastRightCol = tableHeaderLast.value.find(it => it.fixed === 'right');
51
+ node = { __PARENT__: lastRightCol };
52
+ while ((node = node.__PARENT__)) {
53
+ if (node.fixed) {
54
+ fixedShadowCols.push(node);
55
+ }
56
+ }
57
+ }
58
+
59
+ /** 固定列class */
60
+ function getFixedColClass(col: StkTableColumn<DT>): Record<string, boolean> {
61
+ const { showR, showL } = fixedShadow.value;
62
+ const showShadow =
63
+ props.fixedColShadow &&
64
+ col.fixed &&
65
+ ((showL && col.fixed === 'left') || (showR && col.fixed === 'right')) &&
66
+ fixedShadowCols.includes(col);
67
+ const classObj = {
68
+ 'fixed-cell': col.fixed,
69
+ ['fixed-cell--' + col.fixed]: col.fixed,
70
+ 'fixed-cell--shadow': showShadow,
71
+ };
72
+ return classObj;
73
+ }
74
+
75
+ /** 滚动条变化时,更新需要展示阴影的列 */
76
+ function updateFixedShadow() {
77
+ if (!props.fixedColShadow) return;
78
+ const { clientWidth, scrollWidth, scrollLeft } = tableContainer.value as HTMLDivElement;
79
+ fixedShadow.value.showL = Boolean(scrollLeft);
80
+ fixedShadow.value.showR = Math.abs(scrollWidth - scrollLeft - clientWidth) > 0.5;
81
+ }
82
+
83
+ return {
84
+ /** 固定列class */
85
+ getFixedColClass,
86
+ /** 处理固定列阴影 */
87
+ dealFixedColShadow,
88
+ /** 滚动条变化时,更新需要展示阴影的列 */
89
+ updateFixedShadow,
90
+ };
91
+ }