stk-table-vue 0.6.14 → 0.6.16
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/stk-table-vue.js +28 -10
- package/package.json +1 -1
- package/src/StkTable/useVirtualScroll.ts +32 -15
package/lib/stk-table-vue.js
CHANGED
|
@@ -1089,9 +1089,18 @@ function useVirtualScroll({
|
|
|
1089
1089
|
});
|
|
1090
1090
|
const virtual_offsetBottom = computed(() => {
|
|
1091
1091
|
if (!virtual_on.value) return 0;
|
|
1092
|
-
const { startIndex } = virtualScroll.value;
|
|
1092
|
+
const { startIndex, endIndex } = virtualScroll.value;
|
|
1093
|
+
const dataSourceCopyValue = dataSourceCopy.value;
|
|
1093
1094
|
const rowHeight = getRowHeightFn.value();
|
|
1094
|
-
|
|
1095
|
+
if (props.autoRowHeight) {
|
|
1096
|
+
let offsetBottom = 0;
|
|
1097
|
+
for (let i = endIndex + 1; i < dataSourceCopyValue.length; i++) {
|
|
1098
|
+
const rowHeight2 = getRowHeightFn.value(dataSourceCopyValue[i]);
|
|
1099
|
+
offsetBottom += rowHeight2;
|
|
1100
|
+
}
|
|
1101
|
+
return offsetBottom;
|
|
1102
|
+
}
|
|
1103
|
+
return (dataSourceCopyValue.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
|
|
1095
1104
|
});
|
|
1096
1105
|
const virtualX_on = computed(() => {
|
|
1097
1106
|
return props.virtualX && tableHeaderLast.value.reduce((sum, col) => sum += getCalculatedColWidth(col), 0) > virtualScrollX.value.containerWidth + 100;
|
|
@@ -1156,7 +1165,7 @@ function useVirtualScroll({
|
|
|
1156
1165
|
}
|
|
1157
1166
|
const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
|
|
1158
1167
|
let scrollTop = ((_a = tableContainerRef.value) == null ? void 0 : _a.scrollTop) || 0;
|
|
1159
|
-
const rowHeight = getRowHeightFn.value(
|
|
1168
|
+
const rowHeight = getRowHeightFn.value();
|
|
1160
1169
|
const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
|
|
1161
1170
|
const { headless } = props;
|
|
1162
1171
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
@@ -1183,9 +1192,9 @@ function useVirtualScroll({
|
|
|
1183
1192
|
const autoRowHeightMap = /* @__PURE__ */ new Map();
|
|
1184
1193
|
function setAutoHeight(rowKey, height) {
|
|
1185
1194
|
if (!height) {
|
|
1186
|
-
autoRowHeightMap.delete(rowKey);
|
|
1195
|
+
autoRowHeightMap.delete(String(rowKey));
|
|
1187
1196
|
} else {
|
|
1188
|
-
autoRowHeightMap.set(rowKey, height);
|
|
1197
|
+
autoRowHeightMap.set(String(rowKey), height);
|
|
1189
1198
|
}
|
|
1190
1199
|
}
|
|
1191
1200
|
function clearAllAutoHeight() {
|
|
@@ -1195,7 +1204,7 @@ function useVirtualScroll({
|
|
|
1195
1204
|
var _a;
|
|
1196
1205
|
if (!row) return;
|
|
1197
1206
|
const rowKey = rowKeyGen(row);
|
|
1198
|
-
const storedHeight = autoRowHeightMap.get(rowKey);
|
|
1207
|
+
const storedHeight = autoRowHeightMap.get(String(rowKey));
|
|
1199
1208
|
if (storedHeight) {
|
|
1200
1209
|
return storedHeight;
|
|
1201
1210
|
}
|
|
@@ -1210,17 +1219,18 @@ function useVirtualScroll({
|
|
|
1210
1219
|
}
|
|
1211
1220
|
function updateVirtualScrollY(sTop = 0) {
|
|
1212
1221
|
var _a;
|
|
1213
|
-
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
|
|
1222
|
+
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex, containerHeight } = virtualScroll.value;
|
|
1214
1223
|
virtualScroll.value.scrollTop = sTop;
|
|
1215
1224
|
if (!virtual_on.value) {
|
|
1216
1225
|
return;
|
|
1217
1226
|
}
|
|
1218
1227
|
const dataSourceCopyTemp = dataSourceCopy.value;
|
|
1219
|
-
const rowHeight = getRowHeightFn.value(
|
|
1228
|
+
const rowHeight = getRowHeightFn.value();
|
|
1220
1229
|
const { autoRowHeight, stripe, optimizeVue2Scroll } = props;
|
|
1230
|
+
const dataLength = dataSourceCopyTemp.length;
|
|
1221
1231
|
let startIndex = 0;
|
|
1232
|
+
let endIndex = dataLength;
|
|
1222
1233
|
let autoRowHeightTop = 0;
|
|
1223
|
-
const dataLength = dataSourceCopyTemp.length;
|
|
1224
1234
|
if (autoRowHeight || hasExpandCol.value) {
|
|
1225
1235
|
if (autoRowHeight) {
|
|
1226
1236
|
(_a = trRef.value) == null ? void 0 : _a.forEach((tr) => {
|
|
@@ -1238,10 +1248,18 @@ function useVirtualScroll({
|
|
|
1238
1248
|
break;
|
|
1239
1249
|
}
|
|
1240
1250
|
}
|
|
1251
|
+
let containerHeightSum = 0;
|
|
1252
|
+
for (let i = startIndex + 1; i < dataLength; i++) {
|
|
1253
|
+
containerHeightSum += getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
1254
|
+
if (containerHeightSum >= containerHeight) {
|
|
1255
|
+
endIndex = i;
|
|
1256
|
+
break;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1241
1259
|
} else {
|
|
1242
1260
|
startIndex = Math.floor(sTop / rowHeight);
|
|
1261
|
+
endIndex = startIndex + pageSize;
|
|
1243
1262
|
}
|
|
1244
|
-
let endIndex = startIndex + pageSize;
|
|
1245
1263
|
if (stripe && startIndex > 0 && startIndex % 2) {
|
|
1246
1264
|
startIndex -= 1;
|
|
1247
1265
|
if (autoRowHeight || hasExpandCol.value) {
|
package/package.json
CHANGED
|
@@ -107,9 +107,19 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
107
107
|
|
|
108
108
|
const virtual_offsetBottom = computed(() => {
|
|
109
109
|
if (!virtual_on.value) return 0;
|
|
110
|
-
const { startIndex } = virtualScroll.value;
|
|
110
|
+
const { startIndex, endIndex } = virtualScroll.value;
|
|
111
|
+
const dataSourceCopyValue = dataSourceCopy.value;
|
|
111
112
|
const rowHeight = getRowHeightFn.value();
|
|
112
|
-
|
|
113
|
+
if (props.autoRowHeight) {
|
|
114
|
+
let offsetBottom = 0;
|
|
115
|
+
for (let i = endIndex + 1; i < dataSourceCopyValue.length; i++) {
|
|
116
|
+
const rowHeight = getRowHeightFn.value(dataSourceCopyValue[i]);
|
|
117
|
+
offsetBottom += rowHeight;
|
|
118
|
+
}
|
|
119
|
+
return offsetBottom;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return (dataSourceCopyValue.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
|
|
113
123
|
});
|
|
114
124
|
|
|
115
125
|
const virtualX_on = computed(() => {
|
|
@@ -202,7 +212,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
202
212
|
const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
|
|
203
213
|
let scrollTop = tableContainerRef.value?.scrollTop || 0;
|
|
204
214
|
|
|
205
|
-
const rowHeight = getRowHeightFn.value(
|
|
215
|
+
const rowHeight = getRowHeightFn.value();
|
|
206
216
|
const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
|
|
207
217
|
const { headless } = props;
|
|
208
218
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
@@ -232,13 +242,13 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
232
242
|
let vue2ScrollYTimeout: null | number = null;
|
|
233
243
|
|
|
234
244
|
/** every row actual height */
|
|
235
|
-
const autoRowHeightMap = new Map<
|
|
245
|
+
const autoRowHeightMap = new Map<string, number>();
|
|
236
246
|
/** 如果行高度有变化,则要调用此方法清除保存的行高 */
|
|
237
247
|
function setAutoHeight(rowKey: UniqKey, height?: number | null) {
|
|
238
248
|
if (!height) {
|
|
239
|
-
autoRowHeightMap.delete(rowKey);
|
|
249
|
+
autoRowHeightMap.delete(String(rowKey));
|
|
240
250
|
} else {
|
|
241
|
-
autoRowHeightMap.set(rowKey, height);
|
|
251
|
+
autoRowHeightMap.set(String(rowKey), height);
|
|
242
252
|
}
|
|
243
253
|
}
|
|
244
254
|
|
|
@@ -249,7 +259,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
249
259
|
function getAutoRowHeight(row?: DT) {
|
|
250
260
|
if (!row) return;
|
|
251
261
|
const rowKey = rowKeyGen(row);
|
|
252
|
-
const storedHeight = autoRowHeightMap.get(rowKey);
|
|
262
|
+
const storedHeight = autoRowHeightMap.get(String(rowKey));
|
|
253
263
|
if (storedHeight) {
|
|
254
264
|
return storedHeight;
|
|
255
265
|
}
|
|
@@ -265,7 +275,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
265
275
|
|
|
266
276
|
/** 通过滚动条位置,计算虚拟滚动的参数 */
|
|
267
277
|
function updateVirtualScrollY(sTop = 0) {
|
|
268
|
-
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
|
|
278
|
+
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex, containerHeight } = virtualScroll.value;
|
|
269
279
|
// 先更新滚动条位置记录,其他地方有依赖。(stripe 时ArrowUp/Down滚动依赖)
|
|
270
280
|
virtualScroll.value.scrollTop = sTop;
|
|
271
281
|
|
|
@@ -275,12 +285,13 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
275
285
|
}
|
|
276
286
|
|
|
277
287
|
const dataSourceCopyTemp = dataSourceCopy.value;
|
|
278
|
-
const rowHeight = getRowHeightFn.value(
|
|
288
|
+
const rowHeight = getRowHeightFn.value();
|
|
279
289
|
const { autoRowHeight, stripe, optimizeVue2Scroll } = props;
|
|
290
|
+
const dataLength = dataSourceCopyTemp.length;
|
|
280
291
|
|
|
281
292
|
let startIndex = 0;
|
|
293
|
+
let endIndex = dataLength;
|
|
282
294
|
let autoRowHeightTop = 0;
|
|
283
|
-
const dataLength = dataSourceCopyTemp.length;
|
|
284
295
|
|
|
285
296
|
if (autoRowHeight || hasExpandCol.value) {
|
|
286
297
|
if (autoRowHeight) {
|
|
@@ -290,7 +301,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
290
301
|
autoRowHeightMap.set(rowKey, tr.offsetHeight);
|
|
291
302
|
});
|
|
292
303
|
}
|
|
293
|
-
|
|
304
|
+
// calculate startIndex
|
|
294
305
|
for (let i = 0; i < dataLength; i++) {
|
|
295
306
|
const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
296
307
|
autoRowHeightTop += height;
|
|
@@ -300,12 +311,20 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
300
311
|
break;
|
|
301
312
|
}
|
|
302
313
|
}
|
|
314
|
+
// calculate endIndex
|
|
315
|
+
let containerHeightSum = 0;
|
|
316
|
+
for (let i = startIndex + 1; i < dataLength; i++) {
|
|
317
|
+
containerHeightSum += getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
318
|
+
if (containerHeightSum >= containerHeight) {
|
|
319
|
+
endIndex = i;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
303
323
|
} else {
|
|
304
324
|
startIndex = Math.floor(sTop / rowHeight);
|
|
325
|
+
endIndex = startIndex + pageSize;
|
|
305
326
|
}
|
|
306
327
|
|
|
307
|
-
let endIndex = startIndex + pageSize;
|
|
308
|
-
|
|
309
328
|
if (stripe && startIndex > 0 && startIndex % 2) {
|
|
310
329
|
// 斑马纹情况下,每滚动偶数行才加载。防止斑马纹错位。
|
|
311
330
|
startIndex -= 1; // 奇数-1变成偶数
|
|
@@ -316,8 +335,6 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
316
335
|
}
|
|
317
336
|
|
|
318
337
|
startIndex = Math.max(0, startIndex);
|
|
319
|
-
|
|
320
|
-
// 溢出修正
|
|
321
338
|
endIndex = Math.min(endIndex, dataLength);
|
|
322
339
|
|
|
323
340
|
if (startIndex >= endIndex) {
|