fix(pagination): 统一表格分页与密钥查询交互
统一各中心表格的分页样式和切换行为,保留密钥筛选条件与兑换码搜索分页。
This commit is contained in:
@@ -499,11 +499,7 @@ export const ActionCenter = ({ lists, activeTab, onTabChange, cny, t }) => (
|
||||
rowKey='org_id'
|
||||
size='small'
|
||||
scroll={{ x: 1200 }}
|
||||
pagination={
|
||||
lists[tab].length > 10
|
||||
? { pageSize: 10, showSizeChanger: false }
|
||||
: false
|
||||
}
|
||||
pagination={lists[tab].length > 10 ? { pageSize: 10 } : false}
|
||||
empty={<Empty description={t('暂无需要跟进的企业')} />}
|
||||
/>
|
||||
</TabPane>
|
||||
|
||||
@@ -123,9 +123,7 @@ export const SalesRepTable = ({ reps, cny, onSelect, t }) => {
|
||||
rowKey={(r) => r.sales_rep || '__none__'}
|
||||
size='small'
|
||||
scroll={{ x: 920 }}
|
||||
pagination={
|
||||
reps.length > 8 ? { pageSize: 8, showSizeChanger: false } : false
|
||||
}
|
||||
pagination={reps.length > 8 ? { pageSize: 10 } : false}
|
||||
empty={<Empty description={t('暂无数据')} />}
|
||||
/>
|
||||
</SectionCard>
|
||||
|
||||
@@ -136,16 +136,12 @@ const DecisionTable = ({ mode, orgId }) => {
|
||||
pageSize,
|
||||
total: data.total || 0,
|
||||
size: 'small',
|
||||
showSizeChanger: mode === 'org',
|
||||
onPageSizeChange:
|
||||
mode === 'org'
|
||||
? (size) => {
|
||||
setPage(1);
|
||||
setPageSize(size);
|
||||
}
|
||||
: undefined,
|
||||
onPageSizeChange: (size) => {
|
||||
setPage(1);
|
||||
setPageSize(size);
|
||||
},
|
||||
showTotal: (total) => t('共 {{total}} 条', { total }),
|
||||
onChange: setPage,
|
||||
onPageChange: setPage,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState } from 'react';
|
||||
import Table from '../../../ui/CenterActionTable';
|
||||
import { Table } from '@/components/ui';
|
||||
import { Modal, Button, Input, Tag, Typography, Select } from 'antd';
|
||||
import { Search } from 'lucide-react';
|
||||
import { copy, showError, showInfo, showSuccess } from '../../../../helpers';
|
||||
@@ -269,10 +269,6 @@ const ModelTestModal = ({
|
||||
pagination={{
|
||||
current: modelTablePage,
|
||||
pageSize: paginationSize,
|
||||
total: filteredModels.length,
|
||||
showSizeChanger: false,
|
||||
showTotal: (total) => t('共 {{total}} 条', { total }),
|
||||
size: 'small',
|
||||
onChange: (page, size) => {
|
||||
setModelTablePage(size !== paginationSize ? 1 : page);
|
||||
setPaginationSize(size);
|
||||
|
||||
@@ -160,7 +160,6 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
|
||||
currentPage: currentPage,
|
||||
pageSize: paginationSize,
|
||||
total: filteredModels.length,
|
||||
showSizeChanger: false,
|
||||
onPageChange: (page) => setCurrentPage(page),
|
||||
onPageSizeChange: (size) => {
|
||||
setCurrentPage(1);
|
||||
|
||||
@@ -279,7 +279,6 @@ const UpstreamConflictModal = ({
|
||||
currentPage: currentPage,
|
||||
pageSize: paginationSize,
|
||||
total: filteredDataSource.length,
|
||||
showSizeChanger: false,
|
||||
onPageChange: (page) => setCurrentPage(page),
|
||||
onPageSizeChange: (size) => {
|
||||
setCurrentPage(1);
|
||||
|
||||
+105
-115
@@ -4,9 +4,8 @@ import { controlSize, placement } from './controls';
|
||||
import {
|
||||
centerPaginationEvents,
|
||||
centerPaginationOptions,
|
||||
isCenterPaginationScope,
|
||||
paginationEvents,
|
||||
paginationShowTotal,
|
||||
hasPageSizeHandler,
|
||||
lastPage,
|
||||
} from './pagination';
|
||||
import { overlayMask } from './overlayPolicy';
|
||||
import CenterTable from './CenterActionTable';
|
||||
@@ -273,12 +272,12 @@ export function Table({
|
||||
pagination,
|
||||
size,
|
||||
onChange,
|
||||
locale,
|
||||
...props
|
||||
}) {
|
||||
const consolePage = useConsolePage();
|
||||
const BaseTable = consolePage ? ConsoleTable : CenterTable;
|
||||
const unified = Boolean(pagination) && isCenterPaginationScope();
|
||||
const Component = unified ? CenterPaginatedTable : BaseTable;
|
||||
const Component = pagination ? PaginatedTable : BaseTable;
|
||||
const expandable = expandedRowRender
|
||||
? {
|
||||
expandedRowRender,
|
||||
@@ -291,9 +290,7 @@ export function Table({
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
{...(unified
|
||||
? { component: BaseTable, legacyPagination: pagination }
|
||||
: {})}
|
||||
{...(pagination ? { component: BaseTable } : {})}
|
||||
size={controlSize(size)}
|
||||
onChange={
|
||||
consolePage && onChange
|
||||
@@ -302,147 +299,140 @@ export function Table({
|
||||
}
|
||||
locale={
|
||||
empty !== undefined || emptyText !== undefined
|
||||
? { emptyText: empty ?? emptyText }
|
||||
: undefined
|
||||
? { ...locale, emptyText: empty ?? emptyText }
|
||||
: locale
|
||||
}
|
||||
expandable={expandable}
|
||||
pagination={
|
||||
pagination === false
|
||||
? false
|
||||
: pagination
|
||||
? {
|
||||
...pagination,
|
||||
current: pagination.currentPage ?? pagination.current,
|
||||
pageSizeOptions:
|
||||
pagination.pageSizeOpts ?? pagination.pageSizeOptions,
|
||||
showTotal: paginationShowTotal(pagination.showTotal),
|
||||
...paginationEvents(pagination),
|
||||
}
|
||||
: false
|
||||
}
|
||||
pagination={pagination || false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CenterPaginatedTable({
|
||||
component: Component,
|
||||
legacyPagination,
|
||||
...props
|
||||
}) {
|
||||
const isMobile = useIsMobile();
|
||||
const { resetOnDataChange, ...config } = legacyPagination;
|
||||
const local = config.total === undefined;
|
||||
const [localPage, setLocalPage] = React.useState(config.currentPage ?? 1);
|
||||
const [localSize, setLocalSize] = React.useState(config.pageSize ?? 10);
|
||||
const resetLocalPage = local && resetOnDataChange;
|
||||
const resetSource = resetLocalPage ? props.dataSource : undefined;
|
||||
React.useEffect(() => {
|
||||
if (resetLocalPage) setLocalPage(1);
|
||||
}, [resetLocalPage, resetSource]);
|
||||
const pageSize =
|
||||
local && !config.onPageSizeChange ? localSize : (config.pageSize ?? 10);
|
||||
const total = config.total ?? props.dataSource?.length ?? 0;
|
||||
const current = Math.min(
|
||||
config.currentPage ?? config.current ?? localPage,
|
||||
Math.max(1, Math.ceil(total / pageSize)),
|
||||
function PaginatedTable({ component: Component, pagination, ...props }) {
|
||||
if (pagination.total !== undefined) {
|
||||
return (
|
||||
<>
|
||||
<Component {...props} pagination={false} />
|
||||
<Pagination
|
||||
{...pagination}
|
||||
className={['table-pagination-footer', pagination.className]
|
||||
.filter(Boolean)
|
||||
.join(' ')}
|
||||
loading={Boolean(props.loading)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<LocalPaginatedTable {...props} component={Component} config={pagination} />
|
||||
);
|
||||
const events = centerPaginationEvents({
|
||||
...config,
|
||||
pageSize,
|
||||
...(local && !config.onPageSizeChange && !config.onShowSizeChange
|
||||
? {
|
||||
onPageSizeChange: (size) => {
|
||||
config.onPageChange?.(1);
|
||||
config.onChange?.(1, size);
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
|
||||
function LocalPaginatedTable({ component: Component, config, ...props }) {
|
||||
const isMobile = useIsMobile();
|
||||
const { resetOnDataChange } = config;
|
||||
const [localPage, setLocalPage] = React.useState(config.defaultCurrent ?? 1);
|
||||
const [localSize, setLocalSize] = React.useState(
|
||||
config.pageSize ?? config.defaultPageSize ?? 10,
|
||||
);
|
||||
const resetSource = resetOnDataChange ? props.dataSource : undefined;
|
||||
React.useEffect(() => {
|
||||
const requested = config.currentPage ?? config.current;
|
||||
if (!props.loading && requested !== undefined && requested > current) {
|
||||
config.onPageChange?.(current);
|
||||
config.onChange?.(current, pageSize);
|
||||
}
|
||||
}, [current, pageSize, props.loading, config]);
|
||||
if (resetOnDataChange) setLocalPage(1);
|
||||
}, [resetOnDataChange, resetSource]);
|
||||
const managesSize = !hasPageSizeHandler(config);
|
||||
const pageSize = managesSize ? localSize : (config.pageSize ?? localSize);
|
||||
const current = useValidPage({
|
||||
page: config.currentPage ?? config.current ?? localPage,
|
||||
total: props.dataSource?.length ?? 0,
|
||||
pageSize,
|
||||
loading: props.loading || resetOnDataChange,
|
||||
onPageChange:
|
||||
config.onPageChange ?? (config.onChange ? undefined : setLocalPage),
|
||||
onChange: config.onChange,
|
||||
});
|
||||
const events = centerPaginationEvents({ ...config, pageSize });
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
pagination={{
|
||||
...centerPaginationOptions(config, isMobile),
|
||||
showSizeChanger:
|
||||
config.showSizeChanger ??
|
||||
Boolean(
|
||||
local ||
|
||||
config.onPageSizeChange ||
|
||||
config.onShowSizeChange ||
|
||||
config.onChange,
|
||||
),
|
||||
...centerPaginationOptions({ className: config.className }, isMobile),
|
||||
current,
|
||||
pageSize,
|
||||
onShowSizeChange: undefined,
|
||||
onChange: (page, size) => {
|
||||
setLocalPage(size === pageSize ? page : 1);
|
||||
setLocalSize(size);
|
||||
events.onChange(page, size);
|
||||
if (size !== pageSize && managesSize) {
|
||||
setLocalSize(size);
|
||||
if (current !== 1) config.onPageChange?.(1);
|
||||
} else {
|
||||
events.onChange(page, size);
|
||||
}
|
||||
},
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function useValidPage({
|
||||
page,
|
||||
total,
|
||||
pageSize,
|
||||
loading,
|
||||
onPageChange,
|
||||
onChange,
|
||||
}) {
|
||||
const current = Math.min(page, lastPage(total, pageSize));
|
||||
const lastCorrection = React.useRef(null);
|
||||
React.useEffect(() => {
|
||||
if (page <= current) {
|
||||
lastCorrection.current = null;
|
||||
} else if (!loading) {
|
||||
const correction = `${page}:${current}:${pageSize}`;
|
||||
if (lastCorrection.current === correction) return;
|
||||
lastCorrection.current = correction;
|
||||
if (onPageChange) onPageChange(current);
|
||||
else onChange?.(current, pageSize);
|
||||
}
|
||||
}, [page, current, pageSize, loading, onPageChange, onChange]);
|
||||
return current;
|
||||
}
|
||||
|
||||
export function Pagination({
|
||||
currentPage,
|
||||
current,
|
||||
onPageChange,
|
||||
pageSizeOpts,
|
||||
onPageSizeChange,
|
||||
preventPageChangeOnPageSizeChange,
|
||||
size,
|
||||
showTotal,
|
||||
...props
|
||||
onShowSizeChange,
|
||||
onChange,
|
||||
pageSize = 10,
|
||||
total = 0,
|
||||
className,
|
||||
loading = false,
|
||||
}) {
|
||||
const isMobile = useIsMobile();
|
||||
const unified = isCenterPaginationScope();
|
||||
const { onChange: onAntChange, pageSize: configuredSize = 10 } = props;
|
||||
const config = {
|
||||
...props,
|
||||
currentPage,
|
||||
pageSize,
|
||||
onPageChange,
|
||||
onPageSizeChange,
|
||||
preventPageChangeOnPageSizeChange,
|
||||
onShowSizeChange,
|
||||
onChange,
|
||||
};
|
||||
const requestedPage = currentPage ?? props.current;
|
||||
const current =
|
||||
unified && props.total !== undefined && requestedPage !== undefined
|
||||
? Math.min(
|
||||
requestedPage,
|
||||
Math.max(1, Math.ceil(props.total / configuredSize)),
|
||||
)
|
||||
: requestedPage;
|
||||
React.useEffect(() => {
|
||||
if (unified && requestedPage !== undefined && requestedPage > current) {
|
||||
onPageChange?.(current);
|
||||
onAntChange?.(current, configuredSize);
|
||||
}
|
||||
}, [
|
||||
unified,
|
||||
requestedPage,
|
||||
current,
|
||||
onPageChange,
|
||||
onAntChange,
|
||||
configuredSize,
|
||||
]);
|
||||
const resolvedPage = useValidPage({
|
||||
page: currentPage ?? current ?? 1,
|
||||
total,
|
||||
loading,
|
||||
...config,
|
||||
});
|
||||
if (!total) return null;
|
||||
return (
|
||||
<Ant.Pagination
|
||||
{...props}
|
||||
current={current}
|
||||
{...(unified ? centerPaginationEvents(config) : paginationEvents(config))}
|
||||
pageSizeOptions={pageSizeOpts ?? props.pageSizeOptions}
|
||||
size={size === 'small' ? 'small' : 'default'}
|
||||
showTotal={paginationShowTotal(showTotal)}
|
||||
{...(unified
|
||||
? centerPaginationOptions({ className: props.className }, isMobile)
|
||||
: {})}
|
||||
{...centerPaginationOptions(
|
||||
{ className, showSizeChanger: hasPageSizeHandler(config) },
|
||||
isMobile,
|
||||
)}
|
||||
{...centerPaginationEvents(config)}
|
||||
current={resolvedPage}
|
||||
pageSize={pageSize}
|
||||
total={total}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
.center-pagination.ant-pagination {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.center-pagination.table-pagination-footer {
|
||||
margin-block: 16px 0;
|
||||
}
|
||||
|
||||
/* Keep the requested mobile controls visible below Ant's default breakpoint. */
|
||||
@media (max-width: 767px) {
|
||||
.center-pagination.ant-pagination {
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import i18next from 'i18next';
|
||||
|
||||
export const isCenterPaginationScope = () =>
|
||||
typeof window !== 'undefined' &&
|
||||
/^\/(?:console|org|user-center\/key-management)(?:\/|$)/.test(
|
||||
window.location?.pathname || '',
|
||||
);
|
||||
export const hasPageSizeHandler = ({
|
||||
onPageSizeChange,
|
||||
onShowSizeChange,
|
||||
onChange,
|
||||
}) => Boolean(onPageSizeChange || onShowSizeChange || onChange);
|
||||
|
||||
export const centerPaginationOptions = (config, isMobile = false) => ({
|
||||
...config,
|
||||
className: ['center-pagination', config.className].filter(Boolean).join(' '),
|
||||
size: 'small',
|
||||
showSizeChanger: true,
|
||||
align: 'end',
|
||||
hideOnSinglePage: false,
|
||||
showSizeChanger: config.showSizeChanger ?? true,
|
||||
showQuickJumper: isMobile,
|
||||
pageSizeOptions: [10, 20, 50, 100],
|
||||
showTotal: (total) => i18next.t('共 {{total}} 条', { total }),
|
||||
@@ -27,43 +29,12 @@ export function centerPaginationEvents(config) {
|
||||
else onChange?.(1, size);
|
||||
return;
|
||||
}
|
||||
onPageChange?.(page);
|
||||
onChange?.(page, size);
|
||||
if (onPageChange) onPageChange(page);
|
||||
else onChange?.(page, size);
|
||||
},
|
||||
onShowSizeChange: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
// Legacy pagination accepts a boolean; Ant Design calls a renderer when enabled.
|
||||
export const paginationShowTotal = (showTotal) =>
|
||||
showTotal === true ? (total) => `${total}` : showTotal;
|
||||
|
||||
// Preserve the existing callback sequence while Ant Design owns presentation.
|
||||
export function paginationEvents({
|
||||
currentPage,
|
||||
current,
|
||||
pageSize = 10,
|
||||
onPageChange,
|
||||
onChange,
|
||||
onPageSizeChange,
|
||||
onShowSizeChange,
|
||||
preventPageChangeOnPageSizeChange = false,
|
||||
}) {
|
||||
const page = currentPage ?? current ?? 1;
|
||||
return {
|
||||
onChange(nextPage, nextSize) {
|
||||
if (nextSize !== pageSize) return;
|
||||
if (nextPage !== page) onPageChange?.(nextPage);
|
||||
onChange?.(nextPage, nextSize);
|
||||
},
|
||||
onShowSizeChange(nextPage, nextSize) {
|
||||
onPageSizeChange?.(nextSize);
|
||||
onShowSizeChange?.(nextPage, nextSize);
|
||||
const next = preventPageChangeOnPageSizeChange
|
||||
? page
|
||||
: Math.floor(((page - 1) * pageSize) / nextSize) + 1;
|
||||
if (next !== page) onPageChange?.(next);
|
||||
onChange?.(next, nextSize);
|
||||
},
|
||||
};
|
||||
}
|
||||
export const lastPage = (total, pageSize) =>
|
||||
Math.max(1, Math.ceil(total / pageSize));
|
||||
|
||||
Reference in New Issue
Block a user