Skip to content

Commit 7f22cfc

Browse files
committed
去除虚拟滚动等高功能
1 parent 687dd69 commit 7f22cfc

File tree

3 files changed

+29
-90
lines changed

3 files changed

+29
-90
lines changed

packages/ve-table/src/body/body-tr.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ export default {
8686
type: Boolean,
8787
default: false,
8888
},
89-
// is virtual scroll fixed row height
90-
isVirtualScrollFixedRowHeight: {
91-
type: Boolean,
92-
default: false,
93-
},
9489
// cell style option
9590
cellStyleOption: {
9691
type: Object,
@@ -274,7 +269,7 @@ export default {
274269
},
275270
};
276271

277-
if (this.isVirtualScroll && !this.isVirtualScrollFixedRowHeight) {
272+
if (this.isVirtualScroll) {
278273
const props = {
279274
class: this.trClass,
280275
props: {

packages/ve-table/src/body/index.jsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ export default {
6565
type: Boolean,
6666
default: false,
6767
},
68-
// is virtual scroll fixed row height
69-
isVirtualScrollFixedRowHeight: {
70-
type: Boolean,
71-
default: false,
72-
},
7368
// virtual scroll visible data
7469
virtualScrollVisibleData: {
7570
type: Array,
@@ -783,7 +778,6 @@ export default {
783778
internalCheckboxSelectedRowKeys,
784779
internalRadioSelectedRowKey,
785780
isVirtualScroll,
786-
isVirtualScrollFixedRowHeight,
787781
cellStyleOption,
788782
} = this;
789783

@@ -829,7 +823,6 @@ export default {
829823
internalCheckboxSelectedRowKeys,
830824
internalRadioSelectedRowKey,
831825
isVirtualScroll,
832-
isVirtualScrollFixedRowHeight,
833826
isExpandRow: isExpandRow({
834827
rowData,
835828
rowIndex,

packages/ve-table/src/index.jsx

Lines changed: 28 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -275,32 +275,18 @@ export default {
275275
defaultVirtualScrollMinRowHeight,
276276
maxHeight,
277277
tableOffestHeight,
278-
isVirtualScrollFixedRowHeight,
279278
} = this;
280279

281280
if (isVirtualScroll && maxHeight) {
282-
const { fixedRowHeight } = virtualScrollOption;
283-
284-
// fixed row height
285-
if (isVirtualScrollFixedRowHeight) {
286-
if (isNumber(maxHeight)) {
287-
result = Math.ceil(maxHeight / fixedRowHeight);
288-
} else if (tableOffestHeight) {
289-
result = Math.ceil(tableOffestHeight / fixedRowHeight);
290-
}
291-
} else {
292-
const minRowHeight = isNumber(
293-
virtualScrollOption.minRowHeight,
294-
)
295-
? virtualScrollOption.minRowHeight
296-
: defaultVirtualScrollMinRowHeight;
297-
298-
if (isNumber(maxHeight)) {
299-
result = Math.ceil(maxHeight / minRowHeight);
300-
} else if (tableOffestHeight) {
301-
// 修复当动态高度 当 max-height="calc(100vh - 210px)" 或者 max-height="80%" 时无法计算的问题
302-
result = Math.ceil(tableOffestHeight / minRowHeight);
303-
}
281+
const minRowHeight = isNumber(virtualScrollOption.minRowHeight)
282+
? virtualScrollOption.minRowHeight
283+
: defaultVirtualScrollMinRowHeight;
284+
285+
if (isNumber(maxHeight)) {
286+
result = Math.ceil(maxHeight / minRowHeight);
287+
} else if (tableOffestHeight) {
288+
// 修复当动态高度 当 max-height="calc(100vh - 210px)" 或者 max-height="80%" 时无法计算的问题
289+
result = Math.ceil(tableOffestHeight / minRowHeight);
304290
}
305291
}
306292
return result;
@@ -385,11 +371,6 @@ export default {
385371
const { virtualScrollOption } = this;
386372
return virtualScrollOption && virtualScrollOption.enable;
387373
},
388-
// is virtual scroll fixed row height
389-
isVirtualScrollFixedRowHeight() {
390-
const { virtualScrollOption } = this;
391-
return virtualScrollOption && virtualScrollOption.isFixedRowHeight;
392-
},
393374
// has fixed column
394375
hasFixedColumn() {
395376
return this.colgroups.some(
@@ -847,7 +828,7 @@ export default {
847828

848829
// init virtual scroll positions
849830
initVirtualScrollPositions() {
850-
if (this.isVirtualScroll && !this.isVirtualScrollFixedRowHeight) {
831+
if (this.isVirtualScroll) {
851832
const {
852833
virtualScrollOption,
853834
rowKeyFieldName,
@@ -872,11 +853,6 @@ export default {
872853

873854
// list item height change
874855
bodyTrHeightChange({ rowKey, height }) {
875-
// 固定高度时不处理
876-
if (this.isVirtualScrollFixedRowHeight) {
877-
return false;
878-
}
879-
880856
//获取真实元素大小,修改对应的尺寸缓存
881857
const index = this.virtualScrollPositions.findIndex(
882858
(x) => x.rowKey === rowKey,
@@ -911,45 +887,30 @@ export default {
911887
setVirtualPhantomHeight() {
912888
let totalHeight = 0;
913889

914-
if (this.isVirtualScrollFixedRowHeight) {
915-
totalHeight =
916-
this.cloneTableData.length *
917-
this.virtualScrollOption.fixedRowHeight;
918-
} else {
919-
totalHeight =
920-
this.virtualScrollPositions[
921-
this.virtualScrollPositions.length - 1
922-
].bottom;
923-
}
890+
totalHeight =
891+
this.virtualScrollPositions[
892+
this.virtualScrollPositions.length - 1
893+
].bottom;
924894

925895
this.$refs[this.virtualPhantomRef].style.height =
926896
totalHeight + "px";
927897
},
928898
// set virtual scroll start offset
929-
setVirtualScrollStartOffset(scrollTop = 0) {
899+
setVirtualScrollStartOffset() {
930900
const start = this.$options.customOption.virtualScrollStartIndex;
931901

932902
const aboveCount = this.getVirtualScrollAboveCount();
933903

934-
const { fixedRowHeight } = this.virtualScrollOption;
935-
936904
let startOffset = 0;
937-
if (this.isVirtualScrollFixedRowHeight) {
905+
906+
if (start >= 1) {
907+
let size =
908+
this.virtualScrollPositions[start].top -
909+
(this.virtualScrollPositions[start - aboveCount]
910+
? this.virtualScrollPositions[start - aboveCount].top
911+
: 0);
938912
startOffset =
939-
scrollTop -
940-
aboveCount * fixedRowHeight -
941-
(scrollTop % fixedRowHeight);
942-
} else {
943-
if (start >= 1) {
944-
let size =
945-
this.virtualScrollPositions[start].top -
946-
(this.virtualScrollPositions[start - aboveCount]
947-
? this.virtualScrollPositions[start - aboveCount]
948-
.top
949-
: 0);
950-
startOffset =
951-
this.virtualScrollPositions[start - 1].bottom - size;
952-
}
913+
this.virtualScrollPositions[start - 1].bottom - size;
953914
}
954915

955916
//this.$refs[this.tableContentRef].style.transform = `translate3d(0,${startOffset}px,0)`;
@@ -959,18 +920,10 @@ export default {
959920
},
960921
// get virtual scroll start index
961922
getVirtualScrollStartIndex(scrollTop = 0) {
962-
let result;
963-
if (this.isVirtualScrollFixedRowHeight) {
964-
result = Math.floor(
965-
scrollTop / this.virtualScrollOption.fixedRowHeight,
966-
);
967-
} else {
968-
result = this.virtualScrollBinarySearch(
969-
this.virtualScrollPositions,
970-
scrollTop,
971-
);
972-
}
973-
return result;
923+
return this.virtualScrollBinarySearch(
924+
this.virtualScrollPositions,
925+
scrollTop,
926+
);
974927
},
975928
// virtual scroll binary search
976929
virtualScrollBinarySearch(list, value) {
@@ -1021,7 +974,7 @@ export default {
1021974
visibleEndIndex;
1022975

1023976
//此时的偏移量
1024-
this.setVirtualScrollStartOffset(scrollTop);
977+
this.setVirtualScrollStartOffset();
1025978

1026979
const { scrolling } = virtualScrollOption;
1027980
if (isFunction(scrolling)) {
@@ -1159,7 +1112,6 @@ export default {
11591112
rowKeyFieldName,
11601113
virtualScrollOption,
11611114
isVirtualScroll,
1162-
isVirtualScrollFixedRowHeight,
11631115
virtualScrollVisibleData,
11641116
sortOption,
11651117
cellStyleOption,
@@ -1194,7 +1146,6 @@ export default {
11941146
radioOption,
11951147
virtualScrollOption,
11961148
isVirtualScroll,
1197-
isVirtualScrollFixedRowHeight,
11981149
virtualScrollVisibleData,
11991150
cellStyleOption,
12001151
cellSpanOption: this.cellSpanOption,

0 commit comments

Comments
 (0)