fix: CRUD2 加载更多时接口page传参始终为1 (#6298)

This commit is contained in:
sansiro 2023-03-07 12:45:33 +08:00 committed by GitHub
parent 0cbd4857c3
commit 00c4a216d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -399,7 +399,11 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
function changePage(page: number, perPage?: number | string) {
self.page = page;
perPage && (self.perPage = parseInt(perPage as string, 10));
perPage && changePerPage(perPage);
}
function changePerPage(perPage: number | string) {
self.perPage = parseInt(perPage as string, 10);
}
function selectAction(action: ActionObject) {
@ -611,6 +615,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
updateQuery,
fetchInitData,
changePage,
changePerPage,
selectAction,
saveRemote,
setFilterTogglable,

View File

@ -413,6 +413,9 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
*
*/
handleLoadMore() {
const {store, perPage} = this.props;
store.changePage(store.page + 1, perPage);
this.getData(undefined, undefined, undefined, true);
}
@ -500,7 +503,8 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
loadDataOnce,
loadDataOnceFetchOnFilter,
source,
columns
columns,
perPage
} = this.props;
// reload 需要清空用户选择
@ -518,7 +522,14 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
this.lastQuery = store.query;
const loadDataMode = loadMore ?? loadType === 'more';
const data = createObject(store.data, store.query);
const data: Record<string, any> = createObject(store.data, store.query);
// handleLoadMore 是在事件触发后才执行,首次加载并不走到 handleLoadMore
// 所以加载更多模式下,首次加载也需要使用设置的 perPage避免前后 perPage 不一致导致的问题
if (loadDataMode && perPage) {
store.changePerPage(perPage);
}
isEffectiveApi(api, data)
? store
.fetchInitData(api, data, {