Skip to content

Commit 61d3dff

Browse files
committed
优化
1 parent 2b27ea6 commit 61d3dff

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

packages/ve-table/src/index.jsx

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,53 +1020,49 @@ export default {
10201020
}
10211021
return tempIndex;
10221022
},
1023-
// virtual scroll handler
1024-
tableContainerScrollHandler() {
1023+
// table container virtual scroll handler
1024+
tableContainerVirtualScrollHandler() {
10251025
const tableContainerRef = this.$refs[this.tableContainerRef];
10261026

10271027
this.setScrolling(tableContainerRef);
10281028

1029-
if (this.isVirtualScroll) {
1030-
const {
1031-
virtualScrollVisibleCount: visibleCount,
1032-
virtualScrollOption,
1033-
} = this;
1034-
1035-
//当前滚动位置
1036-
let scrollTop = tableContainerRef.scrollTop;
1029+
const {
1030+
virtualScrollVisibleCount: visibleCount,
1031+
virtualScrollOption,
1032+
} = this;
10371033

1038-
//此时的开始索引
1039-
let visibleStartIndex =
1040-
this.getVirtualScrollStartIndex(scrollTop);
1041-
this.$options.customOption.virtualScrollStartIndex =
1042-
visibleStartIndex;
1034+
//当前滚动位置
1035+
let scrollTop = tableContainerRef.scrollTop;
10431036

1044-
//此时的结束索引
1045-
let visibleEndIndex = visibleStartIndex + visibleCount;
1046-
this.$options.customOption.virtualScrollEndIndex =
1047-
visibleEndIndex;
1037+
//此时的开始索引
1038+
let visibleStartIndex = this.getVirtualScrollStartIndex(scrollTop);
1039+
this.$options.customOption.virtualScrollStartIndex =
1040+
visibleStartIndex;
10481041

1049-
//此时的偏移量
1050-
this.setVirtualScrollStartOffset();
1042+
//此时的结束索引
1043+
let visibleEndIndex = visibleStartIndex + visibleCount;
1044+
this.$options.customOption.virtualScrollEndIndex = visibleEndIndex;
10511045

1052-
const { scrolling } = virtualScrollOption;
1053-
if (isFunction(scrolling)) {
1054-
const visibleAboveCount = this.getVirtualScrollAboveCount();
1055-
const visibleBelowCount = this.getVirtualScrollBelowCount();
1046+
//此时的偏移量
1047+
this.setVirtualScrollStartOffset();
10561048

1057-
let startRowIndex = visibleStartIndex - visibleAboveCount;
1049+
const { scrolling } = virtualScrollOption;
1050+
if (isFunction(scrolling)) {
1051+
const visibleAboveCount = this.getVirtualScrollAboveCount();
1052+
const visibleBelowCount = this.getVirtualScrollBelowCount();
10581053

1059-
scrolling({
1060-
startRowIndex: startRowIndex > 0 ? startRowIndex : 0,
1061-
visibleStartIndex,
1062-
visibleEndIndex,
1063-
visibleAboveCount,
1064-
visibleBelowCount,
1065-
});
1066-
}
1054+
let startRowIndex = visibleStartIndex - visibleAboveCount;
10671055

1068-
this.setVirtualScrollVisibleData();
1056+
scrolling({
1057+
startRowIndex: startRowIndex > 0 ? startRowIndex : 0,
1058+
visibleStartIndex,
1059+
visibleEndIndex,
1060+
visibleAboveCount,
1061+
visibleBelowCount,
1062+
});
10691063
}
1064+
1065+
this.setVirtualScrollVisibleData();
10701066
},
10711067
// debounce scroll ended
10721068
debounceScrollEnded() {
@@ -1097,7 +1093,7 @@ export default {
10971093
this.$options.customOption.virtualScrollEndIndex =
10981094
startIndex + this.virtualScrollVisibleCount;
10991095

1100-
this.tableContainerScrollHandler();
1096+
this.tableContainerVirtualScrollHandler();
11011097
this.setVirtualPhantomHeight();
11021098
}
11031099
},
@@ -1795,7 +1791,7 @@ export default {
17951791
on: {
17961792
scroll: () => {
17971793
if (isVirtualScroll) {
1798-
this.tableContainerScrollHandler();
1794+
this.tableContainerVirtualScrollHandler();
17991795

18001796
const {
18011797
virtualScrollStartIndex: startIndex,

0 commit comments

Comments
 (0)