Pagination: trigger current-change event on user input (#10247)

pull/10254/head
杨奕 2018-03-20 11:59:33 +08:00 committed by GitHub
parent 674f8648bf
commit 725af9d1a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -50,7 +50,9 @@ export default {
data() { data() {
return { return {
internalCurrentPage: 1, internalCurrentPage: 1,
internalPageSize: 0 internalPageSize: 0,
lastEmittedPage: -1,
userChangePageSize: false
}; };
}, },
@ -194,6 +196,7 @@ export default {
handleChange(val) { handleChange(val) {
if (val !== this.$parent.internalPageSize) { if (val !== this.$parent.internalPageSize) {
this.$parent.internalPageSize = val = parseInt(val, 10); this.$parent.internalPageSize = val = parseInt(val, 10);
this.$parent.userChangePageSize = true;
this.$parent.$emit('size-change', val); this.$parent.$emit('size-change', val);
} }
} }
@ -234,6 +237,7 @@ export default {
}, },
handleChange(value) { handleChange(value) {
this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(value); this.$parent.internalCurrentPage = this.$parent.getValidCurrentPage(value);
this.$parent.emitChange();
this.oldValue = null; this.oldValue = null;
this.resetValueIfNeed(value); this.resetValueIfNeed(value);
}, },
@ -295,18 +299,21 @@ export default {
methods: { methods: {
handleCurrentChange(val) { handleCurrentChange(val) {
this.internalCurrentPage = this.getValidCurrentPage(val); this.internalCurrentPage = this.getValidCurrentPage(val);
this.emitChange();
}, },
prev() { prev() {
if (this.disabled) return; if (this.disabled) return;
const newVal = this.internalCurrentPage - 1; const newVal = this.internalCurrentPage - 1;
this.internalCurrentPage = this.getValidCurrentPage(newVal); this.internalCurrentPage = this.getValidCurrentPage(newVal);
this.emitChange();
}, },
next() { next() {
if (this.disabled) return; if (this.disabled) return;
const newVal = this.internalCurrentPage + 1; const newVal = this.internalCurrentPage + 1;
this.internalCurrentPage = this.getValidCurrentPage(newVal); this.internalCurrentPage = this.getValidCurrentPage(newVal);
this.emitChange();
}, },
getValidCurrentPage(value) { getValidCurrentPage(value) {
@ -332,6 +339,15 @@ export default {
} }
return resetValue === undefined ? value : resetValue; return resetValue === undefined ? value : resetValue;
},
emitChange() {
this.$nextTick(() => {
if (this.internalCurrentPage !== this.lastEmittedPage) {
this.$emit('current-change', this.internalCurrentPage);
this.lastEmittedPage = this.internalCurrentPage;
}
});
} }
}, },
@ -376,12 +392,10 @@ export default {
this.internalCurrentPage = newVal; this.internalCurrentPage = newVal;
if (oldVal !== newVal) { if (oldVal !== newVal) {
this.$emit('update:currentPage', newVal); this.$emit('update:currentPage', newVal);
this.$emit('current-change', this.internalCurrentPage);
} }
}); });
} else { } else {
this.$emit('update:currentPage', newVal); this.$emit('update:currentPage', newVal);
this.$emit('current-change', this.internalCurrentPage);
} }
}, },
@ -392,7 +406,9 @@ export default {
this.internalCurrentPage = 1; this.internalCurrentPage = 1;
} else if (oldPage > newVal) { } else if (oldPage > newVal) {
this.internalCurrentPage = newVal === 0 ? 1 : newVal; this.internalCurrentPage = newVal === 0 ? 1 : newVal;
this.userChangePageSize && this.emitChange();
} }
this.userChangePageSize = false;
} }
} }
}; };