From c28aad6bc22b67a4a65ca1b6927afb88a96b2867 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Mon, 13 May 2019 13:08:24 +0800 Subject: [PATCH] =?UTF-8?q?Pagination=20=E8=B0=83=E6=95=B4,=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=20pageNum=20changePageNum=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/CRUD.tsx | 4 +-- src/renderers/Pagination.tsx | 60 +++++++++++++++++------------------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/renderers/CRUD.tsx b/src/renderers/CRUD.tsx index 8b53bbf7c..7be3dc47c 100644 --- a/src/renderers/CRUD.tsx +++ b/src/renderers/CRUD.tsx @@ -1015,9 +1015,7 @@ export default class CRUD extends React.Component { items: lastPage, hasNext: store.hasNext, mode: store.mode, - onPageChange: this.handleChangePage, - pageNum: store.pageNum, - changePageNum: store.changePageNum, + onPageChange: this.handleChangePage } )} diff --git a/src/renderers/Pagination.tsx b/src/renderers/Pagination.tsx index 62ff9b621..49350bca6 100644 --- a/src/renderers/Pagination.tsx +++ b/src/renderers/Pagination.tsx @@ -1,31 +1,23 @@ import * as React from 'react'; import {Renderer, RendererProps} from '../factory'; +import { autobind } from '../utils/helper'; export interface PaginationProps extends RendererProps { - activePage?: number; - items?: number; - maxButtons?: number; - hasNext?: boolean; - mode?: string; - onPageChange: (page: number, perPage?: number) => void; - pageNum?: number; - changePageNum: (value: number) => void; - showPageInput: boolean; -} - -export interface DefaultProps { activePage: number; items: number; maxButtons: number; - mode: string; hasNext: boolean; + mode: string; + onPageChange: (page: number, perPage?: number) => void; showPageInput: boolean; } -type PropsWithDefault = PaginationProps & DefaultProps; +export interface PaginationState { + pageNum: string; +}; -export default class Pagination extends React.PureComponent { - static defaultProps: DefaultProps = { +export default class Pagination extends React.Component { + static defaultProps = { activePage: 1, items: 1, maxButtons: 5, @@ -34,13 +26,20 @@ export default class Pagination extends React.PureComponent @@ -68,22 +67,21 @@ export default class Pagination extends React.PureComponent) { - const {changePageNum, items} = this.props; + const {items} = this.props; let value = e.currentTarget.value; - if (((typeof value === 'number' || /^\d+$/.test(value)) && value > 0) || value === '') { - if (value !== '') { - value = parseInt(value, 10); - value = (value > (items as number) ? items : value) as number; - } - changePageNum(value); + if (/^\d+$/.test(value) && parseInt(value, 10) > items) { + value = String(items); } + + this.setState({pageNum: value}); } renderNormal() { - let {activePage, items, maxButtons, onPageChange, pageNum, classnames: cx, showPageInput} = this - .props as PropsWithDefault; + let {activePage, items, maxButtons, onPageChange, classnames: cx, showPageInput} = this.props; + const pageNum = this.state.pageNum; let pageButtons: any = []; let startPage: number; @@ -195,7 +193,7 @@ export default class Pagination extends React.PureComponent -
    onPageChange(value)}> +
      {pageButtons}
    @@ -214,7 +212,7 @@ export default class Pagination extends React.PureComponent