Skip to content

Commit f0c330d

Browse files
author
黄书伟
committed
update
1 parent 110e1ed commit f0c330d

File tree

8 files changed

+125
-85
lines changed

8 files changed

+125
-85
lines changed

libs/src/utils/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ exports.default = {
2727
left: left,
2828
top: top,
2929
right: window.document.documentElement.clientWidth - box.width - left,
30-
bottom: window.document.documentElement.clientHeight - box.height - top
30+
bottom: window.document.documentElement.clientHeight - box.height - top,
31+
right2: window.document.documentElement.clientWidth - left,
32+
bottom2: window.document.documentElement.clientHeight - top
3133
};
3234
},
3335
bind: function bind(elem, event, handler) {

libs/themes-base/index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,8 @@
911911
top: 0;
912912
bottom: 0;
913913
right: 0;
914-
width: 100%;
915-
height: 100%;
914+
/* width: 100%;
915+
height: 100%;*/
916916
}
917917

918918
.v-checkbox-inner{

libs/themes-base/v-checkbox.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
top: 0;
4242
bottom: 0;
4343
right: 0;
44-
width: 100%;
45-
height: 100%;
44+
/* width: 100%;
45+
height: 100%;*/
4646
}
4747

4848
.v-checkbox-inner{

libs/v-table/src/sort-control-mixin.js

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,100 @@ Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
66
exports.default = {
7+
data: function data() {
8+
9+
return {
10+
sortColumns: {}
11+
};
12+
},
13+
14+
715
methods: {
816
enableSort: function enableSort(val) {
917
return typeof val === 'string' ? true : false;
1018
},
11-
sortColumns: function sortColumns() {
19+
setSortColumns: function setSortColumns() {
1220
var self = this,
1321
sortColumns = {},
14-
collection = self.titleRowsToSortInfo.length > 0 ? self.titleRowsToSortInfo : self.internalColumns;
22+
titleRowsToSortInfo = [];
23+
24+
if (self.internalTitleRows.length > 0) {
25+
self.internalTitleRows.filter(function (row) {
26+
row.filter(function (column, index) {
27+
if (typeof column.orderBy === 'string' && column.fields.length === 1) {
28+
column.field = column.fields[0];
29+
titleRowsToSortInfo.push(column);
30+
}
31+
});
32+
});
33+
}
34+
35+
var collection = titleRowsToSortInfo.length > 0 ? titleRowsToSortInfo : self.internalColumns;
1536

1637
collection.filter(function (item, index) {
1738
if (self.enableSort(item.orderBy)) {
1839
sortColumns[item.field] = item.orderBy;
1940
}
2041
});
2142

22-
return sortColumns;
43+
this.sortColumns = sortColumns;
44+
45+
this.singleSortInit();
2346
},
24-
sortControl: function sortControl(field, orderBy) {
47+
getCurrentSort: function getCurrentSort(field) {
2548

26-
var self = this,
27-
collection = self.titleRowsToSortInfo.length > 0 ? self.titleRowsToSortInfo : self.internalColumns;
49+
return this.sortColumns[field];
50+
},
51+
sortControl: function sortControl(field) {
2852

29-
if (self.enableSort(orderBy)) {
30-
collection.filter(function (column, index) {
53+
var orderBy = this.sortColumns[field];
3154

32-
if (self.enableSort(column.orderBy) && column.field === field) {
55+
if (this.enableSort(orderBy)) {
3356

34-
if (self.sortAlways) {
57+
if (this.sortAlways) {
3558

36-
column.orderBy = column.orderBy === 'asc' ? 'desc' : 'asc';
37-
} else {
59+
this.sortColumns[field] = orderBy === 'asc' ? 'desc' : 'asc';
60+
} else {
3861

39-
column.orderBy = column.orderBy === 'asc' ? 'desc' : column.orderBy === 'desc' ? '' : 'asc';
40-
}
41-
}
62+
this.sortColumns[field] = orderBy === 'asc' ? 'desc' : this.sortColumns[field] === 'desc' ? '' : 'asc';
63+
}
64+
65+
if (!this.multipleSort) {
4266

43-
if (!self.multipleSort) {
44-
if (column.field !== field && self.enableSort(column.orderBy)) {
45-
column.orderBy = '';
67+
for (var col in this.sortColumns) {
68+
69+
if (col !== field) {
70+
71+
this.sortColumns[col] = '';
4672
}
4773
}
48-
});
74+
}
4975

50-
self.$emit('sort-change', self.sortColumns());
76+
this.$emit('sort-change', this.sortColumns);
5177
}
5278
},
53-
singelSortInit: function singelSortInit() {
79+
singleSortInit: function singleSortInit() {
80+
5481
var self = this,
55-
result = false,
56-
collection;
57-
if (!self.multipleSort) {
58-
collection = self.titleRowsToSortInfo.length > 0 ? self.titleRowsToSortInfo : self.internalColumns;
59-
collection.filter(function (item, index) {
60-
if (self.enableSort(item.orderBy) && item.orderBy !== '') {
61-
if (result) {
62-
item.orderBy = '';
63-
}
64-
result = true;
82+
result = false;
83+
84+
if (!self.multipleSort && self.sortColumns) {
85+
86+
for (var col in self.sortColumns) {
87+
88+
if (result) {
89+
90+
self.sortColumns[col] = '';
6591
}
66-
});
92+
result = true;
93+
}
6794
}
95+
},
96+
resetOrder: function resetOrder() {
97+
98+
this.setSortColumns();
99+
100+
this.$emit('sort-change', this.sortColumns);
68101
}
69102
}
70103
};

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,17 @@ exports.default = {
112112
viewOffset = _utils2.default.getViewportOffset(view),
113113
currentWidth = view.getBoundingClientRect !== 'undefined' ? view.getBoundingClientRect().width : view.clientWidth,
114114
currentHeight = view.getBoundingClientRect !== 'undefined' ? view.getBoundingClientRect().height : view.clientHeight,
115-
bottom = window.document.documentElement.clientHeight - currentHeight - viewOffset.top - 2;
115+
bottom = window.document.documentElement.clientHeight - currentHeight - viewOffset.top - 2,
116+
bottom2 = viewOffset.bottom2,
117+
scrollbarWidth = this.scrollbarWidth;
118+
119+
if (this.isHorizontalResize && this.internalWidth && this.internalWidth > 0 && currentWidth > 0) {
120+
121+
currentWidth = currentWidth > maxWidth ? maxWidth : currentWidth;
122+
currentWidth = currentWidth < minWidth ? minWidth : currentWidth;
123+
124+
this.internalWidth = currentWidth;
125+
}
116126

117127
if (this.isVerticalResize && currentHeight > 0) {
118128

@@ -121,17 +131,26 @@ exports.default = {
121131
currentHeight = currentHeight + bottom;
122132
currentHeight = currentHeight > maxHeight ? maxHeight : currentHeight;
123133
currentHeight = currentHeight < minHeight ? minHeight : currentHeight;
124-
this.internalHeight = currentHeight;
125-
}
126134

127-
if (this.isHorizontalResize && this.internalWidth && this.internalWidth > 0 && currentWidth > 0) {
135+
if (currentWidth <= this.initTotalColumnsWidth && !this.isTableEmpty) {
128136

129-
currentWidth = currentWidth > maxWidth ? maxWidth : currentWidth;
130-
currentWidth = currentWidth < minWidth ? minWidth : currentWidth;
137+
bottom2 -= this.verticalResizeOffset;
131138

132-
this.internalWidth = currentWidth;
133-
this.changeColumnsWidth(currentWidth);
139+
var differ = bottom2 - totalColumnsHeight;
140+
141+
if (bottom2 > totalColumnsHeight + scrollbarWidth) {
142+
143+
currentHeight += scrollbarWidth;
144+
} else if (differ > 0 && differ < scrollbarWidth) {
145+
146+
currentHeight += differ;
147+
}
148+
}
149+
150+
this.internalHeight = currentHeight;
134151
}
152+
153+
this.changeColumnsWidth(currentWidth);
135154
},
136155
changeColumnsWidth: function changeColumnsWidth(currentWidth) {
137156
var _this2 = this;

libs/v-table/src/table.vue

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
></v-checkbox>
3636
</span>
3737
<span v-else v-html="col.title"></span>
38-
<span @click.stop="sortControl(col.fields[0],col.orderBy)"
38+
<span @click.stop="sortControl(col.fields[0])"
3939
class="v-table-sort-icon" v-if="enableSort(col.orderBy)">
40-
<i :class='["v-icon-up-dir",col.orderBy ==="asc" ? "checked":""]'></i>
41-
<i :class='["v-icon-down-dir",col.orderBy ==="desc" ? "checked":""]'></i>
40+
<i :class='["v-icon-up-dir",getCurrentSort(col.field) ==="asc" ? "checked":""]'></i>
41+
<i :class='["v-icon-down-dir",getCurrentSort(col.field) ==="desc" ? "checked":""]'></i>
4242
</span>
4343
</span>
4444
</div>
@@ -68,10 +68,10 @@
6868
></v-checkbox>
6969
</span>
7070
<span v-else v-html="col.title"></span>
71-
<span @click.stop="sortControl(col.field,col.orderBy)"
71+
<span @click.stop="sortControl(col.field)"
7272
class="v-table-sort-icon" v-if="enableSort(col.orderBy)">
73-
<i :class='["v-icon-up-dir",col.orderBy ==="asc" ? "checked":""]'></i>
74-
<i :class='["v-icon-down-dir",col.orderBy ==="desc" ? "checked":""]'></i>
73+
<i :class='["v-icon-up-dir",getCurrentSort(col.field) ==="asc" ? "checked":""]'></i>
74+
<i :class='["v-icon-down-dir",getCurrentSort(col.field) ==="desc" ? "checked":""]'></i>
7575
</span>
7676
</span>
7777
</div>
@@ -103,7 +103,7 @@
103103
<div v-if="isCellMergeRender(rowIndex,col.field,item)"
104104
:class="['v-table-body-cell',showVerticalBorder ? 'vertical-border':'',showHorizontalBorder?'horizontal-border':'']"
105105
:style="{'width':getRowWidthByColSpan(rowIndex,col.field,item)+'px','height': getRowHeightByRowSpan(rowIndex,col.field,item)+'px','line-height':getRowHeightByRowSpan(rowIndex,col.field,item)+'px','text-align':col.columnAlign}"
106-
:title="col.overflowTitle ? overflowTitle(item,col) :''"
106+
:title="col.overflowTitle ? overflowTitle(item,rowIndex,col) :''"
107107
@click.stop="rowCellClick(rowIndex,item,col);cellEditClick($event,col.isEdit,item,col.field,rowIndex)"
108108
@dblclick.stop="rowCellDbClick(rowIndex,item,col)"
109109
>
@@ -119,7 +119,7 @@
119119
<div v-else
120120
:class="['v-table-body-cell',showVerticalBorder ? 'vertical-border':'',showHorizontalBorder?'horizontal-border':'']"
121121
:style="{'width':col.width+'px','height': rowHeight+'px','line-height':rowHeight+'px','text-align':col.columnAlign}"
122-
:title="col.overflowTitle ? overflowTitle(item,col) :''"
122+
:title="col.overflowTitle ? overflowTitle(item,rowIndex,col) :''"
123123
@click.stop="rowCellClick(rowIndex,item,col);cellEditClick($event,col.isEdit,item,col.field,rowIndex)"
124124
@dblclick.stop="rowCellDbClick(rowIndex,item,col)"
125125
>
@@ -188,10 +188,10 @@
188188
<span class="table-title">
189189
<span v-if="col.type === 'selection'"></span>
190190
<span v-else v-html="col.title"></span>
191-
<span @click.stop="sortControl(col.fields[0],col.orderBy)"
191+
<span @click.stop="sortControl(col.fields[0])"
192192
class="v-table-sort-icon" v-if="enableSort(col.orderBy)">
193-
<i :class='["v-icon-up-dir",col.orderBy ==="asc" ? "checked":""]'></i>
194-
<i :class='["v-icon-down-dir",col.orderBy ==="desc" ? "checked":""]'></i>
193+
<i :class='["v-icon-up-dir",getCurrentSort(col.field) ==="asc" ? "checked":""]'></i>
194+
<i :class='["v-icon-down-dir",getCurrentSort(col.field) ==="desc" ? "checked":""]'></i>
195195
</span>
196196
</span>
197197
</div>
@@ -221,11 +221,11 @@
221221
></v-checkbox>
222222
</span>
223223
<span v-else v-html="col.title"></span>
224-
<span @click.stop="sortControl(col.field,col.orderBy)"
224+
<span @click.stop="sortControl(col.field)"
225225
class="v-table-sort-icon"
226226
v-if="enableSort(col.orderBy)">
227-
<i :class='["v-icon-up-dir",col.orderBy ==="asc" ? "checked":""]'></i>
228-
<i :class='["v-icon-down-dir",col.orderBy ==="desc" ? "checked":""]'></i>
227+
<i :class='["v-icon-up-dir",getCurrentSort(col.field) ==="asc" ? "checked":""]'></i>
228+
<i :class='["v-icon-down-dir",getCurrentSort(col.field) ==="desc" ? "checked":""]'></i>
229229
</span>
230230
</span>
231231
</div>
@@ -257,7 +257,7 @@
257257
<div v-if="isCellMergeRender(rowIndex,col.field,item)"
258258
:class="['v-table-body-cell',showVerticalBorder ? 'vertical-border':'',showHorizontalBorder?'horizontal-border':'']"
259259
:style="{'width':getRowWidthByColSpan(rowIndex,col.field,item)+'px','height': getRowHeightByRowSpan(rowIndex,col.field,item)+'px','line-height':getRowHeightByRowSpan(rowIndex,col.field,item)+'px','text-align':col.columnAlign}"
260-
:title="col.overflowTitle ? overflowTitle(item,col) :''"
260+
:title="col.overflowTitle ? overflowTitle(item,rowIndex,col) :''"
261261
@click.stop="rowCellClick(rowIndex,item,col);cellEditClick($event,col.isEdit,item,col.field,rowIndex)"
262262
@dblclick.stop="rowCellDbClick(rowIndex,item,col)"
263263
>
@@ -273,7 +273,7 @@
273273
<div v-else
274274
:class="['v-table-body-cell',showVerticalBorder ? 'vertical-border':'',showHorizontalBorder?'horizontal-border':'']"
275275
:style="{'width':col.width+'px','height': rowHeight+'px','line-height':rowHeight+'px','text-align':col.columnAlign}"
276-
:title="col.overflowTitle ? overflowTitle(item,col) :''"
276+
:title="col.overflowTitle ? overflowTitle(item,rowIndex,col) :''"
277277
@click.stop="rowCellClick(rowIndex,item,col);cellEditClick($event,col.isEdit,item,col.field,rowIndex)"
278278
@dblclick.stop="rowCellDbClick(rowIndex,item,col)"
279279
>
@@ -592,29 +592,12 @@
592592
result = this.internalHeight - this.titleRowHeight;
593593
}
594594
595-
result -= this.footerTotalHeight;
595+
// 1px: 当有滚动条时,使滚动条显示全
596+
result -= (this.footerTotalHeight+1);
596597
597598
return result;
598599
},
599600
600-
// 将复杂表头配置数据简单化
601-
titleRowsToSortInfo(){
602-
var result = [], self = this;
603-
604-
if (self.internalTitleRows.length > 0) {
605-
self.internalTitleRows.filter(function (row) {
606-
row.filter(function (column, index) {
607-
if (typeof column.orderBy === 'string' && column.fields.length === 1) {
608-
column.field = column.fields[0];
609-
result.push(column);
610-
}
611-
})
612-
})
613-
}
614-
return result;
615-
},
616-
617-
618601
// 所有列的总宽度
619602
totalColumnsWidth(){
620603
return this.internalColumns.reduce(function (total, curr) {
@@ -696,10 +679,11 @@
696679
},
697680
698681
// 超出的title提示
699-
overflowTitle(row, col){
682+
overflowTitle(row, rowIndex,col){
683+
700684
var result = '';
701685
if (typeof col.formatter === 'function') {
702-
var val = col.formatter(row, -1);
686+
var val = col.formatter(row, rowIndex,this.pagingIndex,col.field);
703687
// 如果是html 不处理
704688
if (utils.isHtml(val)) {
705689
result = '';
@@ -747,6 +731,8 @@
747731
748732
this.initTableWidth();
749733
734+
this.setSortColumns();
735+
750736
751737
var self = this, widthCountCheck = 0;
752738
@@ -840,7 +826,7 @@
840826
this.scrollControl();
841827
}
842828
843-
this.singelSortInit();
829+
//this.singleSortInit();
844830
845831
this.controlScrollBar();
846832
},

0 commit comments

Comments
 (0)