stk-table-vue 0.8.5 → 0.8.7
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/lib/src/StkTable/useVirtualScroll.d.ts +1 -0
- package/lib/stk-table-vue.js +2806 -2797
- package/lib/style.css +414 -412
- package/package.json +1 -1
- package/src/StkTable/StkTable.vue +20 -12
- package/src/StkTable/style.less +2 -0
- package/src/StkTable/useVirtualScroll.ts +6 -10
package/package.json
CHANGED
|
@@ -36,12 +36,7 @@
|
|
|
36
36
|
@scroll="onTableScroll"
|
|
37
37
|
@wheel="onTableWheel"
|
|
38
38
|
>
|
|
39
|
-
|
|
40
|
-
<div
|
|
41
|
-
v-if="isSRBRActive && virtual"
|
|
42
|
-
class="row-by-row-table-height"
|
|
43
|
-
:style="{ height: dataSourceCopy.length * virtualScroll.rowHeight + 'px' }"
|
|
44
|
-
><!-- 这个元素用于整数行虚拟滚动时,撑开父容器的高度) --></div>
|
|
39
|
+
<div v-if="SRBRTotalHeight" class="row-by-row-table-height" :style="`height: ${SRBRTotalHeight}px`"></div>
|
|
45
40
|
|
|
46
41
|
<div v-if="colResizable" ref="colResizeIndicatorRef" class="column-resize-indicator"></div>
|
|
47
42
|
<table
|
|
@@ -83,7 +78,6 @@
|
|
|
83
78
|
@drop="onThDrop"
|
|
84
79
|
@dragover="onThDragOver"
|
|
85
80
|
>
|
|
86
|
-
<!-- 列宽拖动handler -->
|
|
87
81
|
<div
|
|
88
82
|
v-if="colResizeOn(col) && colIndex > 0"
|
|
89
83
|
class="table-header-resizer left"
|
|
@@ -241,6 +235,7 @@
|
|
|
241
235
|
</template>
|
|
242
236
|
</tr>
|
|
243
237
|
<tr v-if="virtual_on && !isSRBRActive" :style="`height: ${virtual_offsetBottom}px`"></tr>
|
|
238
|
+
<tr v-if="SRBRBottomHeight" :style="`height: ${SRBRBottomHeight}px`"></tr>
|
|
244
239
|
</tbody>
|
|
245
240
|
</table>
|
|
246
241
|
<div v-if="(!dataSourceCopy || !dataSourceCopy.length) && showNoData" class="stk-table-no-data" :class="{ 'no-data-full': noDataFull }">
|
|
@@ -745,6 +740,18 @@ const getEmptyCellText = computed(() => {
|
|
|
745
740
|
}
|
|
746
741
|
});
|
|
747
742
|
|
|
743
|
+
/** scroll-row-by-row total-height */
|
|
744
|
+
const SRBRTotalHeight = computed(() => {
|
|
745
|
+
if (!isSRBRActive.value || !props.virtual) return 0;
|
|
746
|
+
return (
|
|
747
|
+
dataSourceCopy.value.length * virtualScroll.value.rowHeight + tableHeaderHeight.value //+
|
|
748
|
+
);
|
|
749
|
+
});
|
|
750
|
+
const SRBRBottomHeight = computed(() => {
|
|
751
|
+
if (!isSRBRActive.value || !props.virtual) return 0;
|
|
752
|
+
return (virtualScroll.value.containerHeight - tableHeaderHeight.value) % virtualScroll.value.rowHeight;
|
|
753
|
+
});
|
|
754
|
+
|
|
748
755
|
const rowKeyGenCache = new WeakMap();
|
|
749
756
|
|
|
750
757
|
const { isSRBRActive } = useScrollRowByRow({ props, tableContainerRef });
|
|
@@ -764,6 +771,7 @@ const {
|
|
|
764
771
|
virtualX_on,
|
|
765
772
|
virtualX_columnPart,
|
|
766
773
|
virtualX_offsetRight,
|
|
774
|
+
tableHeaderHeight,
|
|
767
775
|
initVirtualScroll,
|
|
768
776
|
initVirtualScrollY,
|
|
769
777
|
initVirtualScrollX,
|
|
@@ -881,7 +889,7 @@ watch(
|
|
|
881
889
|
console.warn('invalid dataSource');
|
|
882
890
|
return;
|
|
883
891
|
}
|
|
884
|
-
|
|
892
|
+
|
|
885
893
|
let needInitVirtualScrollY = false;
|
|
886
894
|
if (dataSourceCopy.value.length !== val.length) {
|
|
887
895
|
needInitVirtualScrollY = true;
|
|
@@ -1083,7 +1091,7 @@ const cellStyleMap = computed(() => {
|
|
|
1083
1091
|
});
|
|
1084
1092
|
|
|
1085
1093
|
function getRowIndex(rowIndex: number) {
|
|
1086
|
-
return rowIndex + (virtual_on ? virtualScroll.value.startIndex : 0);
|
|
1094
|
+
return rowIndex + (virtual_on.value ? virtualScroll.value.startIndex : 0);
|
|
1087
1095
|
}
|
|
1088
1096
|
|
|
1089
1097
|
/** th title */
|
|
@@ -1302,13 +1310,13 @@ function onTableWheel(e: WheelEvent) {
|
|
|
1302
1310
|
* 只有虚拟滚动时,才要用 wheel 代理scroll,防止滚动过快导致的白屏。
|
|
1303
1311
|
* 滚动条在边界情况时,not preventDefault 。因为会阻塞父级滚动条滚动。
|
|
1304
1312
|
*/
|
|
1305
|
-
if (virtual_on && deltaY) {
|
|
1313
|
+
if (virtual_on.value && deltaY) {
|
|
1306
1314
|
if ((deltaY > 0 && !isScrollBottom) || (deltaY < 0 && scrollTop > 0)) {
|
|
1307
1315
|
e.preventDefault();
|
|
1308
1316
|
}
|
|
1309
1317
|
dom.scrollTop += deltaY;
|
|
1310
1318
|
}
|
|
1311
|
-
if (virtualX_on && deltaX) {
|
|
1319
|
+
if (virtualX_on.value && deltaX) {
|
|
1312
1320
|
if ((deltaX > 0 && !isScrollRight) || (deltaX < 0 && scrollLeft > 0)) {
|
|
1313
1321
|
e.preventDefault();
|
|
1314
1322
|
}
|
|
@@ -1347,7 +1355,7 @@ function onTableScroll(e: Event) {
|
|
|
1347
1355
|
}
|
|
1348
1356
|
|
|
1349
1357
|
if (isYScroll) {
|
|
1350
|
-
const {
|
|
1358
|
+
const { startIndex, endIndex } = virtualScroll.value;
|
|
1351
1359
|
emits('scroll', e, { startIndex, endIndex });
|
|
1352
1360
|
}
|
|
1353
1361
|
if (isXScroll) {
|
package/src/StkTable/style.less
CHANGED
|
@@ -67,7 +67,8 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
67
67
|
rowKeyGen,
|
|
68
68
|
maxRowSpan,
|
|
69
69
|
}: Option<DT>) {
|
|
70
|
-
const tableHeaderHeight =
|
|
70
|
+
const tableHeaderHeight = computed(() => props.headerRowHeight * tableHeaders.value.length);
|
|
71
|
+
|
|
71
72
|
|
|
72
73
|
const virtualScroll = ref<VirtualScrollStore>({
|
|
73
74
|
containerHeight: 0,
|
|
@@ -188,10 +189,6 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
188
189
|
return rowHeightFn;
|
|
189
190
|
});
|
|
190
191
|
|
|
191
|
-
function getTableHeaderHeight() {
|
|
192
|
-
return props.headerRowHeight * tableHeaders.value.length;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
192
|
/**
|
|
196
193
|
* 初始化虚拟滚动参数
|
|
197
194
|
* @param {number} [height] 虚拟滚动的高度
|
|
@@ -210,18 +207,16 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
210
207
|
console.warn('initVirtualScrollY: height must be a number');
|
|
211
208
|
height = 0;
|
|
212
209
|
}
|
|
213
|
-
const {
|
|
210
|
+
const { clientHeight, scrollHeight } = tableContainerRef.value || {};
|
|
214
211
|
let scrollTop = tableContainerRef.value?.scrollTop || 0;
|
|
215
212
|
|
|
216
213
|
const rowHeight = getRowHeightFn.value();
|
|
217
|
-
const containerHeight = height ||
|
|
214
|
+
const containerHeight = height || clientHeight || DEFAULT_TABLE_HEIGHT;
|
|
218
215
|
const { headless } = props;
|
|
219
216
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
220
|
-
const headerHeight = getTableHeaderHeight();
|
|
221
|
-
tableHeaderHeight.value = headerHeight;
|
|
222
217
|
if (!headless) {
|
|
223
218
|
/** 表头高度占几行表体高度数 */
|
|
224
|
-
const headerToBodyRowHeightCount = Math.floor(
|
|
219
|
+
const headerToBodyRowHeightCount = Math.floor(tableHeaderHeight.value / rowHeight);
|
|
225
220
|
pageSize -= headerToBodyRowHeightCount; //减去表头行数
|
|
226
221
|
}
|
|
227
222
|
const maxScrollTop = dataSourceCopy.value.length * rowHeight + tableHeaderHeight.value - containerHeight;
|
|
@@ -487,6 +482,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
487
482
|
virtualX_on,
|
|
488
483
|
virtualX_columnPart,
|
|
489
484
|
virtualX_offsetRight,
|
|
485
|
+
tableHeaderHeight,
|
|
490
486
|
initVirtualScroll,
|
|
491
487
|
initVirtualScrollY,
|
|
492
488
|
initVirtualScrollX,
|