diff --git a/src/js/pager/index.js b/src/js/pager/index.js index a399182..f7e0ddf 100644 --- a/src/js/pager/index.js +++ b/src/js/pager/index.js @@ -4,7 +4,7 @@ import './main.scss' Anot.ui.pager = '1.0.0' //计算页码列表 -function calculate({ currPage, maxPageShow, totalPages }) { +function calculate({ currPage, maxPageShow, totalPage }) { let arr = [] let fixNum = 0 let halfPage = @@ -12,87 +12,135 @@ function calculate({ currPage, maxPageShow, totalPages }) { ? maxPageShow - currPage : Math.floor(maxPageShow / 2) - if (totalPages < 2) { + if (totalPage < 2) { return arr } if (currPage - halfPage > 1) { arr.push('...') } - if (totalPages - currPage < halfPage) { - fixNum = halfPage - totalPages + currPage + if (totalPage - currPage < halfPage) { + fixNum = halfPage - totalPage + currPage } for ( let i = currPage - halfPage - fixNum; - i < currPage + halfPage + 1 && i <= totalPages; + i < currPage + halfPage + 1 && i <= totalPage; i++ ) { if (i > 0) { arr.push(i) } } - if (currPage + halfPage < totalPages) { + if (currPage + halfPage < totalPage) { arr.push('...') } return arr } // 更新组件 function update(currPage, vm) { - const { totalPages, props: { maxPageShow } } = vm + const { totalPage, props: { maxPageShow } } = vm vm.currPage = vm.inputPage = currPage - vm.props.onPageChange(currPage) - vm.pageList.clear() - if (totalPages > 1) { - vm.pageList.pushArray(calculate({ currPage, totalPages, maxPageShow })) + if (typeof vm.props.onPageChange === 'function') { + vm.props.onPageChange(currPage) } + vm.pageList.clear() + if (totalPage > 1) { + vm.pageList.pushArray(calculate({ currPage, totalPage, maxPageShow })) + } +} + +const tmpls = { + home: ``, + end: ``, + prev: ``, + next: ``, + pager: ``, + curr: ``, + total: `共 {{totalPage}} 页 {{totalItems}} 条`, + jumper: `