Skip to content

Commit 2054f37

Browse files
author
huangshuwei
committed
v2.4.1
1 parent d752036 commit 2054f37

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-easytable",
3-
"version": "2.4.0",
3+
"version": "2.4.1",
44
"main": "libs/main.js",
55
"description": "Vue table component",
66
"keywords": [

packages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import VeSelect from './ve-select';
1313
import VeTable from './ve-table';
1414

1515

16-
const version = '2.4.0';
16+
const version = '2.4.1';
1717
const components = [
1818
VeCheckbox,
1919
VeCheckboxGroup,

packages/ve-table/src/index.jsx

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ import clickoutside from "../../src/directives/clickoutside";
1717
import { mutations } from "./util/store";
1818
import 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-
];
2920
export 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

Comments
 (0)