From eaea15af3075aca93eea1ffeeb86ba88fe25cc0a Mon Sep 17 00:00:00 2001 From: zhangtao07 Date: Mon, 30 Sep 2024 15:00:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dcrud2=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=88=86=E9=A1=B5=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../amis-editor/src/plugin/CRUD2/BaseCRUD.tsx | 1 + packages/amis/src/renderers/CRUD2.tsx | 35 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx b/packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx index a981dbd00..537867ea6 100644 --- a/packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx +++ b/packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx @@ -802,6 +802,7 @@ export class BaseCRUDPlugin extends BasePlugin { this.addFeatToToolbar(schema, newCompSchema, 'footer', 'right'); } form.setValues({ + perPage: value !== 'more' ? undefined : schema.perPage, footerToolbar: schema.footerToolbar, headerToolbar: schema.headerToolbar }); diff --git a/packages/amis/src/renderers/CRUD2.tsx b/packages/amis/src/renderers/CRUD2.tsx index 79b670946..6cbb741d4 100644 --- a/packages/amis/src/renderers/CRUD2.tsx +++ b/packages/amis/src/renderers/CRUD2.tsx @@ -30,7 +30,8 @@ import { isApiOutdated, isPureVariable, resolveVariableAndFilter, - parsePrimitiveQueryString + parsePrimitiveQueryString, + JSONTraverse } from 'amis-core'; import pickBy from 'lodash/pickBy'; import {Html, SpinnerExtraProps} from 'amis-ui'; @@ -285,7 +286,6 @@ export default class CRUD2 extends React.Component { silentPolling: false, autoFillHeight: false, showSelection: true, - perPage: 10, primaryField: 'id', parsePrimitiveQuery: true }; @@ -350,12 +350,19 @@ export default class CRUD2 extends React.Component { } componentDidMount() { - const {store, pickerMode, loadType, loadDataOnce, perPage} = this.props; + const {store, pickerMode, loadType, loadDataOnce, maxLoadNum} = this.props; // 初始化分页 - let pagination = loadType && !!loadDataOnce; + let pagination = loadType && !loadDataOnce; if (pagination) { + // crud2的翻页每页条数是翻页组件里单独配置的 + let perPage = + loadType === 'more' + ? this.props.perPage || 10 + : this.getPaginationPerPage(); store.changePage(store.page, perPage); + } else if (!loadType) { + store.changePage(1, maxLoadNum || 500); // 不分页时默认一次最多查询500条(jsonql) } // 初始化筛选条件 @@ -446,6 +453,24 @@ export default class CRUD2 extends React.Component { clearTimeout(this.timer); } + @autobind + getPaginationPerPage() { + let perPage = 10; + let {headerToolbar, footerToolbar} = this.props; + JSONTraverse( + { + headerToolbar, + footerToolbar + }, + (value: any, key: string, host: any) => { + if (key === 'type' && value === 'pagination' && !isNaN(host?.perPage)) { + perPage = +host.perPage; + } + } + ); + return perPage; + } + getParseQueryOptions(props: CRUD2Props) { const {parsePrimitiveQuery} = props; type PrimitiveQueryObj = Exclude< @@ -503,7 +528,7 @@ export default class CRUD2 extends React.Component { * 加载更多动作处理器 */ handleLoadMore() { - const {store, perPage} = this.props; + const {store, perPage = 10} = this.props; store.changePage(store.page + 1, perPage); this.getData(undefined, undefined, undefined, true);