|
@@ -17,10 +17,9 @@ export default {
|
|
|
|
|
|
small: Boolean,
|
|
|
|
|
|
- total: {
|
|
|
- type: Number,
|
|
|
- default: 0
|
|
|
- },
|
|
|
+ total: Number,
|
|
|
+
|
|
|
+ pageCount: Number,
|
|
|
|
|
|
currentPage: {
|
|
|
type: Number,
|
|
@@ -53,7 +52,7 @@ export default {
|
|
|
const TEMPLATE_MAP = {
|
|
|
prev: <prev></prev>,
|
|
|
jumper: <jumper></jumper>,
|
|
|
- pager: <pager currentPage={ this.internalCurrentPage } pageCount={ this.pageCount } on-change={ this.handleCurrentChange }></pager>,
|
|
|
+ pager: <pager currentPage={ this.internalCurrentPage } pageCount={ this.internalPageCount } on-change={ this.handleCurrentChange }></pager>,
|
|
|
next: <next></next>,
|
|
|
sizes: <sizes></sizes>,
|
|
|
slot: <slot></slot>,
|
|
@@ -107,7 +106,7 @@ export default {
|
|
|
class={
|
|
|
[
|
|
|
'btn-next',
|
|
|
- { disabled: this.$parent.internalCurrentPage === this.$parent.pageCount }
|
|
|
+ { disabled: this.$parent.internalCurrentPage === this.$parent.internalPageCount || this.$parent.internalPageCount === 0 }
|
|
|
]
|
|
|
}
|
|
|
on-click={ this.$parent.next }>
|
|
@@ -189,7 +188,7 @@ export default {
|
|
|
class="el-pagination__editor"
|
|
|
type="number"
|
|
|
min={ 1 }
|
|
|
- max={ this.pageCount }
|
|
|
+ max={ this.internalPageCount }
|
|
|
domProps-value={ this.$parent.internalCurrentPage }
|
|
|
on-change={ this.handleChange }
|
|
|
on-focus={ this.handleFocus }
|
|
@@ -204,7 +203,9 @@ export default {
|
|
|
Total: {
|
|
|
render(h) {
|
|
|
return (
|
|
|
- <span class="el-pagination__total">{ $t('el.pagination.total', { total: this.$parent.total }) }</span>
|
|
|
+ typeof this.$parent.total === 'number'
|
|
|
+ ? <span class="el-pagination__total">{ $t('el.pagination.total', { total: this.$parent.total }) }</span>
|
|
|
+ : ''
|
|
|
);
|
|
|
}
|
|
|
},
|
|
@@ -248,39 +249,26 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- // XXX: 暂时没有到第一页和最后一页的交互
|
|
|
- // first() {
|
|
|
- // const oldPage = this.internalCurrentPage;
|
|
|
- // const newVal = 1;
|
|
|
- // this.internalCurrentPage = this.getValidCurrentPage(newVal);
|
|
|
-
|
|
|
- // if (this.internalCurrentPage !== oldPage) {
|
|
|
- // this.$emit('current-change', this.internalCurrentPage);
|
|
|
- // }
|
|
|
- // },
|
|
|
-
|
|
|
- // last() {
|
|
|
- // const oldPage = this.internalCurrentPage;
|
|
|
- // const newVal = this.pageCount;
|
|
|
- // this.internalCurrentPage = this.getValidCurrentPage(newVal);
|
|
|
-
|
|
|
- // if (this.internalCurrentPage !== oldPage) {
|
|
|
- // this.$emit('current-change', this.internalCurrentPage);
|
|
|
- // }
|
|
|
- // },
|
|
|
-
|
|
|
getValidCurrentPage(value) {
|
|
|
value = parseInt(value, 10);
|
|
|
|
|
|
- var resetValue;
|
|
|
- if (value < 1) {
|
|
|
- resetValue = this.pageCount > 0 ? 1 : 0;
|
|
|
- } else if (value > this.pageCount) {
|
|
|
- resetValue = this.pageCount;
|
|
|
+ const havePageCount = typeof this.internalPageCount === 'number';
|
|
|
+
|
|
|
+ let resetValue;
|
|
|
+ if (!havePageCount) {
|
|
|
+ if (isNaN(value) || value < 1) resetValue = 1;
|
|
|
+ } else {
|
|
|
+ if (value < 1) {
|
|
|
+ resetValue = 1;
|
|
|
+ } else if (value > this.internalPageCount) {
|
|
|
+ resetValue = this.internalPageCount;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (resetValue === undefined && isNaN(value)) {
|
|
|
- value = this.pageCount > 0 ? 1 : 0;
|
|
|
+ resetValue = 1;
|
|
|
+ } else if (resetValue === 0) {
|
|
|
+ resetValue = 1;
|
|
|
}
|
|
|
|
|
|
return resetValue === undefined ? value : resetValue;
|
|
@@ -288,24 +276,18 @@ export default {
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
- pageCount() {
|
|
|
- return Math.ceil(this.total / this.internalPageSize);
|
|
|
+ internalPageCount() {
|
|
|
+ if (typeof this.total === 'number') {
|
|
|
+ return Math.ceil(this.total / this.internalPageSize);
|
|
|
+ } else if (typeof this.pageCount === 'number') {
|
|
|
+ return this.pageCount;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
-
|
|
|
- // 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) {
|
|
|
+ internalPageCount(newVal) {
|
|
|
/* istanbul ignore if */
|
|
|
if (newVal > 0 && this.internalCurrentPage === 0) {
|
|
|
this.internalCurrentPage = 1;
|