diff --git a/packages/core/actions/src/actions/list.ts b/packages/core/actions/src/actions/list.ts index 570b4950fa..5e42b26765 100644 --- a/packages/core/actions/src/actions/list.ts +++ b/packages/core/actions/src/actions/list.ts @@ -38,7 +38,7 @@ function findArgs(ctx: Context) { } async function listWithPagination(ctx: Context) { - const { page = DEFAULT_PAGE, pageSize = DEFAULT_PER_PAGE } = ctx.action.params; + const { page = DEFAULT_PAGE, pageSize = DEFAULT_PER_PAGE, simplePaginate } = ctx.action.params; const repository = getRepositoryFromParams(ctx); @@ -54,15 +54,24 @@ async function listWithPagination(ctx: Context) { } }); - const [rows, count] = await repository.findAndCount(options); + if (simplePaginate) { + const rows = await repository.find(options); + ctx.body = { + rows, + page: Number(page), + pageSize: Number(pageSize), + }; + } else { + const [rows, count] = await repository.findAndCount(options); - ctx.body = { - count, - rows, - page: Number(page), - pageSize: Number(pageSize), - totalPage: totalPage(count, pageSize), - }; + ctx.body = { + count, + rows, + page: Number(page), + pageSize: Number(pageSize), + totalPage: totalPage(count, pageSize), + }; + } } async function listWithNonPaged(ctx: Context) { diff --git a/packages/core/client/src/block-provider/TableBlockProvider.tsx b/packages/core/client/src/block-provider/TableBlockProvider.tsx index cf52966199..241e420e00 100644 --- a/packages/core/client/src/block-provider/TableBlockProvider.tsx +++ b/packages/core/client/src/block-provider/TableBlockProvider.tsx @@ -147,7 +147,7 @@ export const TableBlockProvider = withDynamicSchemaProps((props) => { const fieldSchema = useFieldSchema(); const { getCollection, getCollectionField } = useCollectionManager_deprecated(props.dataSource); const collection = getCollection(props.collection, props.dataSource); - const { treeTable } = fieldSchema?.['x-decorator-props'] || {}; + const { treeTable, pagingMode } = fieldSchema?.['x-decorator-props'] || {}; const { params, parseVariableLoading } = useTableBlockParamsCompat(props); let childrenColumnName = 'children'; @@ -166,6 +166,11 @@ export const TableBlockProvider = withDynamicSchemaProps((props) => { params['tree'] = true; } } + if (pagingMode === 'simplePaginate') { + params['simplePaginate'] = true; + } else { + delete params?.['simplePaginate']; + } const form = useMemo(() => createForm(), [treeTable]); // 在解析变量的时候不渲染,避免因为重复请求数据导致的资源浪费 diff --git a/packages/core/client/src/locale/zh-CN.json b/packages/core/client/src/locale/zh-CN.json index fae581d41e..d7b483e8fd 100644 --- a/packages/core/client/src/locale/zh-CN.json +++ b/packages/core/client/src/locale/zh-CN.json @@ -964,5 +964,7 @@ "Expand All": "展开全部", "Search": "搜索", "Clear default value": "清除默认值", - "Open in new window": "新窗口打开" + "Open in new window": "新窗口打开", + "Paging mode": "分页模式", + "Simple Paginate": "简单分页" } diff --git a/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx b/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx index f5c7e3b8e7..d49d7198ab 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx @@ -24,6 +24,7 @@ import { setDataLoadingModeSettingsItem } from '../details-multi/setDataLoadingM import { setDefaultSortingRulesSchemaSettingsItem } from '../../../../schema-settings/setDefaultSortingRulesSchemaSettingsItem'; import { setTheDataScopeSchemaSettingsItem } from '../../../../schema-settings/setTheDataScopeSchemaSettingsItem'; import { createSwitchSettingsItem } from '../../../../application/schema-settings/utils'; +import { SchemaSettingsPagingMode } from '../../../../schema-settings/SchemaSettingsPagingMode'; export const tableBlockSettings = new SchemaSettings({ name: 'blockSettings:table', @@ -185,6 +186,10 @@ export const tableBlockSettings = new SchemaSettings({ }; }, }, + { + name: 'pagingMode', + Component: SchemaSettingsPagingMode, + }, { name: 'ConnectDataBlocks', Component: SchemaSettingsConnectDataBlocks, diff --git a/packages/core/client/src/schema-component/antd/table-v2/Table.tsx b/packages/core/client/src/schema-component/antd/table-v2/Table.tsx index 82eb8a9bf5..5d6236eec7 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/Table.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/Table.tsx @@ -258,21 +258,61 @@ const TableIndex = (props) => { const usePaginationProps = (pagination1, pagination2) => { const { t } = useTranslation(); + const field: any = useField(); + const { token } = useToken(); const pagination = useMemo( () => ({ ...pagination1, ...pagination2 }), [JSON.stringify({ ...pagination1, ...pagination2 })], ); - - const showTotal = useCallback((total) => t('Total {{count}} items', { count: total }), [t]); - - const result = useMemo( - () => ({ - showTotal, - showSizeChanger: true, - ...pagination, - }), - [pagination, t, showTotal], + const { total: totalCount, current, pageSize } = pagination || {}; + const showTotal = useCallback( + (total) => { + return t('Total {{count}} items', { count: total }); + }, + [t, totalCount], ); + const result = useMemo(() => { + if (totalCount) { + return { + showTotal, + showSizeChanger: true, + ...pagination, + }; + } else { + return { + showTotal: false, + simple: true, + showTitle: false, + showSizeChanger: true, + hideOnSinglePage: false, + ...pagination, + total: field.value?.length < pageSize ? pageSize * current : pageSize * current + 1, + className: css` + .ant-pagination-simple-pager { + display: none !important; + } + `, + itemRender: (_, type, originalElement) => { + if (type === 'prev') { + return ( +