From 00c4a216d554dbe9881c73545d64a83a8744478e Mon Sep 17 00:00:00 2001 From: sansiro Date: Tue, 7 Mar 2023 12:45:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20CRUD2=20=E5=8A=A0=E8=BD=BD=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E6=97=B6=E6=8E=A5=E5=8F=A3page=E4=BC=A0=E5=8F=82?= =?UTF-8?q?=E5=A7=8B=E7=BB=88=E4=B8=BA1=20(#6298)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/store/crud.ts | 7 ++++++- packages/amis/src/renderers/CRUD2.tsx | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/amis-core/src/store/crud.ts b/packages/amis-core/src/store/crud.ts index 0d02c74a3..0d7b8f49b 100644 --- a/packages/amis-core/src/store/crud.ts +++ b/packages/amis-core/src/store/crud.ts @@ -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, diff --git a/packages/amis/src/renderers/CRUD2.tsx b/packages/amis/src/renderers/CRUD2.tsx index eae5a6db5..9d7016f0b 100644 --- a/packages/amis/src/renderers/CRUD2.tsx +++ b/packages/amis/src/renderers/CRUD2.tsx @@ -413,6 +413,9 @@ export default class CRUD2 extends React.Component { * 加载更多动作处理器 */ 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 { loadDataOnce, loadDataOnceFetchOnFilter, source, - columns + columns, + perPage } = this.props; // reload 需要清空用户选择 @@ -518,7 +522,14 @@ export default class CRUD2 extends React.Component { this.lastQuery = store.query; const loadDataMode = loadMore ?? loadType === 'more'; - const data = createObject(store.data, store.query); + const data: Record = createObject(store.data, store.query); + + // handleLoadMore 是在事件触发后才执行,首次加载并不走到 handleLoadMore + // 所以加载更多模式下,首次加载也需要使用设置的 perPage,避免前后 perPage 不一致导致的问题 + if (loadDataMode && perPage) { + store.changePerPage(perPage); + } + isEffectiveApi(api, data) ? store .fetchInitData(api, data, {