stk-table-vue 0.8.14 → 0.9.0-beta.1
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 +172 -172
- package/lib/src/StkTable/StkTable.vue.d.ts +19 -1
- package/lib/src/StkTable/useScrollbar.d.ts +57 -0
- package/lib/src/StkTable/utils/index.d.ts +7 -0
- package/lib/stk-table-vue.js +396 -205
- package/lib/style.css +42 -1
- package/package.json +74 -74
- package/src/StkTable/StkTable.vue +1730 -1665
- package/src/StkTable/components/DragHandle.vue +9 -9
- package/src/StkTable/components/SortIcon.vue +6 -6
- package/src/StkTable/components/TriangleIcon.vue +3 -3
- package/src/StkTable/const.ts +50 -50
- package/src/StkTable/index.ts +4 -4
- package/src/StkTable/style.less +627 -578
- package/src/StkTable/types/highlightDimOptions.ts +26 -26
- package/src/StkTable/types/index.ts +297 -297
- package/src/StkTable/useAutoResize.ts +91 -91
- package/src/StkTable/useColResize.ts +216 -216
- package/src/StkTable/useFixedCol.ts +150 -150
- package/src/StkTable/useFixedStyle.ts +75 -75
- package/src/StkTable/useGetFixedColPosition.ts +65 -65
- package/src/StkTable/useHighlight.ts +257 -257
- package/src/StkTable/useKeyboardArrowScroll.ts +112 -112
- package/src/StkTable/useMaxRowSpan.ts +55 -55
- package/src/StkTable/useMergeCells.ts +120 -120
- package/src/StkTable/useRowExpand.ts +88 -88
- package/src/StkTable/useScrollRowByRow.ts +113 -113
- package/src/StkTable/useScrollbar.ts +187 -0
- package/src/StkTable/useThDrag.ts +102 -102
- package/src/StkTable/useTrDrag.ts +113 -113
- package/src/StkTable/useTree.ts +161 -161
- package/src/StkTable/useVirtualScroll.ts +494 -494
- package/src/StkTable/utils/constRefUtils.ts +29 -29
- package/src/StkTable/utils/index.ts +287 -258
- package/src/StkTable/utils/useTriggerRef.ts +33 -33
- package/src/VirtualTree.vue +622 -622
- package/src/VirtualTreeSelect.vue +367 -367
- package/src/vite-env.d.ts +10 -10
|
@@ -1,1665 +1,1730 @@
|
|
|
1
|
-
<!-- eslint-disable vue/attribute-hyphenation -->
|
|
2
|
-
<template>
|
|
3
|
-
<div
|
|
4
|
-
ref="tableContainerRef"
|
|
5
|
-
class="stk-table"
|
|
6
|
-
:class="{
|
|
7
|
-
virtual,
|
|
8
|
-
'virtual-x': virtualX,
|
|
9
|
-
'vt-on': virtual_on,
|
|
10
|
-
light: theme === 'light',
|
|
11
|
-
dark: theme === 'dark',
|
|
12
|
-
headless,
|
|
13
|
-
'is-col-resizing': isColResizing,
|
|
14
|
-
'col-resizable': props.colResizable,
|
|
15
|
-
bordered: props.bordered,
|
|
16
|
-
[`bordered-${props.bordered}`]: typeof props.bordered === 'string',
|
|
17
|
-
stripe: props.stripe,
|
|
18
|
-
'cell-hover': props.cellHover,
|
|
19
|
-
'cell-active': props.cellActive,
|
|
20
|
-
'row-hover': props.rowHover,
|
|
21
|
-
'row-active': rowActiveProp.enabled,
|
|
22
|
-
'text-overflow': props.showOverflow,
|
|
23
|
-
'header-text-overflow': props.showHeaderOverflow,
|
|
24
|
-
'fixed-relative-mode': isRelativeMode,
|
|
25
|
-
'auto-row-height': props.autoRowHeight,
|
|
26
|
-
'scroll-row-by-row': isSRBRActive,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
'--
|
|
31
|
-
'--
|
|
32
|
-
'--highlight-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<table
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
<
|
|
107
|
-
<
|
|
108
|
-
<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
<
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
</
|
|
184
|
-
|
|
185
|
-
<
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
import {
|
|
234
|
-
import
|
|
235
|
-
import
|
|
236
|
-
import
|
|
237
|
-
import {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
*
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
*
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
* -
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
*
|
|
381
|
-
* -
|
|
382
|
-
*/
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
*
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*/
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
const
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
});
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
);
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
if (
|
|
957
|
-
col
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
function
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
colKey
|
|
1103
|
-
col.
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
if (
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
const
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
function
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
if (
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
const
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
function
|
|
1301
|
-
const
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
emits('
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
function
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
/**
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
const {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
}
|
|
1391
|
-
if
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
const
|
|
1434
|
-
|
|
1435
|
-
if (
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
if (
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
if (
|
|
1485
|
-
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
/**
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1492
|
-
*
|
|
1493
|
-
* @param
|
|
1494
|
-
* @param option.
|
|
1495
|
-
* @param option.
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
/**
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
*
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
*
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
*
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
*
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
*
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
*
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
*
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
*
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1
|
+
<!-- eslint-disable vue/attribute-hyphenation -->
|
|
2
|
+
<template>
|
|
3
|
+
<div
|
|
4
|
+
ref="tableContainerRef"
|
|
5
|
+
class="stk-table"
|
|
6
|
+
:class="{
|
|
7
|
+
virtual,
|
|
8
|
+
'virtual-x': virtualX,
|
|
9
|
+
'vt-on': virtual_on,
|
|
10
|
+
light: theme === 'light',
|
|
11
|
+
dark: theme === 'dark',
|
|
12
|
+
headless,
|
|
13
|
+
'is-col-resizing': isColResizing,
|
|
14
|
+
'col-resizable': props.colResizable,
|
|
15
|
+
bordered: props.bordered,
|
|
16
|
+
[`bordered-${props.bordered}`]: typeof props.bordered === 'string',
|
|
17
|
+
stripe: props.stripe,
|
|
18
|
+
'cell-hover': props.cellHover,
|
|
19
|
+
'cell-active': props.cellActive,
|
|
20
|
+
'row-hover': props.rowHover,
|
|
21
|
+
'row-active': rowActiveProp.enabled,
|
|
22
|
+
'text-overflow': props.showOverflow,
|
|
23
|
+
'header-text-overflow': props.showHeaderOverflow,
|
|
24
|
+
'fixed-relative-mode': isRelativeMode,
|
|
25
|
+
'auto-row-height': props.autoRowHeight,
|
|
26
|
+
'scroll-row-by-row': isSRBRActive,
|
|
27
|
+
'scrollbar-on': scrollbarOptions.enabled,
|
|
28
|
+
}"
|
|
29
|
+
:style="{
|
|
30
|
+
'--row-height': props.autoRowHeight ? void 0 : virtualScroll.rowHeight + 'px',
|
|
31
|
+
'--header-row-height': props.headerRowHeight + 'px',
|
|
32
|
+
'--highlight-duration': props.highlightConfig.duration && props.highlightConfig.duration + 's',
|
|
33
|
+
'--highlight-timing-function': highlightSteps ? `steps(${highlightSteps})` : '',
|
|
34
|
+
'--sb-width': `${scrollbarOptions.width}px`,
|
|
35
|
+
'--sb-height': `${scrollbarOptions.height}px`,
|
|
36
|
+
}"
|
|
37
|
+
@scroll="onTableScroll"
|
|
38
|
+
@wheel="onTableWheel"
|
|
39
|
+
>
|
|
40
|
+
<div v-if="SRBRTotalHeight" class="row-by-row-table-height" :style="`height: ${SRBRTotalHeight}px`"></div>
|
|
41
|
+
|
|
42
|
+
<div v-if="colResizable" ref="colResizeIndicatorRef" class="column-resize-indicator"></div>
|
|
43
|
+
|
|
44
|
+
<div style="display: flex">
|
|
45
|
+
<div style="display: flex; flex-direction: column">
|
|
46
|
+
<table
|
|
47
|
+
class="stk-table-main"
|
|
48
|
+
:style="{ width, minWidth, maxWidth }"
|
|
49
|
+
:class="{
|
|
50
|
+
'fixed-mode': props.fixedMode,
|
|
51
|
+
}"
|
|
52
|
+
@dragover="onTrDragOver"
|
|
53
|
+
@dragenter="onTrDragEnter"
|
|
54
|
+
@dragend="onTrDragEnd"
|
|
55
|
+
@click="onRowClick"
|
|
56
|
+
@dblclick="onRowDblclick"
|
|
57
|
+
@contextmenu="onRowMenu"
|
|
58
|
+
@mouseover="onTrMouseOver"
|
|
59
|
+
>
|
|
60
|
+
<thead v-if="!headless">
|
|
61
|
+
<tr v-for="(row, rowIndex) in tableHeaders" :key="rowIndex" @contextmenu="onHeaderMenu($event)">
|
|
62
|
+
<th
|
|
63
|
+
v-if="virtualX_on"
|
|
64
|
+
class="vt-x-left"
|
|
65
|
+
:style="`min-width:${virtualScrollX.offsetLeft}px;width:${virtualScrollX.offsetLeft}px`"
|
|
66
|
+
></th>
|
|
67
|
+
<th
|
|
68
|
+
v-for="(col, colIndex) in virtualX_on && rowIndex === tableHeaders.length - 1 ? virtualX_columnPart : row"
|
|
69
|
+
:key="colKeyGen(col)"
|
|
70
|
+
v-bind="getTHProps(col)"
|
|
71
|
+
@click="e => onHeaderCellClick(e, col)"
|
|
72
|
+
@dragstart="headerDrag ? onThDragStart : void 0"
|
|
73
|
+
@drop="headerDrag ? onThDrop : void 0"
|
|
74
|
+
@dragover="headerDrag ? onThDragOver : void 0"
|
|
75
|
+
>
|
|
76
|
+
<div
|
|
77
|
+
v-if="colResizeOn(col) && colIndex > 0"
|
|
78
|
+
class="table-header-resizer left"
|
|
79
|
+
@mousedown="onThResizeMouseDown($event, col, true)"
|
|
80
|
+
></div>
|
|
81
|
+
<div class="table-header-cell-wrapper" :style="`--row-span:${virtualX_on ? 1 : col.__R_SP__}`">
|
|
82
|
+
<component
|
|
83
|
+
:is="col.customHeaderCell"
|
|
84
|
+
v-if="col.customHeaderCell"
|
|
85
|
+
:col="col"
|
|
86
|
+
:colIndex="colIndex"
|
|
87
|
+
:rowIndex="rowIndex"
|
|
88
|
+
/>
|
|
89
|
+
<template v-else>
|
|
90
|
+
<slot name="tableHeader" :col="col">
|
|
91
|
+
<span class="table-header-title">{{ col.title }}</span>
|
|
92
|
+
</slot>
|
|
93
|
+
</template>
|
|
94
|
+
<SortIcon v-if="col.sorter" class="table-header-sorter" />
|
|
95
|
+
</div>
|
|
96
|
+
<div v-if="colResizeOn(col)" class="table-header-resizer right" @mousedown="onThResizeMouseDown($event, col)"></div>
|
|
97
|
+
</th>
|
|
98
|
+
<th
|
|
99
|
+
v-if="virtualX_on"
|
|
100
|
+
class="vt-x-right"
|
|
101
|
+
:style="`min-width:${virtualX_offsetRight}px;width:${virtualX_offsetRight}px`"
|
|
102
|
+
></th>
|
|
103
|
+
</tr>
|
|
104
|
+
</thead>
|
|
105
|
+
|
|
106
|
+
<tbody class="stk-tbody-main" @click="onCellClick" @mousedown="onCellMouseDown" @mouseover="onCellMouseOver">
|
|
107
|
+
<tr v-if="virtual_on && !isSRBRActive" :style="`height:${virtualScroll.offsetTop}px`" class="padding-top-tr">
|
|
108
|
+
<td v-if="virtualX_on && fixedMode && headless" class="vt-x-left"></td>
|
|
109
|
+
<template v-if="fixedMode && headless">
|
|
110
|
+
<td
|
|
111
|
+
v-for="col in virtualX_columnPart"
|
|
112
|
+
:key="colKeyGen(col)"
|
|
113
|
+
:style="cellStyleMap[TagType.TD].get(colKeyGen(col))"
|
|
114
|
+
></td>
|
|
115
|
+
</template>
|
|
116
|
+
</tr>
|
|
117
|
+
<tr
|
|
118
|
+
v-for="(row, rowIndex) in virtual_dataSourcePart"
|
|
119
|
+
ref="trRef"
|
|
120
|
+
:key="rowKeyGen(row)"
|
|
121
|
+
v-bind="getTRProps(row, rowIndex)"
|
|
122
|
+
@drop="onTrDrop($event, getRowIndex(rowIndex))"
|
|
123
|
+
@mouseleave="onTrMouseLeave"
|
|
124
|
+
>
|
|
125
|
+
<td v-if="virtualX_on" class="vt-x-left"></td>
|
|
126
|
+
<td v-if="row && row.__EXP_R__" :colspan="virtualX_columnPart.length">
|
|
127
|
+
<div class="table-cell-wrapper">
|
|
128
|
+
<slot name="expand" :row="row.__EXP_R__" :col="row.__EXP_C__">
|
|
129
|
+
{{ row.__EXP_R__?.[row.__EXP_C__!.dataIndex] ?? '' }}
|
|
130
|
+
</slot>
|
|
131
|
+
</div>
|
|
132
|
+
</td>
|
|
133
|
+
<template v-else>
|
|
134
|
+
<template v-for="(col, colIndex) in virtualX_columnPart">
|
|
135
|
+
<td
|
|
136
|
+
v-if="!hiddenCellMap[rowKeyGen(row)]?.has(colKeyGen(col))"
|
|
137
|
+
:key="colKeyGen(col)"
|
|
138
|
+
v-bind="getTDProps(row, col, rowIndex, colIndex)"
|
|
139
|
+
@mouseenter="onCellMouseEnter"
|
|
140
|
+
@mouseleave="onCellMouseLeave"
|
|
141
|
+
>
|
|
142
|
+
<component
|
|
143
|
+
:is="col.customCell"
|
|
144
|
+
v-if="col.customCell"
|
|
145
|
+
class="table-cell-wrapper"
|
|
146
|
+
:col="col"
|
|
147
|
+
:row="row"
|
|
148
|
+
:rowIndex="getRowIndex(rowIndex)"
|
|
149
|
+
:colIndex="colIndex"
|
|
150
|
+
:cellValue="row && row[col.dataIndex]"
|
|
151
|
+
:expanded="row && row.__EXP__"
|
|
152
|
+
:tree-expanded="row && row.__T_EXP__"
|
|
153
|
+
>
|
|
154
|
+
<template #stkFoldIcon>
|
|
155
|
+
<TriangleIcon @click="triangleClick($event, row, col)"></TriangleIcon>
|
|
156
|
+
</template>
|
|
157
|
+
<template #stkDragIcon>
|
|
158
|
+
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
159
|
+
</template>
|
|
160
|
+
</component>
|
|
161
|
+
<div
|
|
162
|
+
v-else
|
|
163
|
+
class="table-cell-wrapper"
|
|
164
|
+
:title="col.type !== 'seq' ? row?.[col.dataIndex] : ''"
|
|
165
|
+
:style="col.type === 'tree-node' && row.__T_LV__ ? `padding-left:${row.__T_LV__ * 16}px` : ''"
|
|
166
|
+
>
|
|
167
|
+
<template v-if="col.type === 'seq'">
|
|
168
|
+
{{ (props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1 }}
|
|
169
|
+
</template>
|
|
170
|
+
<template v-else-if="col.type === 'dragRow'">
|
|
171
|
+
<DragHandle @dragstart="onTrDragStart($event, getRowIndex(rowIndex))" />
|
|
172
|
+
<span>
|
|
173
|
+
{{ row?.[col.dataIndex] ?? '' }}
|
|
174
|
+
</span>
|
|
175
|
+
</template>
|
|
176
|
+
<template v-else-if="col.type === 'expand' || col.type === 'tree-node'">
|
|
177
|
+
<TriangleIcon
|
|
178
|
+
v-if="col.type === 'expand' || (col.type === 'tree-node' && row.children !== void 0)"
|
|
179
|
+
@click="triangleClick($event, row, col)"
|
|
180
|
+
/>
|
|
181
|
+
<span :style="col.type === 'tree-node' && !row.children ? 'padding-left: 16px;' : ''">
|
|
182
|
+
{{ row?.[col.dataIndex] ?? '' }}
|
|
183
|
+
</span>
|
|
184
|
+
</template>
|
|
185
|
+
<template v-else>
|
|
186
|
+
{{ row?.[col.dataIndex] ?? getEmptyCellText(col, row) }}
|
|
187
|
+
</template>
|
|
188
|
+
</div>
|
|
189
|
+
</td>
|
|
190
|
+
</template>
|
|
191
|
+
</template>
|
|
192
|
+
<td v-if="virtualX_on" class="vt-x-right"></td>
|
|
193
|
+
</tr>
|
|
194
|
+
<tr v-if="virtual_on && !isSRBRActive" :style="`height: ${virtual_offsetBottom}px`"></tr>
|
|
195
|
+
<tr v-if="SRBRBottomHeight" :style="`height: ${SRBRBottomHeight}px`"></tr>
|
|
196
|
+
</tbody>
|
|
197
|
+
</table>
|
|
198
|
+
<slot name="customBottom"></slot>
|
|
199
|
+
</div>
|
|
200
|
+
<div
|
|
201
|
+
v-if="showScrollbar.y"
|
|
202
|
+
ref="verticalScrollbarRef"
|
|
203
|
+
class="stk-sb-thumb vertical"
|
|
204
|
+
:style="{
|
|
205
|
+
height: `${scrollbar.h}px`,
|
|
206
|
+
transform: `translateY(${scrollbar.top}px)`,
|
|
207
|
+
}"
|
|
208
|
+
@mousedown="onVerticalScrollbarMouseDown"
|
|
209
|
+
@touchstart="onVerticalScrollbarMouseDown"
|
|
210
|
+
></div>
|
|
211
|
+
</div>
|
|
212
|
+
<div v-if="(!dataSourceCopy || !dataSourceCopy.length) && showNoData" class="stk-table-no-data" :class="{ 'no-data-full': noDataFull }">
|
|
213
|
+
<slot name="empty">暂无数据</slot>
|
|
214
|
+
</div>
|
|
215
|
+
<div
|
|
216
|
+
v-if="showScrollbar.x"
|
|
217
|
+
ref="horizontalScrollbarRef"
|
|
218
|
+
class="stk-sb-thumb horizontal"
|
|
219
|
+
:style="{
|
|
220
|
+
width: `${scrollbar.w}px`,
|
|
221
|
+
transform: `translateX(${scrollbar.left}px)`,
|
|
222
|
+
}"
|
|
223
|
+
@mousedown="onHorizontalScrollbarMouseDown"
|
|
224
|
+
@touchstart="onHorizontalScrollbarMouseDown"
|
|
225
|
+
></div>
|
|
226
|
+
</div>
|
|
227
|
+
</template>
|
|
228
|
+
|
|
229
|
+
<script setup lang="ts">
|
|
230
|
+
/**
|
|
231
|
+
* @author japlus
|
|
232
|
+
*/
|
|
233
|
+
import { CSSProperties, computed, nextTick, onMounted, ref, shallowRef, toRaw, watch } from 'vue';
|
|
234
|
+
import DragHandle from './components/DragHandle.vue';
|
|
235
|
+
import SortIcon from './components/SortIcon.vue';
|
|
236
|
+
import TriangleIcon from './components/TriangleIcon.vue';
|
|
237
|
+
import {
|
|
238
|
+
CELL_KEY_SEPARATE,
|
|
239
|
+
DEFAULT_ROW_ACTIVE_CONFIG,
|
|
240
|
+
DEFAULT_ROW_HEIGHT,
|
|
241
|
+
DEFAULT_SMOOTH_SCROLL,
|
|
242
|
+
DEFAULT_SORT_CONFIG,
|
|
243
|
+
IS_LEGACY_MODE,
|
|
244
|
+
} from './const';
|
|
245
|
+
import {
|
|
246
|
+
AutoRowHeightConfig,
|
|
247
|
+
ColResizableConfig,
|
|
248
|
+
DragRowConfig,
|
|
249
|
+
ExpandConfig,
|
|
250
|
+
HeaderDragConfig,
|
|
251
|
+
HighlightConfig,
|
|
252
|
+
Order,
|
|
253
|
+
PrivateRowDT,
|
|
254
|
+
PrivateStkTableColumn,
|
|
255
|
+
RowActiveOption,
|
|
256
|
+
SeqConfig,
|
|
257
|
+
SortConfig,
|
|
258
|
+
SortOption,
|
|
259
|
+
StkTableColumn,
|
|
260
|
+
TagType,
|
|
261
|
+
TreeConfig,
|
|
262
|
+
UniqKey,
|
|
263
|
+
UniqKeyProp,
|
|
264
|
+
} from './types/index';
|
|
265
|
+
import { useAutoResize } from './useAutoResize';
|
|
266
|
+
import { useColResize } from './useColResize';
|
|
267
|
+
import { useFixedCol } from './useFixedCol';
|
|
268
|
+
import { useFixedStyle } from './useFixedStyle';
|
|
269
|
+
import { useGetFixedColPosition } from './useGetFixedColPosition';
|
|
270
|
+
import { useHighlight } from './useHighlight';
|
|
271
|
+
import { useKeyboardArrowScroll } from './useKeyboardArrowScroll';
|
|
272
|
+
import { useMaxRowSpan } from './useMaxRowSpan';
|
|
273
|
+
import { useMergeCells } from './useMergeCells';
|
|
274
|
+
import { useRowExpand } from './useRowExpand';
|
|
275
|
+
import { useScrollbar, type ScrollbarOptions } from './useScrollbar';
|
|
276
|
+
import { useScrollRowByRow } from './useScrollRowByRow';
|
|
277
|
+
import { useThDrag } from './useThDrag';
|
|
278
|
+
import { useTrDrag } from './useTrDrag';
|
|
279
|
+
import { useTree } from './useTree';
|
|
280
|
+
import { useVirtualScroll } from './useVirtualScroll';
|
|
281
|
+
import { createStkTableId, getCalculatedColWidth, getColWidth } from './utils/constRefUtils';
|
|
282
|
+
import { getClosestColKey, getClosestTr, getClosestTrIndex, howDeepTheHeader, isEmptyValue, tableSort, transformWidthToStr } from './utils/index';
|
|
283
|
+
|
|
284
|
+
/** Generic stands for DataType */
|
|
285
|
+
type DT = any & PrivateRowDT;
|
|
286
|
+
|
|
287
|
+
/** generate table instance id */
|
|
288
|
+
const stkTableId = createStkTableId();
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* props cannot be placed in a separate file. It will cause compilation errors with vue 2.7 compiler.
|
|
292
|
+
*/
|
|
293
|
+
const props = withDefaults(
|
|
294
|
+
defineProps<{
|
|
295
|
+
width?: string;
|
|
296
|
+
/** 最小表格宽度 */
|
|
297
|
+
minWidth?: string;
|
|
298
|
+
/** 表格最大宽度*/
|
|
299
|
+
maxWidth?: string;
|
|
300
|
+
/** 斑马线条纹 */
|
|
301
|
+
stripe?: boolean;
|
|
302
|
+
/** 是否使用 table-layout:fixed(低版本浏览器需要设置table) */
|
|
303
|
+
fixedMode?: boolean;
|
|
304
|
+
/** 是否隐藏表头 */
|
|
305
|
+
headless?: boolean;
|
|
306
|
+
/** 主题,亮、暗 */
|
|
307
|
+
theme?: 'light' | 'dark';
|
|
308
|
+
/**
|
|
309
|
+
* 行高
|
|
310
|
+
* - `props.autoRowHeight` 为 `true` 时,将表示为期望行高,用于计算。不再影响实际行高。
|
|
311
|
+
*/
|
|
312
|
+
rowHeight?: number;
|
|
313
|
+
/**
|
|
314
|
+
* 是否可变行高
|
|
315
|
+
* - 设置为 `true` 时, `props.rowHeight` 将表示为期望行高,用于计算。不再影响实际行高。
|
|
316
|
+
*/
|
|
317
|
+
autoRowHeight?: boolean | AutoRowHeightConfig<DT>;
|
|
318
|
+
/** 是否高亮鼠标悬浮的行 */
|
|
319
|
+
rowHover?: boolean;
|
|
320
|
+
/** 是否高亮选中的行 */
|
|
321
|
+
rowActive?: boolean | RowActiveOption<DT>;
|
|
322
|
+
/**
|
|
323
|
+
* @deprecated
|
|
324
|
+
*/
|
|
325
|
+
rowCurrentRevokable?: boolean;
|
|
326
|
+
/** 表头行高。default = rowHeight */
|
|
327
|
+
headerRowHeight?: number | string | null;
|
|
328
|
+
/** 虚拟滚动 */
|
|
329
|
+
virtual?: boolean;
|
|
330
|
+
/** x轴虚拟滚动(必须设置列宽)*/
|
|
331
|
+
virtualX?: boolean;
|
|
332
|
+
/** 表格列配置 */
|
|
333
|
+
columns?: StkTableColumn<DT>[];
|
|
334
|
+
/** 表格数据源 */
|
|
335
|
+
dataSource?: DT[];
|
|
336
|
+
/** 行唯一键 (行唯一值不能为undefined) */
|
|
337
|
+
rowKey?: UniqKeyProp;
|
|
338
|
+
/** 列唯一键 */
|
|
339
|
+
colKey?: UniqKeyProp;
|
|
340
|
+
/** 空值展示文字 */
|
|
341
|
+
emptyCellText?: string | ((option: { row: DT; col: StkTableColumn<DT> }) => string);
|
|
342
|
+
/** 暂无数据兜底高度是否撑满 */
|
|
343
|
+
noDataFull?: boolean;
|
|
344
|
+
/** 是否展示暂无数据 */
|
|
345
|
+
showNoData?: boolean;
|
|
346
|
+
/** 是否服务端排序,true则不排序数据 */
|
|
347
|
+
sortRemote?: boolean;
|
|
348
|
+
/** 表头是否溢出展示... */
|
|
349
|
+
showHeaderOverflow?: boolean;
|
|
350
|
+
/** 表体溢出是否展示... */
|
|
351
|
+
showOverflow?: boolean;
|
|
352
|
+
/** 是否增加行hover class $*$ rename*/
|
|
353
|
+
showTrHoverClass?: boolean;
|
|
354
|
+
/** 是否高亮鼠标悬浮的单元格 */
|
|
355
|
+
cellHover?: boolean;
|
|
356
|
+
/** 是否高亮选中的单元格 */
|
|
357
|
+
cellActive?: boolean;
|
|
358
|
+
/** 单元格再次点击否可以取消选中 (cellActive=true)*/
|
|
359
|
+
selectedCellRevokable?: boolean;
|
|
360
|
+
/** 表头是否可拖动。支持回调函数。 */
|
|
361
|
+
headerDrag?: boolean | HeaderDragConfig<DT>;
|
|
362
|
+
/**
|
|
363
|
+
* 给行附加className<br>
|
|
364
|
+
* FIXME: 是否需要优化,因为不传此prop会使表格行一直执行空函数,是否有影响
|
|
365
|
+
*/
|
|
366
|
+
rowClassName?: (row: DT, i: number) => string | undefined;
|
|
367
|
+
/**
|
|
368
|
+
* 列宽是否可拖动(需要设置v-model:columns)<br>
|
|
369
|
+
* **不要设置**列minWidth,**必须**设置width<br>
|
|
370
|
+
* 列宽拖动时,每一列都必须要有width,且minWidth/maxWidth不生效。table width会变为"fit-content"。
|
|
371
|
+
* - 会自动更新props.columns中的with属性
|
|
372
|
+
*/
|
|
373
|
+
colResizable?: boolean | ColResizableConfig<DT>;
|
|
374
|
+
/** 可拖动至最小的列宽 */
|
|
375
|
+
colMinWidth?: number;
|
|
376
|
+
/**
|
|
377
|
+
* 单元格分割线。
|
|
378
|
+
* 默认横竖都有
|
|
379
|
+
* "h" - 仅展示横线
|
|
380
|
+
* "v" - 仅展示竖线
|
|
381
|
+
* "body-v" - 仅表体展示竖线
|
|
382
|
+
*/
|
|
383
|
+
bordered?: boolean | 'h' | 'v' | 'body-v' | 'body-h';
|
|
384
|
+
/**
|
|
385
|
+
* 自动重新计算虚拟滚动高度宽度。默认true
|
|
386
|
+
* [非响应式]
|
|
387
|
+
* 传入方法表示resize后的回调
|
|
388
|
+
*/
|
|
389
|
+
autoResize?: boolean | (() => void);
|
|
390
|
+
/** 是否展示固定列阴影。为节省性能,默认false。 */
|
|
391
|
+
fixedColShadow?: boolean;
|
|
392
|
+
/** 优化vue2 滚动 */
|
|
393
|
+
optimizeVue2Scroll?: boolean;
|
|
394
|
+
/** 排序配置 */
|
|
395
|
+
sortConfig?: SortConfig<DT>;
|
|
396
|
+
/** 隐藏头部title。可传入colKey数组 */
|
|
397
|
+
hideHeaderTitle?: boolean | string[];
|
|
398
|
+
/** 高亮配置 */
|
|
399
|
+
highlightConfig?: HighlightConfig;
|
|
400
|
+
/** 序号列配置 */
|
|
401
|
+
seqConfig?: SeqConfig;
|
|
402
|
+
/** 展开行配置 */
|
|
403
|
+
expandConfig?: ExpandConfig;
|
|
404
|
+
/** 行拖动配置 */
|
|
405
|
+
dragRowConfig?: DragRowConfig;
|
|
406
|
+
/** 树形配置 */
|
|
407
|
+
treeConfig?: TreeConfig;
|
|
408
|
+
/**
|
|
409
|
+
* 固定头,固定列实现方式。(非响应式)
|
|
410
|
+
*
|
|
411
|
+
* relative:固定列只会放在props.columns的两侧。
|
|
412
|
+
* - 如果列宽会变动则谨慎使用。
|
|
413
|
+
* - 多级表头固定列慎用
|
|
414
|
+
*
|
|
415
|
+
* 低版本浏览器强制为'relative',
|
|
416
|
+
*/
|
|
417
|
+
cellFixedMode?: 'sticky' | 'relative';
|
|
418
|
+
/**
|
|
419
|
+
* 是否平滑滚动。default: chrome < 85 || chrome > 120 ? true : false
|
|
420
|
+
* - false: 使用 onwheel 滚动。为了防止滚动过快导致白屏。
|
|
421
|
+
* - true: 不使用 onwheel 滚动。鼠标滚轮滚动时更加平滑。滚动过快时会白屏。
|
|
422
|
+
*/
|
|
423
|
+
smoothScroll?: boolean;
|
|
424
|
+
/**
|
|
425
|
+
* 按整数行纵向滚动
|
|
426
|
+
* - scrollbar:仅拖动滚动条生效
|
|
427
|
+
*/
|
|
428
|
+
scrollRowByRow?: boolean | 'scrollbar';
|
|
429
|
+
/**
|
|
430
|
+
* 自定义滚动条配置
|
|
431
|
+
* - false: 禁用自定义滚动条
|
|
432
|
+
* - true: 启用默认配置的自定义滚动条
|
|
433
|
+
* - ScrollbarOptions: 启用并配置自定义滚动条
|
|
434
|
+
*/
|
|
435
|
+
scrollbar?: boolean | ScrollbarOptions;
|
|
436
|
+
}>(),
|
|
437
|
+
{
|
|
438
|
+
width: '',
|
|
439
|
+
fixedMode: false,
|
|
440
|
+
stripe: false,
|
|
441
|
+
minWidth: '',
|
|
442
|
+
maxWidth: '',
|
|
443
|
+
headless: false,
|
|
444
|
+
theme: 'light',
|
|
445
|
+
rowHeight: DEFAULT_ROW_HEIGHT,
|
|
446
|
+
autoRowHeight: () => false,
|
|
447
|
+
rowHover: true,
|
|
448
|
+
rowActive: () => DEFAULT_ROW_ACTIVE_CONFIG,
|
|
449
|
+
rowCurrentRevokable: true,
|
|
450
|
+
headerRowHeight: DEFAULT_ROW_HEIGHT,
|
|
451
|
+
virtual: false,
|
|
452
|
+
virtualX: false,
|
|
453
|
+
columns: () => [],
|
|
454
|
+
dataSource: () => [],
|
|
455
|
+
rowKey: '',
|
|
456
|
+
colKey: void 0,
|
|
457
|
+
emptyCellText: '--',
|
|
458
|
+
noDataFull: false,
|
|
459
|
+
showNoData: true,
|
|
460
|
+
sortRemote: false,
|
|
461
|
+
showHeaderOverflow: false,
|
|
462
|
+
showOverflow: false,
|
|
463
|
+
showTrHoverClass: false,
|
|
464
|
+
cellHover: false,
|
|
465
|
+
cellActive: false,
|
|
466
|
+
selectedCellRevokable: true,
|
|
467
|
+
headerDrag: () => false,
|
|
468
|
+
rowClassName: () => '',
|
|
469
|
+
colResizable: () => false,
|
|
470
|
+
colMinWidth: 10,
|
|
471
|
+
bordered: true,
|
|
472
|
+
autoResize: true,
|
|
473
|
+
fixedColShadow: false,
|
|
474
|
+
optimizeVue2Scroll: false,
|
|
475
|
+
sortConfig: () => DEFAULT_SORT_CONFIG,
|
|
476
|
+
hideHeaderTitle: false,
|
|
477
|
+
highlightConfig: () => ({}),
|
|
478
|
+
seqConfig: () => ({}),
|
|
479
|
+
expandConfig: () => ({}),
|
|
480
|
+
dragRowConfig: () => ({}),
|
|
481
|
+
treeConfig: () => ({}),
|
|
482
|
+
cellFixedMode: 'sticky',
|
|
483
|
+
smoothScroll: DEFAULT_SMOOTH_SCROLL,
|
|
484
|
+
scrollRowByRow: false,
|
|
485
|
+
scrollbar: false,
|
|
486
|
+
},
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
const emits = defineEmits<{
|
|
490
|
+
/**
|
|
491
|
+
* 排序变更触发。defaultSort.dataIndex 找不到时,col 将返回null。
|
|
492
|
+
*
|
|
493
|
+
* ```(col: StkTableColumn<DT> | null, order: Order, data: DT[], sortConfig: SortConfig<DT>)```
|
|
494
|
+
*/
|
|
495
|
+
(e: 'sort-change', col: StkTableColumn<DT> | null, order: Order, data: DT[], sortConfig: SortConfig<DT>): void;
|
|
496
|
+
/**
|
|
497
|
+
* 一行点击事件
|
|
498
|
+
*
|
|
499
|
+
* ```(ev: MouseEvent, row: DT, data: { rowIndex: number })```
|
|
500
|
+
*/
|
|
501
|
+
(e: 'row-click', ev: MouseEvent, row: DT, data: { rowIndex: number }): void;
|
|
502
|
+
/**
|
|
503
|
+
* 选中一行触发。ev返回null表示不是点击事件触发的
|
|
504
|
+
*
|
|
505
|
+
* ```(ev: MouseEvent | null, row: DT | undefined, data: { select: boolean} })```
|
|
506
|
+
*/
|
|
507
|
+
(e: 'current-change', ev: MouseEvent | null, row: DT | undefined, data: { select: boolean }): void;
|
|
508
|
+
/**
|
|
509
|
+
* 选中单元格触发。ev返回null表示不是点击事件触发的
|
|
510
|
+
*
|
|
511
|
+
* ```(ev: MouseEvent | null, data: { select: boolean; row: DT | undefined; col: StkTableColumn<DT> | null })```
|
|
512
|
+
*/
|
|
513
|
+
(e: 'cell-selected', ev: MouseEvent | null, data: { select: boolean; row: DT | undefined; col: StkTableColumn<DT> | undefined }): void;
|
|
514
|
+
/**
|
|
515
|
+
* 行双击事件
|
|
516
|
+
*
|
|
517
|
+
* ```(ev: MouseEvent, row: DT, data: { rowIndex: number })```
|
|
518
|
+
*/
|
|
519
|
+
(e: 'row-dblclick', ev: MouseEvent, row: DT, data: { rowIndex: number }): void;
|
|
520
|
+
/**
|
|
521
|
+
* 表头右键事件
|
|
522
|
+
*
|
|
523
|
+
* ```(ev: MouseEvent)```
|
|
524
|
+
*/
|
|
525
|
+
(e: 'header-row-menu', ev: MouseEvent): void;
|
|
526
|
+
/**
|
|
527
|
+
* 表体行右键点击事件
|
|
528
|
+
*
|
|
529
|
+
* ```(ev: MouseEvent, row: DT, data: { rowIndex: number })```
|
|
530
|
+
*/
|
|
531
|
+
(e: 'row-menu', ev: MouseEvent, row: DT, data: { rowIndex: number }): void;
|
|
532
|
+
/**
|
|
533
|
+
* 单元格点击事件
|
|
534
|
+
*
|
|
535
|
+
* ```(ev: MouseEvent, row: DT, col: StkTableColumn<DT>, data: { rowIndex: number })```
|
|
536
|
+
*/
|
|
537
|
+
(e: 'cell-click', ev: MouseEvent, row: DT, col: StkTableColumn<DT>, data: { rowIndex: number }): void;
|
|
538
|
+
/**
|
|
539
|
+
* 单元格鼠标进入事件
|
|
540
|
+
*
|
|
541
|
+
* ```(ev: MouseEvent, row: DT, col: StkTableColumn<DT>)```
|
|
542
|
+
*/
|
|
543
|
+
(e: 'cell-mouseenter', ev: MouseEvent, row: DT, col: StkTableColumn<DT>): void;
|
|
544
|
+
/**
|
|
545
|
+
* 单元格鼠标移出事件
|
|
546
|
+
*
|
|
547
|
+
* ```(ev: MouseEvent, row: DT, col: StkTableColumn<DT>)```
|
|
548
|
+
*/
|
|
549
|
+
(e: 'cell-mouseleave', ev: MouseEvent, row: DT, col: StkTableColumn<DT>): void;
|
|
550
|
+
/**
|
|
551
|
+
* 单元格悬浮事件
|
|
552
|
+
*
|
|
553
|
+
* ```(ev: MouseEvent, row: DT, col: StkTableColumn<DT>)```
|
|
554
|
+
*/
|
|
555
|
+
(e: 'cell-mouseover', ev: MouseEvent, row: DT, col: StkTableColumn<DT>): void;
|
|
556
|
+
/**
|
|
557
|
+
* 单元格鼠标按下事件
|
|
558
|
+
*
|
|
559
|
+
* ```(ev: MouseEvent, row: DT, col: StkTableColumn<DT>, data: { rowIndex: number })```
|
|
560
|
+
*/
|
|
561
|
+
(e: 'cell-mousedown', ev: MouseEvent, row: DT, col: StkTableColumn<DT>, data: { rowIndex: number }): void;
|
|
562
|
+
/**
|
|
563
|
+
* 表头单元格点击事件
|
|
564
|
+
*
|
|
565
|
+
* ```(ev: MouseEvent, col: StkTableColumn<DT>)```
|
|
566
|
+
*/
|
|
567
|
+
(e: 'header-cell-click', ev: MouseEvent, col: StkTableColumn<DT>): void;
|
|
568
|
+
/**
|
|
569
|
+
* 表格滚动事件
|
|
570
|
+
*
|
|
571
|
+
* ```(ev: Event, data: { startIndex: number; endIndex: number })```
|
|
572
|
+
*/
|
|
573
|
+
(e: 'scroll', ev: Event, data: { startIndex: number; endIndex: number }): void;
|
|
574
|
+
/**
|
|
575
|
+
* 表格横向滚动事件
|
|
576
|
+
*
|
|
577
|
+
* ```(ev: Event)```
|
|
578
|
+
*/
|
|
579
|
+
(e: 'scroll-x', ev: Event): void;
|
|
580
|
+
/**
|
|
581
|
+
* 表头列拖动事件
|
|
582
|
+
*
|
|
583
|
+
* ```(dragStartKey: string, targetColKey: string)```
|
|
584
|
+
*/
|
|
585
|
+
(e: 'col-order-change', dragStartKey: string, targetColKey: string): void;
|
|
586
|
+
/**
|
|
587
|
+
* 表头列拖动开始
|
|
588
|
+
*
|
|
589
|
+
* ```(dragStartKey: string)```
|
|
590
|
+
*/
|
|
591
|
+
(e: 'th-drag-start', dragStartKey: string): void;
|
|
592
|
+
/**
|
|
593
|
+
* 表头列拖动drop
|
|
594
|
+
*
|
|
595
|
+
* ```(targetColKey: string)```
|
|
596
|
+
*/
|
|
597
|
+
(e: 'th-drop', targetColKey: string): void;
|
|
598
|
+
/**
|
|
599
|
+
* 行拖动事件
|
|
600
|
+
*
|
|
601
|
+
* ```(dragStartKey: string, targetRowKey: string)```
|
|
602
|
+
*/
|
|
603
|
+
(e: 'row-order-change', dragStartKey: string, targetRowKey: string): void;
|
|
604
|
+
/**
|
|
605
|
+
* 列宽变动时触发
|
|
606
|
+
*
|
|
607
|
+
* ```(col: StkTableColumn<DT>)```
|
|
608
|
+
*/
|
|
609
|
+
(e: 'col-resize', col: StkTableColumn<DT>): void;
|
|
610
|
+
/**
|
|
611
|
+
* 展开行触发
|
|
612
|
+
*
|
|
613
|
+
* ```( data: { expanded: boolean; row: DT; col: StkTableColumn<DT> })```
|
|
614
|
+
*/
|
|
615
|
+
(e: 'toggle-row-expand', data: { expanded: boolean; row: DT; col: StkTableColumn<DT> | null }): void;
|
|
616
|
+
/**
|
|
617
|
+
* 点击展开树行触发
|
|
618
|
+
*
|
|
619
|
+
* ```( data: { expanded: boolean; row: DT; col: StkTableColumn<DT> })```
|
|
620
|
+
*/
|
|
621
|
+
(e: 'toggle-tree-expand', data: { expanded: boolean; row: DT; col: StkTableColumn<DT> | null }): void;
|
|
622
|
+
/**
|
|
623
|
+
* v-model:columns col resize 时更新宽度
|
|
624
|
+
*/
|
|
625
|
+
(e: 'update:columns', cols: StkTableColumn<DT>[]): void;
|
|
626
|
+
}>();
|
|
627
|
+
|
|
628
|
+
// 仅支持vue3.3+
|
|
629
|
+
// const slots = defineSlots<{
|
|
630
|
+
// /** 表头插槽 */
|
|
631
|
+
// tableHeader(props: { col: StkTableColumn<DT> }): void;
|
|
632
|
+
// /** 空状态插槽 */
|
|
633
|
+
// empty(): void;
|
|
634
|
+
// }>();
|
|
635
|
+
|
|
636
|
+
const tableContainerRef = ref<HTMLDivElement>();
|
|
637
|
+
const colResizeIndicatorRef = ref<HTMLDivElement>();
|
|
638
|
+
const trRef = ref<HTMLTableRowElement[]>();
|
|
639
|
+
|
|
640
|
+
/** 是否使用 relative 固定头和列 */
|
|
641
|
+
const isRelativeMode = ref(IS_LEGACY_MODE ? true : props.cellFixedMode === 'relative');
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* 当前选中的一行
|
|
645
|
+
* - shallowRef: 使 currentRow.value === row 地址相同。防止rowKeyGen 的WeakMap key不一致。
|
|
646
|
+
*/
|
|
647
|
+
const currentRow = shallowRef<DT>();
|
|
648
|
+
/**
|
|
649
|
+
* 保存当前选中行的key<br>
|
|
650
|
+
* 原因:vue3 不用ref包dataSource时,row为原始对象,与currentItem(Ref)相比会不相等。
|
|
651
|
+
*/
|
|
652
|
+
const currentRowKey = ref<UniqKey | undefined>();
|
|
653
|
+
/** 当前选中的单元格key */
|
|
654
|
+
const currentSelectedCellKey = ref<string | undefined>();
|
|
655
|
+
/** 当前hover行 */
|
|
656
|
+
let currentHoverRow: DT | null = null;
|
|
657
|
+
/** 当前hover的行的key */
|
|
658
|
+
const currentHoverRowKey = ref<UniqKey | null>(null);
|
|
659
|
+
/** 当前hover的列的key */
|
|
660
|
+
// const currentColHoverKey = ref(null);
|
|
661
|
+
|
|
662
|
+
/** sort colKey*/
|
|
663
|
+
let sortCol = ref<keyof DT>();
|
|
664
|
+
let sortOrderIndex = ref(0);
|
|
665
|
+
|
|
666
|
+
/** 排序切换顺序 */
|
|
667
|
+
const sortSwitchOrder: Order[] = [null, 'desc', 'asc'];
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* 表头.内容是 props.columns 的引用集合
|
|
671
|
+
* @eg
|
|
672
|
+
* ```js
|
|
673
|
+
* [
|
|
674
|
+
* [{dataIndex:'id',...}], // 第0行列配置
|
|
675
|
+
* [], // 第一行列配置
|
|
676
|
+
* //...
|
|
677
|
+
* ]
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
const tableHeaders = shallowRef<PrivateStkTableColumn<PrivateRowDT>[][]>([]);
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* 用于计算多级表头的tableHeaders。模拟rowSpan 位置的辅助数组。用于计算固定列。
|
|
684
|
+
* @eg
|
|
685
|
+
* ```
|
|
686
|
+
* | colspan3 |
|
|
687
|
+
* | rowspan2 | colspan2 |
|
|
688
|
+
* | rowspan2 | colspan1 | colspan1 |
|
|
689
|
+
* ```
|
|
690
|
+
* ---
|
|
691
|
+
* expect arr:
|
|
692
|
+
* ```
|
|
693
|
+
* const arr = [
|
|
694
|
+
* [col],
|
|
695
|
+
* [col2, col3],
|
|
696
|
+
* [col2, col4, col5],
|
|
697
|
+
* ]
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
const tableHeadersForCalc = shallowRef<PrivateStkTableColumn<PrivateRowDT>[][]>([]);
|
|
701
|
+
|
|
702
|
+
/** 最后一行的tableHeaders.内容是 props.columns 的引用集合 */
|
|
703
|
+
const tableHeaderLast = computed(() => tableHeadersForCalc.value.slice(-1)[0] || []);
|
|
704
|
+
|
|
705
|
+
const isTreeData = computed(() => {
|
|
706
|
+
return props.columns.some(col => col.type === 'tree-node');
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
const rowActiveProp = computed<Required<RowActiveOption<DT>>>(() => {
|
|
710
|
+
const { rowActive } = props;
|
|
711
|
+
if (typeof rowActive === 'boolean') {
|
|
712
|
+
return {
|
|
713
|
+
...DEFAULT_ROW_ACTIVE_CONFIG,
|
|
714
|
+
enabled: rowActive ?? true,
|
|
715
|
+
revokable: Boolean(props.rowCurrentRevokable),
|
|
716
|
+
};
|
|
717
|
+
} else {
|
|
718
|
+
return { ...DEFAULT_ROW_ACTIVE_CONFIG, ...rowActive };
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
const dataSourceCopy = shallowRef<DT[]>([]);
|
|
723
|
+
|
|
724
|
+
const rowKeyGenComputed = computed(() => {
|
|
725
|
+
const { rowKey } = props;
|
|
726
|
+
if (typeof rowKey === 'function') {
|
|
727
|
+
return (row: DT) => (rowKey as (row: DT) => string)(row);
|
|
728
|
+
} else {
|
|
729
|
+
return (row: DT) => (row as any)[rowKey];
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
const colKeyGen = computed<(col: StkTableColumn<DT>) => string>(() => {
|
|
734
|
+
const { colKey } = props;
|
|
735
|
+
if (colKey === void 0) {
|
|
736
|
+
return col => col.key || col.dataIndex;
|
|
737
|
+
} else if (typeof colKey === 'function') {
|
|
738
|
+
return col => (colKey as (col: StkTableColumn<DT>) => string)(col);
|
|
739
|
+
} else {
|
|
740
|
+
return col => (col as any)[colKey];
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
const getEmptyCellText = computed(() => {
|
|
745
|
+
const { emptyCellText } = props;
|
|
746
|
+
if (typeof emptyCellText === 'string') {
|
|
747
|
+
return () => emptyCellText;
|
|
748
|
+
} else {
|
|
749
|
+
return (col: StkTableColumn<DT>, row: DT) => emptyCellText({ row, col });
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
/** scroll-row-by-row total-height */
|
|
754
|
+
const SRBRTotalHeight = computed(() => {
|
|
755
|
+
if (!isSRBRActive.value || !props.virtual) return 0;
|
|
756
|
+
return (
|
|
757
|
+
dataSourceCopy.value.length * virtualScroll.value.rowHeight + tableHeaderHeight.value //+
|
|
758
|
+
);
|
|
759
|
+
});
|
|
760
|
+
const SRBRBottomHeight = computed(() => {
|
|
761
|
+
if (!isSRBRActive.value || !props.virtual) return 0;
|
|
762
|
+
const { containerHeight, rowHeight } = virtualScroll.value;
|
|
763
|
+
return (containerHeight - tableHeaderHeight.value) % rowHeight;
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
const rowKeyGenCache = new WeakMap();
|
|
767
|
+
|
|
768
|
+
const { scrollbarOptions, scrollbar, showScrollbar, onVerticalScrollbarMouseDown, onHorizontalScrollbarMouseDown, updateCustomScrollbar } =
|
|
769
|
+
useScrollbar(tableContainerRef, props.scrollbar);
|
|
770
|
+
|
|
771
|
+
const { isSRBRActive } = useScrollRowByRow({ props, tableContainerRef });
|
|
772
|
+
|
|
773
|
+
const { onThDragStart, onThDragOver, onThDrop, isHeaderDraggable } = useThDrag({ props, emits, colKeyGen });
|
|
774
|
+
|
|
775
|
+
const { onTrDragStart, onTrDrop, onTrDragOver, onTrDragEnd, onTrDragEnter } = useTrDrag({ props, emits, dataSourceCopy });
|
|
776
|
+
|
|
777
|
+
const { maxRowSpan, updateMaxRowSpan } = useMaxRowSpan({ props, tableHeaderLast, rowKeyGen, dataSourceCopy });
|
|
778
|
+
|
|
779
|
+
const {
|
|
780
|
+
virtualScroll,
|
|
781
|
+
virtualScrollX,
|
|
782
|
+
virtual_on,
|
|
783
|
+
virtual_dataSourcePart,
|
|
784
|
+
virtual_offsetBottom,
|
|
785
|
+
virtualX_on,
|
|
786
|
+
virtualX_columnPart,
|
|
787
|
+
virtualX_offsetRight,
|
|
788
|
+
tableHeaderHeight,
|
|
789
|
+
initVirtualScroll,
|
|
790
|
+
initVirtualScrollY,
|
|
791
|
+
initVirtualScrollX,
|
|
792
|
+
updateVirtualScrollY,
|
|
793
|
+
updateVirtualScrollX,
|
|
794
|
+
setAutoHeight,
|
|
795
|
+
clearAllAutoHeight,
|
|
796
|
+
} = useVirtualScroll({ tableContainerRef, trRef, props, dataSourceCopy, tableHeaderLast, tableHeaders, rowKeyGen, maxRowSpan });
|
|
797
|
+
|
|
798
|
+
const {
|
|
799
|
+
hiddenCellMap, //
|
|
800
|
+
mergeCellsWrapper,
|
|
801
|
+
hoverMergedCells,
|
|
802
|
+
updateHoverMergedCells,
|
|
803
|
+
activeMergedCells,
|
|
804
|
+
updateActiveMergedCells,
|
|
805
|
+
} = useMergeCells({ rowActiveProp, tableHeaderLast, rowKeyGen, colKeyGen, virtual_dataSourcePart });
|
|
806
|
+
|
|
807
|
+
const getFixedColPosition = useGetFixedColPosition({ colKeyGen, tableHeadersForCalc });
|
|
808
|
+
|
|
809
|
+
const getFixedStyle = useFixedStyle<DT>({
|
|
810
|
+
props,
|
|
811
|
+
isRelativeMode,
|
|
812
|
+
getFixedColPosition,
|
|
813
|
+
virtualScroll,
|
|
814
|
+
virtualScrollX,
|
|
815
|
+
virtualX_on,
|
|
816
|
+
virtualX_offsetRight,
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
const { highlightSteps, setHighlightDimCell, setHighlightDimRow } = useHighlight({ props, stkTableId, tableContainerRef });
|
|
820
|
+
|
|
821
|
+
if (props.autoResize) {
|
|
822
|
+
useAutoResize({ tableContainerRef, initVirtualScroll, props, debounceMs: 200 });
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/** 键盘箭头滚动 */
|
|
826
|
+
useKeyboardArrowScroll(tableContainerRef, {
|
|
827
|
+
props,
|
|
828
|
+
scrollTo,
|
|
829
|
+
virtualScroll,
|
|
830
|
+
virtualScrollX,
|
|
831
|
+
tableHeaders,
|
|
832
|
+
virtual_on,
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
/** 固定列处理 */
|
|
836
|
+
const { fixedCols, fixedColClassMap, updateFixedShadow } = useFixedCol({
|
|
837
|
+
props,
|
|
838
|
+
colKeyGen,
|
|
839
|
+
getFixedColPosition,
|
|
840
|
+
tableContainerRef,
|
|
841
|
+
tableHeaders,
|
|
842
|
+
tableHeadersForCalc,
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
const { isColResizing, onThResizeMouseDown, colResizeOn } = useColResize({
|
|
846
|
+
props,
|
|
847
|
+
emits,
|
|
848
|
+
colKeyGen,
|
|
849
|
+
colResizeIndicatorRef,
|
|
850
|
+
tableContainerRef,
|
|
851
|
+
tableHeaderLast,
|
|
852
|
+
fixedCols,
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
const { toggleExpandRow, setRowExpand } = useRowExpand({ dataSourceCopy, rowKeyGen, emits });
|
|
856
|
+
|
|
857
|
+
const { toggleTreeNode, setTreeExpand, flatTreeData } = useTree({ props, dataSourceCopy, rowKeyGen, emits });
|
|
858
|
+
|
|
859
|
+
watch(
|
|
860
|
+
() => props.columns,
|
|
861
|
+
() => {
|
|
862
|
+
dealColumns();
|
|
863
|
+
updateMaxRowSpan();
|
|
864
|
+
// nextTick: initVirtualScrollX need get container width。
|
|
865
|
+
nextTick(() => {
|
|
866
|
+
initVirtualScrollX();
|
|
867
|
+
updateFixedShadow();
|
|
868
|
+
updateCustomScrollbar();
|
|
869
|
+
});
|
|
870
|
+
},
|
|
871
|
+
);
|
|
872
|
+
watch(
|
|
873
|
+
() => props.virtual,
|
|
874
|
+
() => {
|
|
875
|
+
nextTick(() => {
|
|
876
|
+
initVirtualScrollY();
|
|
877
|
+
});
|
|
878
|
+
},
|
|
879
|
+
);
|
|
880
|
+
|
|
881
|
+
watch(
|
|
882
|
+
() => props.rowHeight,
|
|
883
|
+
() => {
|
|
884
|
+
initVirtualScrollY();
|
|
885
|
+
},
|
|
886
|
+
);
|
|
887
|
+
|
|
888
|
+
watch(
|
|
889
|
+
() => props.virtualX,
|
|
890
|
+
() => {
|
|
891
|
+
dealColumns();
|
|
892
|
+
// initVirtualScrollX 需要获取容器滚动宽度等。必须等渲染完成后再调用。因此使用nextTick。
|
|
893
|
+
nextTick(() => {
|
|
894
|
+
initVirtualScrollX();
|
|
895
|
+
updateFixedShadow();
|
|
896
|
+
});
|
|
897
|
+
},
|
|
898
|
+
);
|
|
899
|
+
|
|
900
|
+
watch(
|
|
901
|
+
() => props.dataSource,
|
|
902
|
+
val => {
|
|
903
|
+
updateDataSource(val);
|
|
904
|
+
nextTick(() => {
|
|
905
|
+
updateCustomScrollbar();
|
|
906
|
+
});
|
|
907
|
+
},
|
|
908
|
+
);
|
|
909
|
+
|
|
910
|
+
watch(
|
|
911
|
+
() => props.fixedColShadow,
|
|
912
|
+
() => updateFixedShadow(),
|
|
913
|
+
);
|
|
914
|
+
|
|
915
|
+
dealColumns();
|
|
916
|
+
initDataSource();
|
|
917
|
+
updateMaxRowSpan();
|
|
918
|
+
|
|
919
|
+
onMounted(() => {
|
|
920
|
+
initVirtualScroll();
|
|
921
|
+
updateFixedShadow();
|
|
922
|
+
dealDefaultSorter();
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
function initDataSource(v = props.dataSource) {
|
|
926
|
+
let dataSourceTemp = v.slice(); // shallow copy
|
|
927
|
+
if (isTreeData.value) {
|
|
928
|
+
// only tree data need flat
|
|
929
|
+
dataSourceTemp = flatTreeData(dataSourceTemp);
|
|
930
|
+
}
|
|
931
|
+
dataSourceCopy.value = dataSourceTemp;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function dealDefaultSorter() {
|
|
935
|
+
if (!props.sortConfig.defaultSort) return;
|
|
936
|
+
const { key, dataIndex, order, silent } = { silent: false, ...props.sortConfig.defaultSort };
|
|
937
|
+
setSorter((key || dataIndex) as string, order, { force: false, silent });
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* deal multi-level header
|
|
942
|
+
*/
|
|
943
|
+
function dealColumns() {
|
|
944
|
+
// reset
|
|
945
|
+
const tableHeadersTemp: StkTableColumn<PrivateRowDT>[][] = [];
|
|
946
|
+
const tableHeadersForCalcTemp: StkTableColumn<PrivateRowDT>[][] = [];
|
|
947
|
+
let copyColumn: StkTableColumn<PrivateRowDT>[] = props.columns; // do not deep clone
|
|
948
|
+
// relative 模式下不支持sticky列。因此就放在左右两侧。
|
|
949
|
+
if (isRelativeMode.value) {
|
|
950
|
+
let leftCol: StkTableColumn<PrivateRowDT>[] = [];
|
|
951
|
+
let centerCol: StkTableColumn<PrivateRowDT>[] = [];
|
|
952
|
+
let rightCol: StkTableColumn<PrivateRowDT>[] = [];
|
|
953
|
+
copyColumn.forEach(col => {
|
|
954
|
+
if (col.fixed === 'left') {
|
|
955
|
+
leftCol.push(col);
|
|
956
|
+
} else if (col.fixed === 'right') {
|
|
957
|
+
rightCol.push(col);
|
|
958
|
+
} else {
|
|
959
|
+
centerCol.push(col);
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
copyColumn = leftCol.concat(centerCol).concat(rightCol);
|
|
963
|
+
}
|
|
964
|
+
const maxDeep = howDeepTheHeader(copyColumn);
|
|
965
|
+
|
|
966
|
+
if (maxDeep > 0 && props.virtualX) {
|
|
967
|
+
console.error('StkTableVue:多级表头不支持横向虚拟滚动!');
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
for (let i = 0; i <= maxDeep; i++) {
|
|
971
|
+
tableHeadersTemp[i] = [];
|
|
972
|
+
tableHeadersForCalcTemp[i] = [];
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* flat columns
|
|
977
|
+
* @param arr
|
|
978
|
+
* @param depth 深度
|
|
979
|
+
* @param parent 父节点引用,用于构建双向链表。
|
|
980
|
+
* @param parentFixed 父节点固定列继承。
|
|
981
|
+
*/
|
|
982
|
+
function flat(
|
|
983
|
+
arr: PrivateStkTableColumn<PrivateRowDT>[],
|
|
984
|
+
parent: PrivateStkTableColumn<PrivateRowDT> | null,
|
|
985
|
+
depth = 0 /* , parentFixed: 'left' | 'right' | null = null */,
|
|
986
|
+
) {
|
|
987
|
+
/** 所有子节点数量 */
|
|
988
|
+
let allChildrenLen = 0;
|
|
989
|
+
let allChildrenWidthSum = 0;
|
|
990
|
+
arr.forEach(col => {
|
|
991
|
+
// TODO: 继承父节点固定列配置
|
|
992
|
+
// if (parentFixed) {
|
|
993
|
+
// col.fixed = parentFixed;
|
|
994
|
+
// }
|
|
995
|
+
col.__PARENT__ = parent;
|
|
996
|
+
/** 一列中的子节点数量 */
|
|
997
|
+
let colChildrenLen = 1;
|
|
998
|
+
/** 多级表头的父节点宽度,通过叶子节点宽度计算得到 */
|
|
999
|
+
let colWidth = 0;
|
|
1000
|
+
if (col.children) {
|
|
1001
|
+
// DFS
|
|
1002
|
+
const [len, widthSum] = flat(col.children, col, depth + 1 /* , col.fixed */);
|
|
1003
|
+
colChildrenLen = len;
|
|
1004
|
+
colWidth = widthSum;
|
|
1005
|
+
tableHeadersForCalcTemp[depth].push(col);
|
|
1006
|
+
} else {
|
|
1007
|
+
colWidth = getColWidth(col);
|
|
1008
|
+
for (let i = depth; i <= maxDeep; i++) {
|
|
1009
|
+
// 如有rowSpan 向下复制一个表头col,用于计算固定列
|
|
1010
|
+
tableHeadersForCalcTemp[i].push(col);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
// 回溯
|
|
1014
|
+
col.__WIDTH__ = colWidth; //记录计算的列宽
|
|
1015
|
+
tableHeadersTemp[depth].push(col);
|
|
1016
|
+
const rowSpan = col.children ? 1 : maxDeep - depth + 1;
|
|
1017
|
+
const colSpan = colChildrenLen;
|
|
1018
|
+
if (rowSpan > 1) {
|
|
1019
|
+
col.__R_SP__ = rowSpan;
|
|
1020
|
+
}
|
|
1021
|
+
if (colSpan > 1) {
|
|
1022
|
+
col.__C_SP__ = colSpan;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
allChildrenLen += colChildrenLen;
|
|
1026
|
+
allChildrenWidthSum += colWidth;
|
|
1027
|
+
});
|
|
1028
|
+
return [allChildrenLen, allChildrenWidthSum];
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
flat(copyColumn, null);
|
|
1032
|
+
tableHeaders.value = tableHeadersTemp;
|
|
1033
|
+
tableHeadersForCalc.value = tableHeadersForCalcTemp;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
function updateDataSource(val: DT[]) {
|
|
1037
|
+
if (!Array.isArray(val)) {
|
|
1038
|
+
console.warn('invalid dataSource');
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
let needInitVirtualScrollY = false;
|
|
1043
|
+
if (dataSourceCopy.value.length !== val.length) {
|
|
1044
|
+
needInitVirtualScrollY = true;
|
|
1045
|
+
}
|
|
1046
|
+
initDataSource(val);
|
|
1047
|
+
updateMaxRowSpan();
|
|
1048
|
+
// if data length is not change, not init virtual scroll
|
|
1049
|
+
if (needInitVirtualScrollY) {
|
|
1050
|
+
// wait for table render,initVirtualScrollY has get `dom` operation.
|
|
1051
|
+
nextTick(() => initVirtualScrollY());
|
|
1052
|
+
}
|
|
1053
|
+
const sortColValue = sortCol.value;
|
|
1054
|
+
if (!isEmptyValue(sortColValue) && !props.sortRemote) {
|
|
1055
|
+
// sort
|
|
1056
|
+
const colKey = colKeyGen.value;
|
|
1057
|
+
const column = tableHeaderLast.value.find(it => colKey(it) === sortColValue);
|
|
1058
|
+
onColumnSort(column, false);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
/** tr key */
|
|
1063
|
+
function rowKeyGen(row: DT | null | undefined) {
|
|
1064
|
+
if (!row) return row;
|
|
1065
|
+
let key = rowKeyGenCache.get(row) || (row as PrivateRowDT).__ROW_K__;
|
|
1066
|
+
if (!key) {
|
|
1067
|
+
key = rowKeyGenComputed.value(row);
|
|
1068
|
+
|
|
1069
|
+
if (key === void 0) {
|
|
1070
|
+
// key为undefined时,不应该高亮行。因此重新生成key
|
|
1071
|
+
key = Math.random().toString(36).slice(2);
|
|
1072
|
+
}
|
|
1073
|
+
rowKeyGenCache.set(row, key);
|
|
1074
|
+
}
|
|
1075
|
+
return key;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/** td key */
|
|
1079
|
+
function cellKeyGen(row: DT | null | undefined, col: StkTableColumn<DT>) {
|
|
1080
|
+
return rowKeyGen(row) + CELL_KEY_SEPARATE + colKeyGen.value(col);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
const cellStyleMap = computed(() => {
|
|
1084
|
+
const thMap = new Map();
|
|
1085
|
+
const tdMap = new Map();
|
|
1086
|
+
const { virtualX, colResizable } = props;
|
|
1087
|
+
tableHeaders.value.forEach((cols, depth) => {
|
|
1088
|
+
cols.forEach(col => {
|
|
1089
|
+
const width = virtualX ? getCalculatedColWidth(col) + 'px' : transformWidthToStr(col.width);
|
|
1090
|
+
const style: CSSProperties = {
|
|
1091
|
+
width,
|
|
1092
|
+
};
|
|
1093
|
+
if (colResizable) {
|
|
1094
|
+
// 如果要调整列宽,列宽必须固定。
|
|
1095
|
+
style.minWidth = width;
|
|
1096
|
+
style.maxWidth = width;
|
|
1097
|
+
} else {
|
|
1098
|
+
style.minWidth = transformWidthToStr(col.minWidth) ?? width;
|
|
1099
|
+
style.maxWidth = transformWidthToStr(col.maxWidth) ?? width;
|
|
1100
|
+
}
|
|
1101
|
+
const colKey = colKeyGen.value(col);
|
|
1102
|
+
thMap.set(colKey, Object.assign({ textAlign: col.headerAlign }, style, getFixedStyle(TagType.TH, col, depth)));
|
|
1103
|
+
tdMap.set(colKey, Object.assign({ textAlign: col.align }, style, getFixedStyle(TagType.TD, col, depth)));
|
|
1104
|
+
});
|
|
1105
|
+
});
|
|
1106
|
+
return {
|
|
1107
|
+
[TagType.TH]: thMap,
|
|
1108
|
+
[TagType.TD]: tdMap,
|
|
1109
|
+
};
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
function getRowIndex(rowIndex: number) {
|
|
1113
|
+
return rowIndex + virtualScroll.value.startIndex;
|
|
1114
|
+
}
|
|
1115
|
+
/** th title */
|
|
1116
|
+
function getHeaderTitle(col: StkTableColumn<DT>): string {
|
|
1117
|
+
const colKey = colKeyGen.value(col);
|
|
1118
|
+
// hide title
|
|
1119
|
+
if (props.hideHeaderTitle === true || (Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(colKey))) {
|
|
1120
|
+
return '';
|
|
1121
|
+
}
|
|
1122
|
+
return col.title || '';
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
function getTRProps(row: PrivateRowDT | null | undefined, index: number) {
|
|
1126
|
+
const rowIndex = getRowIndex(index);
|
|
1127
|
+
const rowKey = rowKeyGen(row);
|
|
1128
|
+
|
|
1129
|
+
let classStr = props.rowClassName(row, rowIndex) || '' + ' ' + (row?.__EXP__ ? 'expanded' : '') + ' ' + (row?.__EXP_R__ ? 'expanded-row' : '');
|
|
1130
|
+
if (currentRowKey.value === rowKey || row === currentRow.value) {
|
|
1131
|
+
classStr += ' active';
|
|
1132
|
+
}
|
|
1133
|
+
if (props.showTrHoverClass && (rowKey === currentHoverRowKey.value || row === currentHoverRow)) {
|
|
1134
|
+
classStr += ' hover';
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
const result = {
|
|
1138
|
+
id: stkTableId + '-' + rowKey,
|
|
1139
|
+
'data-row-key': rowKey,
|
|
1140
|
+
'data-row-i': rowIndex,
|
|
1141
|
+
class: classStr,
|
|
1142
|
+
style: '',
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
const needRowHeight = row?.__EXP_R__ && props.virtual && props.expandConfig?.height;
|
|
1146
|
+
|
|
1147
|
+
if (needRowHeight) {
|
|
1148
|
+
result.style = `--row-height: ${props.expandConfig?.height}px`;
|
|
1149
|
+
}
|
|
1150
|
+
return result;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function getTHProps(col: PrivateStkTableColumn<DT>) {
|
|
1154
|
+
const colKey = colKeyGen.value(col);
|
|
1155
|
+
return {
|
|
1156
|
+
'data-col-key': colKey,
|
|
1157
|
+
draggable: Boolean(isHeaderDraggable(col)),
|
|
1158
|
+
rowspan: virtualX_on.value ? 1 : col.__R_SP__,
|
|
1159
|
+
colspan: col.__C_SP__,
|
|
1160
|
+
style: cellStyleMap.value[TagType.TH].get(colKey),
|
|
1161
|
+
title: getHeaderTitle(col),
|
|
1162
|
+
class: [
|
|
1163
|
+
col.sorter ? 'sortable' : '',
|
|
1164
|
+
colKey === sortCol.value && sortOrderIndex.value !== 0 && 'sorter-' + sortSwitchOrder[sortOrderIndex.value],
|
|
1165
|
+
col.headerClassName,
|
|
1166
|
+
fixedColClassMap.value.get(colKey),
|
|
1167
|
+
],
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
function getTDProps(row: PrivateRowDT | null | undefined, col: StkTableColumn<PrivateRowDT>, rowIndex: number, colIndex: number) {
|
|
1172
|
+
const colKey = colKeyGen.value(col);
|
|
1173
|
+
if (!row) {
|
|
1174
|
+
return {
|
|
1175
|
+
style: cellStyleMap.value[TagType.TD].get(colKey),
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
const cellKey = cellKeyGen(row, col);
|
|
1180
|
+
const classList = [col.className, fixedColClassMap.value.get(colKey)];
|
|
1181
|
+
if (col.mergeCells) {
|
|
1182
|
+
if (hoverMergedCells.value.has(cellKey)) {
|
|
1183
|
+
classList.push('cell-hover');
|
|
1184
|
+
}
|
|
1185
|
+
if (activeMergedCells.value.has(cellKey)) {
|
|
1186
|
+
classList.push('cell-active');
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
if (props.cellActive && currentSelectedCellKey.value === cellKey) {
|
|
1191
|
+
classList.push('active');
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
if (col.type === 'seq') {
|
|
1195
|
+
classList.push('seq-column');
|
|
1196
|
+
} else if (col.type === 'expand' && (row.__EXP__ ? colKeyGen.value(row.__EXP__) === colKey : false)) {
|
|
1197
|
+
classList.push('expanded');
|
|
1198
|
+
} else if (row.__T_EXP__ && col.type === 'tree-node') {
|
|
1199
|
+
classList.push('tree-expanded');
|
|
1200
|
+
} else if (col.type === 'dragRow') {
|
|
1201
|
+
classList.push('drag-row-cell');
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
return {
|
|
1205
|
+
'data-col-key': colKey,
|
|
1206
|
+
style: cellStyleMap.value[TagType.TD].get(colKey),
|
|
1207
|
+
class: classList,
|
|
1208
|
+
...mergeCellsWrapper(row, col, rowIndex, colIndex),
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* 表头点击排序
|
|
1214
|
+
*
|
|
1215
|
+
* en: Sort a column
|
|
1216
|
+
* @param click 是否为点击表头触发
|
|
1217
|
+
* @param options.force sort-remote 开启后是否强制排序
|
|
1218
|
+
* @param options.emit 是否触发回调
|
|
1219
|
+
*/
|
|
1220
|
+
function onColumnSort(col: StkTableColumn<DT> | undefined | null, click = true, options: { force?: boolean; emit?: boolean } = {}) {
|
|
1221
|
+
if (!col) {
|
|
1222
|
+
console.warn('onColumnSort: not found col:', col);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
if (!col.sorter && click) {
|
|
1226
|
+
// 点击表头触发的排序,如果列没有配置sorter则不处理。setSorter 触发的排序则保持通行。
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
options = { force: false, emit: false, ...options };
|
|
1230
|
+
const colKey = colKeyGen.value(col);
|
|
1231
|
+
if (sortCol.value !== colKey) {
|
|
1232
|
+
// 改变排序的列时,重置排序
|
|
1233
|
+
sortCol.value = colKey;
|
|
1234
|
+
sortOrderIndex.value = 0;
|
|
1235
|
+
}
|
|
1236
|
+
const prevOrder = sortSwitchOrder[sortOrderIndex.value];
|
|
1237
|
+
if (click) sortOrderIndex.value++;
|
|
1238
|
+
sortOrderIndex.value = sortOrderIndex.value % 3;
|
|
1239
|
+
|
|
1240
|
+
let order = sortSwitchOrder[sortOrderIndex.value];
|
|
1241
|
+
const sortConfig: SortConfig<DT> = { ...DEFAULT_SORT_CONFIG, ...props.sortConfig, ...col.sortConfig };
|
|
1242
|
+
const { defaultSort } = sortConfig;
|
|
1243
|
+
const colKeyGenValue = colKeyGen.value;
|
|
1244
|
+
|
|
1245
|
+
if (!order && defaultSort) {
|
|
1246
|
+
// if no order ,use default order
|
|
1247
|
+
const defaultColKey = defaultSort.key || defaultSort.dataIndex;
|
|
1248
|
+
if (!defaultColKey) {
|
|
1249
|
+
console.error('sortConfig.defaultSort key or dataIndex is required');
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
if (colKey === defaultColKey && prevOrder === defaultSort.order) {
|
|
1253
|
+
order = sortSwitchOrder.find(o => o !== defaultSort.order && o) as Order;
|
|
1254
|
+
} else {
|
|
1255
|
+
order = defaultSort.order;
|
|
1256
|
+
}
|
|
1257
|
+
sortOrderIndex.value = sortSwitchOrder.indexOf(order);
|
|
1258
|
+
sortCol.value = defaultColKey as string;
|
|
1259
|
+
col = null;
|
|
1260
|
+
for (const row of tableHeaders.value) {
|
|
1261
|
+
const c = row.find(item => colKeyGenValue(item) === defaultColKey);
|
|
1262
|
+
if (c) {
|
|
1263
|
+
col = c;
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
let dataSourceTemp: DT[] = props.dataSource.slice();
|
|
1269
|
+
if (!props.sortRemote || options.force) {
|
|
1270
|
+
const sortOption = col || defaultSort;
|
|
1271
|
+
if (sortOption) {
|
|
1272
|
+
dataSourceTemp = tableSort(sortOption, order, dataSourceTemp, sortConfig);
|
|
1273
|
+
dataSourceCopy.value = isTreeData.value ? flatTreeData(dataSourceTemp) : dataSourceTemp;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
// only emit sort-change event when click
|
|
1277
|
+
if (click || options.emit) {
|
|
1278
|
+
emits('sort-change', col, order, toRaw(dataSourceTemp), sortConfig);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function onRowClick(e: MouseEvent) {
|
|
1283
|
+
const rowIndex = getClosestTrIndex(e);
|
|
1284
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
1285
|
+
if (!row) return;
|
|
1286
|
+
emits('row-click', e, row, { rowIndex });
|
|
1287
|
+
if (rowActiveProp.value.disabled?.(row)) return;
|
|
1288
|
+
const isCurrentRow = props.rowKey ? currentRowKey.value === rowKeyGen(row) : currentRow.value === row;
|
|
1289
|
+
if (isCurrentRow) {
|
|
1290
|
+
if (!rowActiveProp.value.revokable) {
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
setCurrentRow(void 0, { silent: true });
|
|
1294
|
+
} else {
|
|
1295
|
+
setCurrentRow(row, { silent: true });
|
|
1296
|
+
}
|
|
1297
|
+
emits('current-change', e, row, { select: !isCurrentRow });
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
function onRowDblclick(e: MouseEvent) {
|
|
1301
|
+
const rowIndex = getClosestTrIndex(e);
|
|
1302
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
1303
|
+
if (!row) return;
|
|
1304
|
+
emits('row-dblclick', e, row, { rowIndex });
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
function onHeaderMenu(e: MouseEvent) {
|
|
1308
|
+
emits('header-row-menu', e);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
function onRowMenu(e: MouseEvent) {
|
|
1312
|
+
const rowIndex = getClosestTrIndex(e);
|
|
1313
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
1314
|
+
if (!row) return;
|
|
1315
|
+
emits('row-menu', e, row, { rowIndex });
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
function triangleClick(e: MouseEvent, row: DT, col: StkTableColumn<DT>) {
|
|
1319
|
+
if (col.type === 'expand') {
|
|
1320
|
+
toggleExpandRow(row, col);
|
|
1321
|
+
} else if (col.type === 'tree-node') {
|
|
1322
|
+
toggleTreeNode(row, col);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
function onCellClick(e: MouseEvent) {
|
|
1327
|
+
const rowIndex = getClosestTrIndex(e);
|
|
1328
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
1329
|
+
if (!row) return;
|
|
1330
|
+
const colKey = getClosestColKey(e);
|
|
1331
|
+
const col = tableHeaderLast.value.find(item => colKeyGen.value(item) === colKey);
|
|
1332
|
+
if (!col) return;
|
|
1333
|
+
if (props.cellActive) {
|
|
1334
|
+
const cellKey = cellKeyGen(row, col);
|
|
1335
|
+
const result = { row, col, select: false, rowIndex };
|
|
1336
|
+
if (props.selectedCellRevokable && currentSelectedCellKey.value === cellKey) {
|
|
1337
|
+
currentSelectedCellKey.value = void 0;
|
|
1338
|
+
} else {
|
|
1339
|
+
currentSelectedCellKey.value = cellKey;
|
|
1340
|
+
result.select = true;
|
|
1341
|
+
}
|
|
1342
|
+
emits('cell-selected', e, result);
|
|
1343
|
+
}
|
|
1344
|
+
emits('cell-click', e, row, col, { rowIndex });
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
function getCellEventData(e: MouseEvent) {
|
|
1348
|
+
const rowIndex = getClosestTrIndex(e) || 0;
|
|
1349
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
1350
|
+
const colKey = getClosestColKey(e);
|
|
1351
|
+
const col = tableHeaderLast.value.find(item => colKeyGen.value(item) === colKey) as any;
|
|
1352
|
+
return { row, col, rowIndex };
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/** th click */
|
|
1356
|
+
function onHeaderCellClick(e: MouseEvent, col: StkTableColumn<DT>) {
|
|
1357
|
+
onColumnSort(col);
|
|
1358
|
+
emits('header-cell-click', e, col);
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
/** td mouseenter */
|
|
1362
|
+
function onCellMouseEnter(e: MouseEvent) {
|
|
1363
|
+
const { row, col } = getCellEventData(e);
|
|
1364
|
+
emits('cell-mouseenter', e, row, col);
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
/** td mouseleave */
|
|
1368
|
+
function onCellMouseLeave(e: MouseEvent) {
|
|
1369
|
+
const { row, col } = getCellEventData(e);
|
|
1370
|
+
emits('cell-mouseleave', e, row, col);
|
|
1371
|
+
}
|
|
1372
|
+
/** td mouseover event */
|
|
1373
|
+
function onCellMouseOver(e: MouseEvent) {
|
|
1374
|
+
const { row, col } = getCellEventData(e);
|
|
1375
|
+
emits('cell-mouseover', e, row, col);
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
function onCellMouseDown(e: MouseEvent) {
|
|
1379
|
+
const { row, col, rowIndex } = getCellEventData(e);
|
|
1380
|
+
emits('cell-mousedown', e, row, col, { rowIndex });
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* proxy scroll, prevent white screen
|
|
1385
|
+
* @param e
|
|
1386
|
+
*/
|
|
1387
|
+
function onTableWheel(e: WheelEvent) {
|
|
1388
|
+
if (props.smoothScroll) {
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
// if is resizing, not allow scroll
|
|
1392
|
+
if (isColResizing.value) {
|
|
1393
|
+
e.stopPropagation();
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
const dom = tableContainerRef.value;
|
|
1397
|
+
if ((!virtual_on.value && !virtualX_on.value) || !dom) return;
|
|
1398
|
+
|
|
1399
|
+
const { deltaY, deltaX, shiftKey } = e;
|
|
1400
|
+
|
|
1401
|
+
if (virtual_on.value && deltaY && !shiftKey) {
|
|
1402
|
+
const { containerHeight, scrollTop, scrollHeight } = virtualScroll.value;
|
|
1403
|
+
const isScrollBottom = scrollHeight - containerHeight - scrollTop < 10;
|
|
1404
|
+
if ((deltaY > 0 && !isScrollBottom) || (deltaY < 0 && scrollTop > 0)) {
|
|
1405
|
+
e.preventDefault(); // parent element scroll
|
|
1406
|
+
}
|
|
1407
|
+
dom.scrollTop += deltaY;
|
|
1408
|
+
}
|
|
1409
|
+
if (virtualX_on.value) {
|
|
1410
|
+
const { containerWidth, scrollLeft, scrollWidth } = virtualScrollX.value;
|
|
1411
|
+
const isScrollRight = scrollWidth - containerWidth - scrollLeft < 10;
|
|
1412
|
+
let distance = deltaX;
|
|
1413
|
+
if (shiftKey && deltaY) {
|
|
1414
|
+
distance = deltaY;
|
|
1415
|
+
}
|
|
1416
|
+
if ((distance > 0 && !isScrollRight) || (distance < 0 && scrollLeft > 0)) {
|
|
1417
|
+
e.preventDefault();
|
|
1418
|
+
}
|
|
1419
|
+
dom.scrollLeft += distance;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
/**
|
|
1424
|
+
* @param e scrollEvent
|
|
1425
|
+
*/
|
|
1426
|
+
function onTableScroll(e: Event) {
|
|
1427
|
+
if (!e?.target) return;
|
|
1428
|
+
|
|
1429
|
+
const { scrollTop, scrollLeft } = e.target as HTMLElement;
|
|
1430
|
+
const { scrollTop: vScrollTop } = virtualScroll.value;
|
|
1431
|
+
const { scrollLeft: vScrollLeft } = virtualScrollX.value;
|
|
1432
|
+
const isYScroll = scrollTop !== vScrollTop;
|
|
1433
|
+
const isXScroll = scrollLeft !== vScrollLeft;
|
|
1434
|
+
|
|
1435
|
+
if (isYScroll) {
|
|
1436
|
+
updateVirtualScrollY(scrollTop);
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
if (isXScroll) {
|
|
1440
|
+
if (virtualX_on.value) {
|
|
1441
|
+
updateVirtualScrollX(scrollLeft);
|
|
1442
|
+
} else {
|
|
1443
|
+
// 非虚拟滚动也记录一下滚动条位置。用于判断isXScroll
|
|
1444
|
+
virtualScrollX.value.scrollLeft = scrollLeft;
|
|
1445
|
+
}
|
|
1446
|
+
updateFixedShadow(virtualScrollX);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
if (isYScroll) {
|
|
1450
|
+
const { startIndex, endIndex } = virtualScroll.value;
|
|
1451
|
+
emits('scroll', e, { startIndex, endIndex });
|
|
1452
|
+
}
|
|
1453
|
+
if (isXScroll) {
|
|
1454
|
+
emits('scroll-x', e);
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
// 更新自定义滚动条位置
|
|
1458
|
+
updateCustomScrollbar();
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/** tr hover */
|
|
1462
|
+
function onTrMouseOver(e: MouseEvent) {
|
|
1463
|
+
const tr = getClosestTr(e);
|
|
1464
|
+
if (!tr) return;
|
|
1465
|
+
const rowIndex = Number(tr.dataset.rowI);
|
|
1466
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
1467
|
+
if (currentHoverRow === row) return;
|
|
1468
|
+
currentHoverRow = row;
|
|
1469
|
+
const rowKey = tr.dataset.rowKey;
|
|
1470
|
+
if (props.showTrHoverClass) {
|
|
1471
|
+
currentHoverRowKey.value = rowKey || null;
|
|
1472
|
+
}
|
|
1473
|
+
if (props.rowHover) {
|
|
1474
|
+
updateHoverMergedCells(rowKey);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
function onTrMouseLeave(e: MouseEvent) {
|
|
1479
|
+
if ((e.target as HTMLElement).tagName !== 'TR') return;
|
|
1480
|
+
currentHoverRow = null;
|
|
1481
|
+
if (props.showTrHoverClass) {
|
|
1482
|
+
currentHoverRowKey.value = null;
|
|
1483
|
+
}
|
|
1484
|
+
if (props.rowHover) {
|
|
1485
|
+
updateHoverMergedCells(void 0);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* 选中一行
|
|
1491
|
+
*
|
|
1492
|
+
* en: Select a row
|
|
1493
|
+
* @param {string} rowKeyOrRow selected rowKey, undefined to unselect
|
|
1494
|
+
* @param {boolean} option.silent if set true not emit `current-change`. default:false
|
|
1495
|
+
* @param {boolean} option.deep if set true, deep search in children. default:false
|
|
1496
|
+
*/
|
|
1497
|
+
function setCurrentRow(rowKeyOrRow: string | undefined | DT, option: { silent?: boolean; deep?: boolean } = { silent: false, deep: false }) {
|
|
1498
|
+
const select = rowKeyOrRow !== void 0;
|
|
1499
|
+
const currentRowTemp = currentRow.value;
|
|
1500
|
+
if (!select) {
|
|
1501
|
+
currentRow.value = void 0;
|
|
1502
|
+
currentRowKey.value = void 0;
|
|
1503
|
+
updateActiveMergedCells(true);
|
|
1504
|
+
} else if (typeof rowKeyOrRow === 'string') {
|
|
1505
|
+
const findRowByKey = (data: DT[], key: string): DT | null => {
|
|
1506
|
+
for (let i = 0; i < data.length; i++) {
|
|
1507
|
+
const item = data[i];
|
|
1508
|
+
if (rowKeyGen(item) === key) {
|
|
1509
|
+
return item;
|
|
1510
|
+
}
|
|
1511
|
+
if (option.deep && item.children?.length) {
|
|
1512
|
+
const found = findRowByKey(item.children, key);
|
|
1513
|
+
if (found) {
|
|
1514
|
+
return found;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
return null;
|
|
1519
|
+
};
|
|
1520
|
+
|
|
1521
|
+
currentRowKey.value = rowKeyOrRow;
|
|
1522
|
+
updateActiveMergedCells(false, currentRowKey.value);
|
|
1523
|
+
const row = findRowByKey(dataSourceCopy.value || [], rowKeyOrRow);
|
|
1524
|
+
if (!row) {
|
|
1525
|
+
console.warn('setCurrentRow failed.rowKey:', rowKeyOrRow);
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
currentRow.value = row;
|
|
1529
|
+
} else {
|
|
1530
|
+
currentRow.value = rowKeyOrRow;
|
|
1531
|
+
currentRowKey.value = rowKeyGen(rowKeyOrRow);
|
|
1532
|
+
updateActiveMergedCells(false, currentRowKey.value);
|
|
1533
|
+
}
|
|
1534
|
+
if (!option.silent) {
|
|
1535
|
+
emits('current-change', /** no Event */ null, select ? currentRow.value : currentRowTemp, { select });
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* set highlight active cell (props.cellActive=true)
|
|
1541
|
+
* @param row row if undefined, clear highlight
|
|
1542
|
+
* @param col column
|
|
1543
|
+
* @param option.silent if emit current-change. default:false(not emit `current-change`)
|
|
1544
|
+
*/
|
|
1545
|
+
function setSelectedCell(row?: DT, col?: StkTableColumn<DT>, option = { silent: false }) {
|
|
1546
|
+
if (!dataSourceCopy.value.length) return;
|
|
1547
|
+
const select = row !== void 0 && col !== void 0;
|
|
1548
|
+
currentSelectedCellKey.value = select ? cellKeyGen(row, col) : void 0;
|
|
1549
|
+
if (!option.silent) {
|
|
1550
|
+
emits('cell-selected', /** no Event */ null, { row, col, select });
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* 设置表头排序状态。
|
|
1556
|
+
* @param colKey 列唯一键字段。如果你想要取消排序状态,请使用`resetSorter`
|
|
1557
|
+
* @param order 正序倒序
|
|
1558
|
+
* @param option.sortOption 指定排序参数。同 StkTableColumn 中排序相关字段。建议从columns中find得到。
|
|
1559
|
+
* @param option.sort 是否触发排序-默认true
|
|
1560
|
+
* @param option.silent 是否禁止触发回调-默认true
|
|
1561
|
+
* @param option.force 是否触发排序-默认true
|
|
1562
|
+
* @return 表格数据
|
|
1563
|
+
*/
|
|
1564
|
+
function setSorter(colKey: string, order: Order, option: { sortOption?: SortOption<DT>; force?: boolean; silent?: boolean; sort?: boolean } = {}) {
|
|
1565
|
+
const newOption = { silent: true, sortOption: null, sort: true, ...option };
|
|
1566
|
+
sortCol.value = colKey;
|
|
1567
|
+
sortOrderIndex.value = sortSwitchOrder.indexOf(order);
|
|
1568
|
+
const colKeyGenValue = colKeyGen.value;
|
|
1569
|
+
|
|
1570
|
+
if (newOption.sort && dataSourceCopy.value?.length) {
|
|
1571
|
+
const column = newOption.sortOption || tableHeaderLast.value.find(it => colKeyGenValue(it) === sortCol.value);
|
|
1572
|
+
if (column) onColumnSort(column, false, { force: option.force ?? true, emit: !newOption.silent });
|
|
1573
|
+
else console.warn('Can not find column by key:', sortCol.value);
|
|
1574
|
+
}
|
|
1575
|
+
return dataSourceCopy.value;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
function resetSorter() {
|
|
1579
|
+
sortCol.value = void 0;
|
|
1580
|
+
sortOrderIndex.value = 0;
|
|
1581
|
+
dataSourceCopy.value = props.dataSource.slice();
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
/**
|
|
1585
|
+
* set scroll bar position
|
|
1586
|
+
* @param top null to not change
|
|
1587
|
+
* @param left null to not change
|
|
1588
|
+
*/
|
|
1589
|
+
function scrollTo(top: number | null = 0, left: number | null = 0) {
|
|
1590
|
+
if (!tableContainerRef.value) return;
|
|
1591
|
+
if (top !== null) tableContainerRef.value.scrollTop = top;
|
|
1592
|
+
if (left !== null) tableContainerRef.value.scrollLeft = left;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
/** get current table data */
|
|
1596
|
+
function getTableData() {
|
|
1597
|
+
return toRaw(dataSourceCopy.value);
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
/**
|
|
1601
|
+
* get current sort info
|
|
1602
|
+
* @return {{key:string,order:Order}[]}
|
|
1603
|
+
*/
|
|
1604
|
+
function getSortColumns() {
|
|
1605
|
+
const sortOrder = sortSwitchOrder[sortOrderIndex.value];
|
|
1606
|
+
if (!sortOrder) return [];
|
|
1607
|
+
return [{ key: sortCol.value, order: sortOrder }];
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
defineExpose({
|
|
1611
|
+
/**
|
|
1612
|
+
* 重新计算虚拟列表宽高
|
|
1613
|
+
*
|
|
1614
|
+
* en: calc virtual scroll x & y info
|
|
1615
|
+
* @see {@link initVirtualScroll}
|
|
1616
|
+
*/
|
|
1617
|
+
initVirtualScroll,
|
|
1618
|
+
/**
|
|
1619
|
+
* 重新计算虚拟列表宽度
|
|
1620
|
+
*
|
|
1621
|
+
* en: calc virtual scroll x
|
|
1622
|
+
* @see {@link initVirtualScrollX}
|
|
1623
|
+
*/
|
|
1624
|
+
initVirtualScrollX,
|
|
1625
|
+
/**
|
|
1626
|
+
* 重新计算虚拟列表高度
|
|
1627
|
+
*
|
|
1628
|
+
* en: calc virtual scroll y
|
|
1629
|
+
* @see {@link initVirtualScrollY}
|
|
1630
|
+
*/
|
|
1631
|
+
initVirtualScrollY,
|
|
1632
|
+
/**
|
|
1633
|
+
* 选中一行
|
|
1634
|
+
*
|
|
1635
|
+
* en:select a row
|
|
1636
|
+
* @see {@link setCurrentRow}
|
|
1637
|
+
*/
|
|
1638
|
+
setCurrentRow,
|
|
1639
|
+
/**
|
|
1640
|
+
* 取消选中单元格
|
|
1641
|
+
*
|
|
1642
|
+
* en: set highlight active cell (props.cellActive=true)
|
|
1643
|
+
* @see {@link setSelectedCell}
|
|
1644
|
+
*/
|
|
1645
|
+
setSelectedCell,
|
|
1646
|
+
/**
|
|
1647
|
+
* 设置高亮单元格
|
|
1648
|
+
*
|
|
1649
|
+
* en: Set highlight cell
|
|
1650
|
+
* @see {@link setHighlightDimCell}
|
|
1651
|
+
*/
|
|
1652
|
+
setHighlightDimCell,
|
|
1653
|
+
/**
|
|
1654
|
+
* 设置高亮行
|
|
1655
|
+
*
|
|
1656
|
+
* en: Set highlight row
|
|
1657
|
+
* @see {@link setHighlightDimRow}
|
|
1658
|
+
*/
|
|
1659
|
+
setHighlightDimRow,
|
|
1660
|
+
/**
|
|
1661
|
+
* 表格排序列colKey
|
|
1662
|
+
*
|
|
1663
|
+
* en: Table sort column colKey
|
|
1664
|
+
*/
|
|
1665
|
+
sortCol,
|
|
1666
|
+
/**
|
|
1667
|
+
* 表格排序列顺序
|
|
1668
|
+
*
|
|
1669
|
+
* en: get current sort info
|
|
1670
|
+
* @see {@link getSortColumns}
|
|
1671
|
+
*/
|
|
1672
|
+
getSortColumns,
|
|
1673
|
+
/**
|
|
1674
|
+
* 设置表头排序状态
|
|
1675
|
+
*
|
|
1676
|
+
* en: Set the sort status of the table header
|
|
1677
|
+
* @see {@link setSorter}
|
|
1678
|
+
*/
|
|
1679
|
+
setSorter,
|
|
1680
|
+
/**
|
|
1681
|
+
* 重置sorter状态
|
|
1682
|
+
*
|
|
1683
|
+
* en: Reset the sorter status
|
|
1684
|
+
* @see {@link resetSorter}
|
|
1685
|
+
*/
|
|
1686
|
+
resetSorter,
|
|
1687
|
+
/**
|
|
1688
|
+
* 滚动至
|
|
1689
|
+
*
|
|
1690
|
+
* en: Scroll to
|
|
1691
|
+
* @see {@link scrollTo}
|
|
1692
|
+
*/
|
|
1693
|
+
scrollTo,
|
|
1694
|
+
/**
|
|
1695
|
+
* 获取表格数据
|
|
1696
|
+
*
|
|
1697
|
+
* en: Get table data
|
|
1698
|
+
* @see {@link getTableData}
|
|
1699
|
+
*/
|
|
1700
|
+
getTableData,
|
|
1701
|
+
/**
|
|
1702
|
+
* 设置展开的行
|
|
1703
|
+
*
|
|
1704
|
+
* en: Set expanded rows
|
|
1705
|
+
* @see {@link setRowExpand}
|
|
1706
|
+
*/
|
|
1707
|
+
setRowExpand,
|
|
1708
|
+
/**
|
|
1709
|
+
* 不定行高时,如果行高有变化,则调用此方法更新行高。
|
|
1710
|
+
*
|
|
1711
|
+
* en: When the row height is not fixed, call this method to update the row height if the row height changes.
|
|
1712
|
+
* @see {@link setAutoHeight}
|
|
1713
|
+
*/
|
|
1714
|
+
setAutoHeight,
|
|
1715
|
+
/**
|
|
1716
|
+
* 清除所有行高
|
|
1717
|
+
*
|
|
1718
|
+
* en: Clear all row heights
|
|
1719
|
+
* @see {@link clearAllAutoHeight}
|
|
1720
|
+
*/
|
|
1721
|
+
clearAllAutoHeight,
|
|
1722
|
+
/**
|
|
1723
|
+
* 设置树节点展开状态
|
|
1724
|
+
*
|
|
1725
|
+
* en: Set tree node expand state
|
|
1726
|
+
* @see {@link setTreeExpand}
|
|
1727
|
+
*/
|
|
1728
|
+
setTreeExpand,
|
|
1729
|
+
});
|
|
1730
|
+
</script>
|