@@ -17,15 +17,6 @@ import clickoutside from "../../src/directives/clickoutside";
1717import { mutations } from "./util/store" ;
1818import VueDomResizeObserver from "../../src/comps/resize-observer" ;
1919
20- // virtual scroll positions
21- let virtualScrollPositions = [
22- /* {
23- rowKey: 0, // 当前行数据索引
24- top: 0, // 距离上一个项的高度
25- bottom: 100, // 距离下一个项的高度
26- height: 100 // 自身高度
27- } */
28- ] ;
2920export default {
3021 name : COMPS_NAME . VE_TABLE ,
3122 directives : {
@@ -197,6 +188,17 @@ export default {
197188 colgroups : [ ] ,
198189 // groupColumns
199190 groupColumns : [ ] ,
191+ /*
192+ // virtual scroll positions(非响应式)
193+ virtualScrollPositions = [
194+ {
195+ rowKey: 0, // 当前行数据索引
196+ top: 0, // 距离上一个项的高度
197+ bottom: 100, // 距离下一个项的高度
198+ height: 100 // 自身高度
199+ }
200+ ],
201+ */
200202 // virtual scroll start index
201203 virtualScrollStartIndex : 0 ,
202204 // virtual scroll end index
@@ -813,7 +815,7 @@ export default {
813815 ? virtualScrollOption . minRowHeight
814816 : defaultVirtualScrollMinRowHeight ;
815817
816- virtualScrollPositions = cloneTableData . map ( ( item , index ) => ( {
818+ this . virtualScrollPositions = cloneTableData . map ( ( item , index ) => ( {
817819 rowKey : item [ rowKeyFieldName ] ,
818820 height : minRowHeight ,
819821 top : index * minRowHeight ,
@@ -823,24 +825,23 @@ export default {
823825 } ,
824826 // list item height change
825827 bodyTrHeightChange ( { rowKey, height } ) {
826- const positions = virtualScrollPositions ;
827828
828829 //获取真实元素大小,修改对应的尺寸缓存
829- const index = positions . findIndex ( x => x . rowKey === rowKey ) ;
830+ const index = this . virtualScrollPositions . findIndex ( x => x . rowKey === rowKey ) ;
830831
831- let oldHeight = positions [ index ] . height ;
832+ let oldHeight = this . virtualScrollPositions [ index ] . height ;
832833 let dValue = oldHeight - height ;
833834 //存在差值
834835 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 ;
840841 }
841842
842843 //更新列表总高度
843- let totalHeight = positions [ positions . length - 1 ] . bottom ;
844+ let totalHeight = this . virtualScrollPositions [ this . virtualScrollPositions . length - 1 ] . bottom ;
844845 this . $refs [ this . virtualPhantomRef ] . style . height =
845846 totalHeight + "px" ;
846847
@@ -855,16 +856,14 @@ export default {
855856 virtualScrollAboveCount : aboveCount
856857 } = this ;
857858
858- const positions = virtualScrollPositions ;
859-
860859 let startOffset ;
861860 if ( start >= 1 ) {
862861 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
866865 : 0 ) ;
867- startOffset = positions [ start - 1 ] . bottom - size ;
866+ startOffset = this . virtualScrollPositions [ start - 1 ] . bottom - size ;
868867 } else {
869868 startOffset = 0 ;
870869 }
@@ -875,7 +874,7 @@ export default {
875874 // get virtual scroll start index
876875 getVirtualScrollStartIndex ( scrollTop = 0 ) {
877876 return this . virtualScrollBinarySearch (
878- virtualScrollPositions ,
877+ this . virtualScrollPositions ,
879878 scrollTop
880879 ) ;
881880 } ,
@@ -934,12 +933,10 @@ export default {
934933
935934 const { scrolling } = virtualScrollOption ;
936935 if ( isFunction ( scrolling ) ) {
937- let startRowIndex =
938- visibleStartIndex - visibleAboveCount ;
936+ let startRowIndex = visibleStartIndex - visibleAboveCount ;
939937
940938 scrolling ( {
941- startRowIndex :
942- startRowIndex > 0 ? startRowIndex : 0 ,
939+ startRowIndex : startRowIndex > 0 ? startRowIndex : 0 ,
943940 visibleStartIndex,
944941 visibleEndIndex,
945942 visibleAboveCount,
0 commit comments