From ea3b19b1c606a8668937c1cb1ad9622e8ba559fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Mon, 25 Dec 2017 01:28:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E9=A1=B5=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/lib/pages/index.js | 31 ++++++++++++++++++++++--------- src/js/lib/pages/main.scss | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/js/lib/pages/index.js b/src/js/lib/pages/index.js index 7ff5d9c..4bccbf1 100644 --- a/src/js/lib/pages/index.js +++ b/src/js/lib/pages/index.js @@ -12,6 +12,9 @@ function calculate({ currPage, maxPageShow, totalPages }) { ? maxPageShow - currPage : Math.floor(maxPageShow / 2) + if (totalPages < 2) { + return arr + } if (currPage - halfPage > 1) { arr.push('...') } @@ -35,12 +38,15 @@ function calculate({ currPage, maxPageShow, totalPages }) { // 更新组件 function update(currPage, vm) { const { totalPages, props } = vm + vm.currPage = vm.inputPage = currPage + vm.props.onPageChange.call(null, currPage) + if (totalPages < 2) { + return + } vm.pageList.clear() vm.pageList.pushArray( calculate({ currPage, totalPages, maxPageShow: props.maxPageShow }) ) - vm.currPage = vm.inputPage = currPage - vm.props.onPageChange.call(null, currPage) } export default Anot.component('pages', { @@ -55,9 +61,6 @@ export default Anot.component('pages', { return tpl }, componentWillMount: function() { - if (this.totalPages < 2) { - return - } const { currPage, totalPages, props } = this this.pageList.clear() this.pageList.pushArray( @@ -69,9 +72,8 @@ export default Anot.component('pages', { }, state: { currPage: 1, - totalItems: 1000, + totalItems: 1, pageSize: 20, - inputPage: 1, pageList: [] }, @@ -80,6 +82,7 @@ export default Anot.component('pages', { return Math.ceil(this.totalItems / this.pageSize) } }, + skip: ['currPage', 'totalItems', 'pageSize'], props: { url: null, btns: { @@ -124,9 +127,18 @@ export default Anot.component('pages', { } } else { if (val === null) { - this.inputPage = this.inputPage >>> 0 || 1 + let { inputPage, totalPages, currPage } = this + inputPage = inputPage >>> 0 + if (ev && ev.keyCode === 13) { - update(this.inputPage, this) + if (inputPage < 1 || currPage === inputPage) { + return (this.inputPage = currPage) + } + if (inputPage > totalPages) { + inputPage = totalPages + } + this.inputPage = inputPage + update(inputPage, this) } } else { val = val >>> 0 @@ -139,6 +151,7 @@ export default Anot.component('pages', { update(1, this) }, setTotalItems: function(num) { + console.log(this, num) this.totalItems = +num update(1, this) } diff --git a/src/js/lib/pages/main.scss b/src/js/lib/pages/main.scss index 2d13035..b60f3c8 100644 --- a/src/js/lib/pages/main.scss +++ b/src/js/lib/pages/main.scss @@ -28,7 +28,7 @@ .input-box, .input-box span, .input-box input {display:inline-block;} - .input-box input {width:30px;height:30px;padding:0 3px;background:#fff;border:1px solid #ddd;text-align:center;} + .input-box input {width:40px;height:30px;padding:0 3px;background:#fff;border:1px solid #ddd;text-align:center;} } &.skin-2 {float:right;width:auto;