fix: Pagination 切换页码后每页显示重置问题 (#4298)

This commit is contained in:
RUNZE LU 2022-05-11 13:13:05 +08:00 committed by GitHub
parent e2deb3c891
commit 8829f6346f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -4,6 +4,7 @@
* @Date: 2021-11-01 16:57:38
*/
import React from 'react';
import isInteger from 'lodash/isInteger';
import {localeable, LocaleProps} from '../locale';
import {themeable, ThemeProps} from '../theme';
import {autobind} from '../utils/helper';
@ -122,12 +123,20 @@ export class Pagination extends React.Component<
this.handlePageNums = this.handlePageNums.bind(this);
}
componentDidUpdate(prevProps: PaginationProps) {
if (prevProps.perPage !== this.props.perPage) {
const perPage = Number(this.props.perPage);
this.setState({perPage: isInteger(perPage) ? perPage : 10});
}
}
handlePageNumChange(page: number, perPage?: number) {
const props = this.props;
if (props.disabled) {
const {disabled, onPageChange} = this.props;
if (disabled) {
return;
}
props.onPageChange && props.onPageChange(page, perPage);
onPageChange?.(page, perPage);
}
/**

View File

@ -665,7 +665,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
: this.search(undefined, undefined, true, true);
action.close && this.closeTarget(action.close);
})
.catch((e) => {
.catch(e => {
if (throwErrors || action.countDown) {
throw e;
}
@ -1693,6 +1693,7 @@ export default class CRUD extends React.Component<CRUDProps, any> {
lastPage: lastPage,
hasNext: store.hasNext,
mode: store.mode,
perPage: store.perPage,
onPageChange: this.handleChangePage
}
)}