diff --git a/src/components/pagination/__snapshots__/index.test.js.snap b/src/components/pagination/__snapshots__/index.test.js.snap index 1d5251a0a..badedd254 100644 --- a/src/components/pagination/__snapshots__/index.test.js.snap +++ b/src/components/pagination/__snapshots__/index.test.js.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AtPagination Snap render AtPagination -- props current 1`] = `"
undefined
undefined
上一页
undefined
undefined
下一页
1/0
"`; +exports[`AtPagination Snap render AtPagination -- props current 1`] = `"
undefined
undefined
上一页
undefined
undefined
下一页
1/1
"`; -exports[`AtPagination Snap render AtPagination -- props icon 1`] = `"
undefined
undefined
undefined
undefined
1/0
"`; +exports[`AtPagination Snap render AtPagination -- props icon 1`] = `"
undefined
undefined
undefined
undefined
1/1
"`; -exports[`AtPagination Snap render AtPagination -- props pageSize 1`] = `"
undefined
undefined
上一页
undefined
undefined
下一页
1/0
"`; +exports[`AtPagination Snap render AtPagination -- props pageSize 1`] = `"
undefined
undefined
上一页
undefined
undefined
下一页
1/1
"`; exports[`AtPagination Snap render AtPagination -- props total 1`] = `"
undefined
undefined
上一页
undefined
undefined
下一页
1/5
"`; diff --git a/src/components/pagination/index.js b/src/components/pagination/index.js index 89f702651..aa048bbcd 100644 --- a/src/components/pagination/index.js +++ b/src/components/pagination/index.js @@ -7,13 +7,19 @@ import AtIcon from '../icon/index' import AtComponent from '../../common/component' import './index.scss' +const MIN_MAXPAGE = 1 +const getMaxPage = (maxPage = 0) => { + if (maxPage <= 0) return MIN_MAXPAGE + return maxPage +} + export default class AtPagination extends AtComponent { constructor () { super(...arguments) const { current, pageSize, total } = this.props this.state = { current, - maxPage: Math.ceil(total / pageSize), + maxPage: getMaxPage(Math.ceil(total / pageSize)), } } @@ -40,7 +46,7 @@ export default class AtPagination extends AtComponent { componentWillReceiveProps (props) { const { total, pageSize, current } = props - const maxPage = Math.ceil(total / pageSize) + const maxPage = getMaxPage(Math.ceil(total / pageSize)) if (maxPage !== this.state.maxPage) { this.setState({ maxPage }) } @@ -58,8 +64,8 @@ export default class AtPagination extends AtComponent { const rootClassName = ['at-pagination'] if (icon) rootClassName.push('at-pagination--icon') - const prevDisabled = maxPage === 0 || current === 1 - const nextDisabled = maxPage === 0 || current === maxPage + const prevDisabled = maxPage === MIN_MAXPAGE || current === 1 + const nextDisabled = maxPage === MIN_MAXPAGE || current === maxPage return (