@@ -17,15 +17,6 @@ import clickoutside from "../../src/directives/clickoutside";
17
17
import { mutations } from "./util/store" ;
18
18
import VueDomResizeObserver from "../../src/comps/resize-observer" ;
19
19
20
- // virtual scroll positions
21
- let virtualScrollPositions = [
22
- /* {
23
- rowKey: 0, // 当前行数据索引
24
- top: 0, // 距离上一个项的高度
25
- bottom: 100, // 距离下一个项的高度
26
- height: 100 // 自身高度
27
- } */
28
- ] ;
29
20
export default {
30
21
name : COMPS_NAME . VE_TABLE ,
31
22
directives : {
@@ -197,6 +188,17 @@ export default {
197
188
colgroups : [ ] ,
198
189
// groupColumns
199
190
groupColumns : [ ] ,
191
+ /*
192
+ // virtual scroll positions(非响应式)
193
+ virtualScrollPositions = [
194
+ {
195
+ rowKey: 0, // 当前行数据索引
196
+ top: 0, // 距离上一个项的高度
197
+ bottom: 100, // 距离下一个项的高度
198
+ height: 100 // 自身高度
199
+ }
200
+ ],
201
+ */
200
202
// virtual scroll start index
201
203
virtualScrollStartIndex : 0 ,
202
204
// virtual scroll end index
@@ -813,7 +815,7 @@ export default {
813
815
? virtualScrollOption . minRowHeight
814
816
: defaultVirtualScrollMinRowHeight ;
815
817
816
- virtualScrollPositions = cloneTableData . map ( ( item , index ) => ( {
818
+ this . virtualScrollPositions = cloneTableData . map ( ( item , index ) => ( {
817
819
rowKey : item [ rowKeyFieldName ] ,
818
820
height : minRowHeight ,
819
821
top : index * minRowHeight ,
@@ -823,24 +825,23 @@ export default {
823
825
} ,
824
826
// list item height change
825
827
bodyTrHeightChange ( { rowKey, height } ) {
826
- const positions = virtualScrollPositions ;
827
828
828
829
//获取真实元素大小,修改对应的尺寸缓存
829
- const index = positions . findIndex ( x => x . rowKey === rowKey ) ;
830
+ const index = this . virtualScrollPositions . findIndex ( x => x . rowKey === rowKey ) ;
830
831
831
- let oldHeight = positions [ index ] . height ;
832
+ let oldHeight = this . virtualScrollPositions [ index ] . height ;
832
833
let dValue = oldHeight - height ;
833
834
//存在差值
834
835
if ( dValue ) {
835
- positions [ index ] . bottom = positions [ index ] . bottom - dValue ;
836
- positions [ index ] . height = height ;
837
- for ( let k = index + 1 ; k < positions . length ; k ++ ) {
838
- positions [ k ] . top = positions [ k - 1 ] . bottom ;
839
- positions [ k ] . bottom = positions [ k ] . bottom - dValue ;
836
+ this . virtualScrollPositions [ index ] . bottom = this . virtualScrollPositions [ index ] . bottom - dValue ;
837
+ this . virtualScrollPositions [ index ] . height = height ;
838
+ for ( let k = index + 1 ; k < this . virtualScrollPositions . length ; k ++ ) {
839
+ this . virtualScrollPositions [ k ] . top = this . virtualScrollPositions [ k - 1 ] . bottom ;
840
+ this . virtualScrollPositions [ k ] . bottom = this . virtualScrollPositions [ k ] . bottom - dValue ;
840
841
}
841
842
842
843
//更新列表总高度
843
- let totalHeight = positions [ positions . length - 1 ] . bottom ;
844
+ let totalHeight = this . virtualScrollPositions [ this . virtualScrollPositions . length - 1 ] . bottom ;
844
845
this . $refs [ this . virtualPhantomRef ] . style . height =
845
846
totalHeight + "px" ;
846
847
@@ -855,16 +856,14 @@ export default {
855
856
virtualScrollAboveCount : aboveCount
856
857
} = this ;
857
858
858
- const positions = virtualScrollPositions ;
859
-
860
859
let startOffset ;
861
860
if ( start >= 1 ) {
862
861
let size =
863
- positions [ start ] . top -
864
- ( positions [ start - aboveCount ]
865
- ? positions [ start - aboveCount ] . top
862
+ this . virtualScrollPositions [ start ] . top -
863
+ ( this . virtualScrollPositions [ start - aboveCount ]
864
+ ? this . virtualScrollPositions [ start - aboveCount ] . top
866
865
: 0 ) ;
867
- startOffset = positions [ start - 1 ] . bottom - size ;
866
+ startOffset = this . virtualScrollPositions [ start - 1 ] . bottom - size ;
868
867
} else {
869
868
startOffset = 0 ;
870
869
}
@@ -875,7 +874,7 @@ export default {
875
874
// get virtual scroll start index
876
875
getVirtualScrollStartIndex ( scrollTop = 0 ) {
877
876
return this . virtualScrollBinarySearch (
878
- virtualScrollPositions ,
877
+ this . virtualScrollPositions ,
879
878
scrollTop
880
879
) ;
881
880
} ,
@@ -934,12 +933,10 @@ export default {
934
933
935
934
const { scrolling } = virtualScrollOption ;
936
935
if ( isFunction ( scrolling ) ) {
937
- let startRowIndex =
938
- visibleStartIndex - visibleAboveCount ;
936
+ let startRowIndex = visibleStartIndex - visibleAboveCount ;
939
937
940
938
scrolling ( {
941
- startRowIndex :
942
- startRowIndex > 0 ? startRowIndex : 0 ,
939
+ startRowIndex : startRowIndex > 0 ? startRowIndex : 0 ,
943
940
visibleStartIndex,
944
941
visibleEndIndex,
945
942
visibleAboveCount,
0 commit comments