Skip to content

Commit 5dc42e5

Browse files
author
黄书伟
committed
fixed bug
1 parent 091bb80 commit 5dc42e5

File tree

7 files changed

+76
-60
lines changed

7 files changed

+76
-60
lines changed

libs/src/utils/utils.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ exports.default = {
113113
var widthWithScroll = inner.offsetWidth;
114114
outer.parentNode.removeChild(outer);
115115

116-
console.log(widthNoScroll - widthWithScroll);
117-
118116
return widthNoScroll - widthWithScroll;
119117
},
120118
getParentCompByName: function getParentCompByName(context, name) {

libs/v-table/src/classes-mixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports.default = {
1616
vTableRightBody: function vTableRightBody() {
1717

1818
var result = {
19-
'v-table-rightview-special-border': this.hasFrozenColumn
19+
'v-table-rightview-special-border': true
2020
};
2121

2222
result[_settings2.default.scrollbarClass] = true;
@@ -27,7 +27,7 @@ exports.default = {
2727

2828
var result = {
2929

30-
'v-table-rightview-special-border': this.hasFrozenColumn
30+
'v-table-rightview-special-border': true
3131
};
3232

3333
result[_settings2.default.scrollbarClass] = true;

libs/v-table/src/frozen-columns-mixin.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
'use strict';
1+
"use strict";
22

33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6-
7-
var _utils = require('../../src/utils/utils.js');
8-
9-
var _utils2 = _interopRequireDefault(_utils);
10-
11-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12-
136
exports.default = {
147
computed: {
158
frozenCols: function frozenCols() {
@@ -73,26 +66,5 @@ exports.default = {
7366
}
7467
return noFrozenTitleCols;
7568
}
76-
},
77-
78-
methods: {
79-
setInternalHeightByFrozen: function setInternalHeightByFrozen(totalColumnsHeight) {
80-
var _this = this;
81-
82-
if (this.$el && this.hasFrozenColumn) {
83-
84-
this.$nextTick(function (x) {
85-
86-
if (_this.hasBodyHorizontalScrollBar()) {
87-
88-
totalColumnsHeight += _utils2.default.getScrollbarWidth();
89-
}
90-
_this.internalHeight = totalColumnsHeight;
91-
});
92-
} else {
93-
94-
this.internalHeight = totalColumnsHeight;
95-
}
96-
}
9769
}
9870
};

libs/v-table/src/scroll-bar-control-mixin.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ exports.default = {
1616
},
1717
hasBodyHorizontalScrollBar: function hasBodyHorizontalScrollBar() {
1818

19-
return this.rightViewWidth < this.totalNoFrozenColumnsWidth;
19+
if (this.$el) {
20+
21+
var rightViewBody = this.$el.querySelector('.v-table-rightview .v-table-body'),
22+
rightColumnsWidth = Math.round(this.totalNoFrozenColumnsWidth);
23+
24+
return rightViewBody.clientWidth + 2 < rightColumnsWidth;
25+
}
26+
27+
return false;
2028
}
2129
}
2230

libs/v-table/src/table-resize-mixin.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@ exports.default = {
3838
this.initTotalColumnsWidth = this.totalColumnsWidth;
3939
this.getResizeColumns();
4040
},
41+
adjustHeight: function adjustHeight() {
42+
var _this = this;
43+
44+
setTimeout(function (x) {
45+
46+
if (!_this.$el || _this.isVerticalResize) {
47+
return false;
48+
}
49+
50+
var totalColumnsHeight = _this.getTotalColumnsHeight(),
51+
scrollbarWidth = _utils2.default.getScrollbarWidth(),
52+
hasScrollBar = _this.hasBodyHorizontalScrollBar();
53+
54+
if (!(_this.height && _this.height > 0) || _this.height > totalColumnsHeight) {
55+
56+
if (hasScrollBar && _this.internalHeight + 2 < totalColumnsHeight + scrollbarWidth) {
57+
58+
_this.internalHeight += scrollbarWidth;
59+
} else if (!hasScrollBar) {
60+
61+
_this.internalHeight = totalColumnsHeight;
62+
}
63+
}
64+
});
65+
},
4166
tableResize: function tableResize() {
4267

4368
if (!this.isHorizontalResize && !this.isVerticalResize) {
@@ -51,8 +76,8 @@ exports.default = {
5176
minHeight = self.minHeight,
5277
view = this.$el,
5378
viewOffset = _utils2.default.getViewportOffset(view),
54-
currentWidth = view.getBoundingClientRect !== 'undefined' ? view.getBoundingClientRect().width : view.clientWidth + 2,
55-
currentHeight = view.getBoundingClientRect !== 'undefined' ? view.getBoundingClientRect().height : view.clientHeight + 2,
79+
currentWidth = view.getBoundingClientRect !== 'undefined' ? view.getBoundingClientRect().width : view.clientWidth,
80+
currentHeight = view.getBoundingClientRect !== 'undefined' ? view.getBoundingClientRect().height : view.clientHeight,
5681
right = window.document.documentElement.clientWidth - currentWidth - viewOffset.left,
5782
bottom = window.document.documentElement.clientHeight - currentHeight - viewOffset.top - 2;
5883

@@ -82,7 +107,7 @@ exports.default = {
82107
},
83108
changeColumnsWidth: function changeColumnsWidth(currentWidth) {
84109

85-
var differ = currentWidth - 2 - this.totalColumnsWidth,
110+
var differ = currentWidth - this.totalColumnsWidth,
86111
initResizeWidths = this.initTotalColumnsWidth,
87112
rightViewBody = this.$el.querySelector('.v-table-rightview .v-table-body'),
88113
rightViewFooter = this.$el.querySelector('.v-table-rightview .v-table-footer');
@@ -99,7 +124,7 @@ exports.default = {
99124
} else {
100125
if (this.getTotalColumnsHeight() > this.internalHeight) {
101126

102-
differ -= _utils2.default.getScrollbarWidth() + 1;
127+
differ -= _utils2.default.getScrollbarWidth();
103128
}
104129

105130
if (this.hasTableFooter) {
@@ -111,6 +136,8 @@ exports.default = {
111136
}
112137
}
113138

139+
this.adjustHeight();
140+
114141
if (currentWidth >= initResizeWidths || differ > 0) {
115142

116143
var average = differ / this.resizeColumns.length;

libs/v-table/src/table.vue

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
<span v-if="cellMergeContentType(rowIndex,col.field,item).isComponent">
9595
<component :rowData="item" :field="col.field ? col.field : ''"
9696
:index="rowIndex"
97-
:is="cellMerge(rowIndex,item,col.field).componentName" @on-custom-comp="customCompFunc"></component>
97+
:is="cellMerge(rowIndex,item,col.field).componentName"
98+
@on-custom-comp="customCompFunc"></component>
9899
</span>
99100
<span v-else v-html="cellMerge(rowIndex,item,col.field).content"></span>
100101
</div>
@@ -107,7 +108,8 @@
107108
>
108109
<span v-if="typeof col.componentName ==='string' && col.componentName.length > 0">
109110
<component :rowData="item" :field="col.field ? col.field : ''"
110-
:index="rowIndex" :is="col.componentName" @on-custom-comp="customCompFunc"></component>
111+
:index="rowIndex" :is="col.componentName"
112+
@on-custom-comp="customCompFunc"></component>
111113
</span>
112114
<span v-else-if="typeof col.formatter==='function'"
113115
v-html="col.formatter(item,rowIndex,pagingIndex,col.field)"></span>
@@ -133,7 +135,8 @@
133135
:style="{'width': leftViewWidth+'px'}">
134136
<table class="v-table-ftable" cellspacing="0" cellpadding="0" border="0">
135137
<tr class="v-table-row" v-for="(item,rowIndex) in frozenFooterCols">
136-
<td v-for="(col,colIndex) in item" :class="setFooterCellClassName(true,rowIndex,colIndex,col.content)">
138+
<td v-for="(col,colIndex) in item"
139+
:class="setFooterCellClassName(true,rowIndex,colIndex,col.content)">
137140
<div :style="{'height':footerRowHeight+'px','line-height':footerRowHeight+'px','width':col.width+'px','text-align':col.align}"
138141
:class="['v-table-body-cell',vTableBodyCell]"
139142
v-html="col.content"></div>
@@ -238,7 +241,8 @@
238241
>
239242
<span v-if="cellMergeContentType(rowIndex,col.field,item).isComponent">
240243
<component :rowData="item" :field="col.field ? col.field : ''" :index="rowIndex"
241-
:is="cellMerge(rowIndex,item,col.field).componentName" @on-custom-comp="customCompFunc"></component>
244+
:is="cellMerge(rowIndex,item,col.field).componentName"
245+
@on-custom-comp="customCompFunc"></component>
242246
</span>
243247
<span v-else v-html="cellMerge(rowIndex,item,col.field).content">
244248
</span>
@@ -278,7 +282,8 @@
278282
:style="{'width': rightViewWidth+'px'}">
279283
<table class="v-table-ftable" cellspacing="0" cellpadding="0" border="0">
280284
<tr class="v-table-row" v-for="(item,rowIndex) in noFrozenFooterCols">
281-
<td v-for="(col,colIndex) in item" :class="setFooterCellClassName(false,rowIndex,colIndex,col.content)">
285+
<td v-for="(col,colIndex) in item"
286+
:class="setFooterCellClassName(false,rowIndex,colIndex,col.content)">
282287
<div :style="{'height':footerRowHeight+'px','line-height':footerRowHeight+'px','width':col.width+'px','text-align':col.align}"
283288
:class="['v-table-body-cell',vTableBodyCell]"
284289
v-html="col.content"></div>
@@ -333,7 +338,7 @@
333338
334339
export default {
335340
name: 'v-table',
336-
mixins: [classesMixin,tableResizeMixin, frozenColumnsMixin, scrollControlMixin, sortControlMixin, tableEmptyMixin, dragWidthMixin, cellEditMixin, bodyCellMergeMixin, titleCellMergeMixin, checkboxSelectionMixin, tableFooterMixin, scrollBarControlMixin],
341+
mixins: [classesMixin, tableResizeMixin, frozenColumnsMixin, scrollControlMixin, sortControlMixin, tableEmptyMixin, dragWidthMixin, cellEditMixin, bodyCellMergeMixin, titleCellMergeMixin, checkboxSelectionMixin, tableFooterMixin, scrollBarControlMixin],
337342
components: {tableEmpty, loading, VCheckboxGroup, VCheckbox},
338343
data(){
339344
return {
@@ -489,7 +494,7 @@
489494
require: false,
490495
default: 40
491496
},
492-
columnWidthDrag:{
497+
columnWidthDrag: {
493498
type: Boolean,
494499
default: false
495500
},
@@ -525,14 +530,17 @@
525530
// 左侧区域宽度
526531
leftViewWidth(){
527532
var result = 0
528-
if (this.frozenCols && this.frozenCols.length > 0) {
533+
if (this.hasFrozenColumn) {
529534
result = this.frozenCols.reduce((total, curr) => total + curr.width, 0);
530535
}
531536
return result
532537
},
533538
// 右侧区域宽度
534539
rightViewWidth(){
535-
return this.internalWidth - this.leftViewWidth - 2;
540+
541+
let result = this.internalWidth - this.leftViewWidth;
542+
543+
return this.hasFrozenColumn ? result - 2 : result;
536544
},
537545
538546
// 左侧、右侧区域高度
@@ -546,7 +554,7 @@
546554
547555
if (this.getFooterContainerHeight) {
548556
549-
result -= this.getFooterContainerHeight + 1;
557+
result -= this.getFooterContainerHeight;
550558
}
551559
552560
return result;
@@ -610,7 +618,7 @@
610618
// custom columns component event
611619
customCompFunc(params){
612620
613-
this.$emit('on-custom-comp',params);
621+
this.$emit('on-custom-comp', params);
614622
},
615623
616624
setRowHoverColor(isMouseenter){
@@ -755,7 +763,7 @@
755763
if (self.isHorizontalResize) {
756764
console.error(self.errorMsg + "If you are using the isHorizontalResize property,Please set the value for each column's width");
757765
} else {
758-
item.width = self.internalWidth - self.totalColumnsWidth - 2;
766+
item.width = self.internalWidth - self.totalColumnsWidth;
759767
}
760768
761769
}
@@ -772,26 +780,25 @@
772780
// 当没设置宽度和高度时动态计算
773781
initView(){
774782
775-
var self = this;
776783
// 当没有设置宽度计算总宽度
777-
if (!(self.internalWidth && self.internalWidth > 0)) {
784+
if (!(this.internalWidth && this.internalWidth > 0)) {
778785
779-
if (self.columns && self.columns.length > 0) {
780-
self.internalWidth = self.columns.reduce((total, curr) => total + curr.width, 0) + 2;
786+
if (this.columns && this.columns.length > 0) {
787+
this.internalWidth = this.columns.reduce((total, curr) => total + curr.width, 0);
781788
782789
}
783790
}
784791
785-
var totalColumnsHeight = self.getTotalColumnsHeight();
792+
var totalColumnsHeight = this.getTotalColumnsHeight();
786793
787794
// 当没有设置高度时计算总高度 || 设置的高度大于所有列高度之和时
788-
if (!(self.height && self.height > 0) || self.height > totalColumnsHeight) {
795+
if (!(this.height && this.height > 0) || this.height > totalColumnsHeight) {
789796
790-
this.setInternalHeightByFrozen(totalColumnsHeight);
797+
this.internalHeight = totalColumnsHeight;
791798
792-
} else if (self.height <= totalColumnsHeight) {
799+
} else if (this.height <= totalColumnsHeight) {
793800
794-
self.internalHeight = self.height;
801+
this.internalHeight = this.height;
795802
}
796803
},
797804
@@ -838,6 +845,8 @@
838845
},
839846
mounted(){
840847
848+
this.adjustHeight();
849+
841850
this.tableEmpty();
842851
843852
if (Array.isArray(this.tableData) && this.tableData.length > 0) {
@@ -890,6 +899,8 @@
890899
}
891900
892901
this.resize();
902+
903+
this.adjustHeight();
893904
},
894905
deep: true
895906
}

umd/js/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)