diff --git a/src/js/pager/index.js b/src/js/pager/index.js index d55a3da..5384b6d 100644 --- a/src/js/pager/index.js +++ b/src/js/pager/index.js @@ -42,10 +42,13 @@ function update(currPage, vm) { totalPage, props: { maxPageShow } } = vm - vm.currPage = vm.inputPage = currPage - if (typeof vm.props.pageChanged === 'function') { - vm.props.pageChanged(currPage) + if (vm.currPage !== currPage) { + vm.currPage = vm.inputPage = currPage + if (typeof vm.props.pageChanged === 'function') { + vm.props.pageChanged(currPage) + } } + vm.pageList.clear() if (totalPage > 1) { vm.pageList.pushArray(calculate({ currPage, totalPage, maxPageShow })) @@ -59,22 +62,22 @@ const tmpls = { :css="{'border-radius': props.radius}" :attr="{disabled: currPage === 1}" :data="{to: parseUrl(1)}" - :click="setPage(1, $event)">`, + :click="go(1, $event)">`, end: ``, + :click="go(totalPage, $event)">`, prev: ``, + :click="go(currPage - 1, $event)">`, next: ``, + :click="go(currPage + 1, $event)">`, pager: ``, + :click="go(el, $event)">`, curr: ``, total: `共 {{totalPage}} 页 {{totalItem}} 条`, jumper: `
前往 - 页 +
`, slot: '' } @@ -186,7 +189,7 @@ export default Anot.component('pager', { skip: ['classList'], methods: { // 格式化页码的URL - parseUrl: function(val) { + parseUrl(val) { val = val >>> 0 if (val < 1 || !this.props.url || this.currPage === val) { return '' @@ -194,7 +197,7 @@ export default Anot.component('pager', { return this.props.url.replace('{id}', val) }, // 设置页码 - setPage: function(val, ev) { + go(val, ev) { let { inputPage, totalPage, currPage } = this let elem = (ev && ev.target) || null if ((elem && elem.disabled) || currPage === val) { @@ -231,11 +234,19 @@ export default Anot.component('pager', { } } }, - setPageSize: function(num) { + setSize(num) { + num = +num + if (this.pageSize === num) { + return + } this.pageSize = +num update(1, this) }, - setTotalItems: function(num) { + setTotal(num) { + num = +num + if (this.totalItem === num) { + return + } this.totalItem = +num update(1, this) }