Pagination: add test

This commit is contained in:
qingwei.li
2016-10-21 16:14:14 +08:00
parent 7bc214ce2f
commit ef75d0d3e4
6 changed files with 326 additions and 42 deletions

View File

@@ -45,7 +45,8 @@ export default {
render(h) {
let template = <div class='el-pagination'></div>;
const layout = this.$options.layout || this.layout || '';
const layout = this.layout || '';
if (!layout) return;
const TEMPLATE_MAP = {
prev: <prev></prev>,
jumper: <jumper></jumper>,
@@ -116,7 +117,9 @@ export default {
Sizes: {
created() {
if (Array.isArray(this.$parent.pageSizes)) {
this.$parent.internalPageSize = this.$parent.pageSizes.indexOf(this.$parent.pageSize) > -1 ? this.$parent.pageSize : this.$parent.pageSizes[0];
this.$parent.internalPageSize = this.$parent.pageSizes.indexOf(this.$parent.pageSize) > -1
? this.$parent.pageSize
: this.$parent.pageSizes[0];
}
},
@@ -232,25 +235,26 @@ export default {
}
},
first() {
const oldPage = this.internalCurrentPage;
const newVal = 1;
this.internalCurrentPage = this.getValidCurrentPage(newVal);
// XXX: 暂时没有到第一页和最后一页的交互
// first() {
// const oldPage = this.internalCurrentPage;
// const newVal = 1;
// this.internalCurrentPage = this.getValidCurrentPage(newVal);
if (this.internalCurrentPage !== oldPage) {
this.$emit('currentchange', this.internalCurrentPage);
}
},
// if (this.internalCurrentPage !== oldPage) {
// this.$emit('currentchange', this.internalCurrentPage);
// }
// },
last() {
const oldPage = this.internalCurrentPage;
const newVal = this.pageCount;
this.internalCurrentPage = this.getValidCurrentPage(newVal);
// last() {
// const oldPage = this.internalCurrentPage;
// const newVal = this.pageCount;
// this.internalCurrentPage = this.getValidCurrentPage(newVal);
if (this.internalCurrentPage !== oldPage) {
this.$emit('currentchange', this.internalCurrentPage);
}
},
// if (this.internalCurrentPage !== oldPage) {
// this.$emit('currentchange', this.internalCurrentPage);
// }
// },
getValidCurrentPage(value) {
value = parseInt(value, 10);
@@ -273,21 +277,23 @@ export default {
computed: {
pageCount() {
return Math.ceil(this.total / this.internalPageSize);
},
startRecordIndex() {
const result = (this.internalCurrentPage - 1) * this.internalPageSize + 1;
return result > 0 ? result : 0;
},
endRecordIndex() {
const result = this.internalCurrentPage * this.internalPageSize;
return result > this.total ? this.total : result;
}
// XXX: 暂时没用到
// startRecordIndex() {
// const result = (this.internalCurrentPage - 1) * this.internalPageSize + 1;
// return result > 0 ? result : 0;
// },
// endRecordIndex() {
// const result = this.internalCurrentPage * this.internalPageSize;
// return result > this.total ? this.total : result;
// }
},
watch: {
pageCount(newVal) {
/* istanbul ignore if */
if (newVal > 0 && this.internalCurrentPage === 0) {
this.internalCurrentPage = 1;
} else if (this.internalCurrentPage > newVal) {
@@ -312,6 +318,7 @@ export default {
internalCurrentPage(newVal, oldVal) {
newVal = parseInt(newVal, 10);
/* istanbul ignore if */
if (isNaN(newVal)) {
newVal = oldVal || 1;
} else {