fix(pagination): 统一表格分页与密钥查询交互
统一各中心表格的分页样式和切换行为,保留密钥筛选条件与兑换码搜索分页。
This commit is contained in:
@@ -10,6 +10,14 @@
|
||||
|
||||
## 2026-11-20
|
||||
|
||||
### 修复 · 个人密钥管理查询交互对齐
|
||||
|
||||
- **范围**:用户中心密钥管理的查询、搜索、分页。
|
||||
- **变更**:保留按名称、Key 或分组匹配的单输入框,对齐控制台的输入防抖、立即搜索和重置操作。
|
||||
- **影响**:普通列表复用 `/api/token/` 服务端分页;搜索复用该个人接口取全,在本地匹配和分页,不调用管理员接口。
|
||||
- **回滚**:仅逆向恢复本条对应的查询表单和密钥数据加载差异。
|
||||
- **关联**:`src/pages/KeyManagement/index.jsx`、`src/hooks/tokens/useTokensData.jsx`、`docs/ui/KEY_MANAGEMENT_SPEC.md`。
|
||||
|
||||
### 修复 · 客服浮钮收起箭头残留
|
||||
|
||||
- **范围**:全站右下角客服浮钮。
|
||||
@@ -18,6 +26,13 @@
|
||||
- **回滚**:逆向恢复本条对应的客服浮钮焦点处理和样式差异。
|
||||
- **关联**:`src/components/customer-service/index.jsx`、`src/components/customer-service/styles.css`。
|
||||
|
||||
### 修复 · 全站表格统一分页
|
||||
|
||||
- **范围**:各中心、业务页面、卡片和弹层内原有分页的表格。
|
||||
- **变更**:统一为密钥管理的小型右对齐分页,补齐单页结果的条数入口和移动端跳页;未启用分页的表格保持原样。
|
||||
- **影响**:前端分页继续使用已加载数据,接口分页沿用原接口与筛选条件;换条数回到第一页,已分页的行不再二次切片。密钥管理本地筛选不再仅查当前接口页;兑换码翻页和换条数保留已提交的关键词。
|
||||
- **回滚**:逆向恢复本条对应的共享分页、页面分页接入、测试和规范差异。
|
||||
|
||||
### 更新 · 移除重复的长版权文件头
|
||||
|
||||
- **范围**:源码、脚本、样式、配置和测试中的统一长文件头。
|
||||
|
||||
@@ -202,7 +202,7 @@ try {
|
||||
- 批量操作:`rowSelection={{ selectedRowKeys, onChange: setSelectedRowKeys }}`。
|
||||
- 删除后的页码回退、筛选后的页码重置放在 hook 中处理(不要散落在组件中)。
|
||||
- 列设置只用于已有该功能的表格(`docs/ui/TABLE_COLUMN_SETTINGS_SPEC.md`)。
|
||||
- 分页统一用适配层 `Table` / `Pagination`;`/console`、`/org` 下自动统一,其他路由按下例显式传入,避免改页容量时请求两次:
|
||||
- 所有路由的分页表格用适配层 `Table` / `Pagination`。完整数据交给 `Table` 本地分页,不传 `total`;已由页面筛选切片或由接口返回单页数据时传 `total`,表格不会再次切片。未开启分页的表格保持原样。受控分页按下例传入,条数回调自行回到第 1 页,不再触发翻页回调:
|
||||
|
||||
```jsx
|
||||
pagination={{
|
||||
@@ -211,10 +211,6 @@ pagination={{
|
||||
total,
|
||||
onPageChange: handlePageChange,
|
||||
onPageSizeChange: handlePageSizeChange,
|
||||
showSizeChanger: true,
|
||||
pageSizeOpts: [10, 20, 50, 100],
|
||||
showTotal: (count) => t('共 {{total}} 条', { total: count }),
|
||||
preventPageChangeOnPageSizeChange: true,
|
||||
}}
|
||||
```
|
||||
|
||||
|
||||
@@ -172,6 +172,7 @@ html.dark .km-page {
|
||||
- 外观:小尺寸,可切换每页条数 `[10, 20, 50, 100]`,总数文案 `t('共 {{total}} 条', { total })`。
|
||||
- 用法:分页列表使用 `@/components/ui` 的 `Table` / `Pagination`。第 4 节的标准列表及其明细分页均沿用密钥管理:表格底部右对齐、小尺寸,依次显示“共 N 条”、上一页/页码/下一页、每页条数(10、20、50、100),移动端保留跳页。已加载的明细可本地分页;服务端分页传 `currentPage`、`pageSize`、`total` 以及分页回调,切换每页条数回到第 1 页,只发一次请求。导出仍作用于原有结果范围,不受当前页条数影响。
|
||||
- 删除当前页最后一条后回到上一页;前端分页的列表在筛选或数据变化时回到第 1 页。`/org/*` 的独立表格、页签和下钻明细均用此分页规则;已加载的树形表格按根节点分页,子节点不拆散;接口已分页时沿用原查询与总数。
|
||||
- 受控分页须实现条数回调(或兼容的统一变更回调)才显示条数选择,不用客户端切片模拟固定条数的服务端接口;分页启用且有结果时单页也显示分页栏。
|
||||
|
||||
## 7. 表单项
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
| --- | --- |
|
||||
| 路由 | `/user-center/key-management`,旧 `/key-management` 重定向 |
|
||||
| 视图 | `KeyManagement/index.jsx` + `key-management.css`;编辑抽屉由 `EditTokenModal presentation='drawer'` 渲染 |
|
||||
| 业务 | `useTokensData`、`/api/token*`、`buildTokenPayload`、启停与删除确认不变 |
|
||||
| 列表 | 固定列宽,每页 5 条;列设置不持久化 |
|
||||
| 业务 | `useTokensData` 负责后端查询与分页;`buildTokenPayload`、启停与删除确认不变 |
|
||||
| 列表 | 固定列宽,默认每页 10 条;列设置不持久化 |
|
||||
| 抽屉 | 模型列表 440px;创建 / 编辑 560px(移动 100%) |
|
||||
| 外壳 | 页头与边距按 `GLOBAL_UI_BASELINE.md` 4.4 |
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
| `src/pages/KeyManagement/key-management.css` | 页面作用域样式与 `--km-*` 变量 |
|
||||
| `src/components/table/tokens/modals/EditTokenDrawer.jsx` | 创建 / 编辑抽屉视图 |
|
||||
| `src/components/table/tokens/modals/EditTokenModal.jsx` | 状态、`formApi`、`submit`、`buildTokenPayload`;`presentation='drawer'` 时渲染抽屉 |
|
||||
| `src/hooks/tokens/useTokensData.jsx` | 列表、搜索、分页、启停、删除(不改) |
|
||||
| `src/hooks/tokens/useTokensData.jsx` | 列表、搜索、分页、启停、删除 |
|
||||
|
||||
独立路由形态(`.km-page-standalone`)只补顶栏偏移(桌面 100px、移动 80px)。
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
| 区域 | 规则 |
|
||||
| --- | --- |
|
||||
| 页头 | `UserCenterPageHeader`;“新手教程 / 查看操作指引”图标按钮保留在右侧 |
|
||||
| 查询卡 | 单字段:标签 + `Input allowClear`(宽 620px)+“重置”“搜索”;卡片上下内边距 22px,描边 `#f0f0f0`(深色 `--border-subtle`) |
|
||||
| 列表 | `Table size='middle' tableLayout='fixed'`,列宽 150 / 300 / 150 / 100 / 180 / 100 / 100 / 130;每页 5 条;列设置用 `ColumnSettings`,不持久化 |
|
||||
| 查询卡 | 保留单输入框,匹配密钥名称、Key 或分组。输入防抖,点击搜索或按回车立即提交,重置取消待提交条件并回到普通列表第 1 页 |
|
||||
| 列表 | `Table size='middle' tableLayout='fixed'`,列宽 150 / 300 / 150 / 100 / 180 / 100 / 100 / 130;默认每页 10 条;列设置用 `ColumnSettings`,不持久化 |
|
||||
| 状态 | `Switch`(`onChange` 仍走原 `Modal.confirm` → `manageToken`);已过期 / 已耗尽另显示语义 `Tag` |
|
||||
| 分组 | `Tag color='blue'` 无边框 + `Tooltip`;额度为 `Tag color='success'` |
|
||||
| 密钥 | `<code>` 密钥框(底 `#f4f6f9`、描边 `#e4e9ee`,深色引用 `--surface-bg-base` / `--border-subtle`)+ 显示、隐藏、复制图标按钮 + `Tooltip`;脱敏提示 `Alert type='success'` |
|
||||
@@ -48,7 +48,8 @@
|
||||
|
||||
## 3. 保留功能与已知差异
|
||||
|
||||
- 默认名称 `claudeNN`、每页 5 条、过去日期禁用为业务默认;“搜索”与回车即时生效。
|
||||
- 默认名称 `claudeNN`、过去日期禁用为业务默认。
|
||||
- 普通列表通过 `/api/token/` 服务端分页。个人搜索接口当前不支持单条件同时匹配名称、Key 和分组,也不提供分页结果;为保持原有条件,搜索复用个人列表接口取全后本地匹配和分页,不调用控制台管理接口。未取全时不展示部分搜索结果。
|
||||
- 技能注入关闭时“绑定技能”字段仅隐藏,仍注册在表单中,载荷不变。
|
||||
- 模型抽屉不显示来源说明行;“自定义”过期选项选中时仅文字变主色。
|
||||
- 第三方新手引导(Joyride)沿用其自身配色配置。
|
||||
|
||||
@@ -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));
|
||||
|
||||
+2
-40
@@ -1051,55 +1051,17 @@ export const createCardProPagination = ({
|
||||
total,
|
||||
onPageChange,
|
||||
onPageSizeChange,
|
||||
isMobile = false,
|
||||
pageSizeOpts = [10, 20, 50, 100],
|
||||
showSizeChanger = true,
|
||||
showRange = true,
|
||||
preventPageChangeOnPageSizeChange = false,
|
||||
t = i18next.t.bind(i18next),
|
||||
}) => {
|
||||
if (!total || total <= 0) return null;
|
||||
|
||||
const unified =
|
||||
typeof window !== 'undefined' &&
|
||||
/^\/(console|org)(\/|$)/.test(window.location?.pathname || '');
|
||||
|
||||
const start = (currentPage - 1) * pageSize + 1;
|
||||
const end = Math.min(currentPage * pageSize, total);
|
||||
const totalText = t('显示第 {{start}} 条 - 第 {{end}} 条,共 {{total}} 条', {
|
||||
start,
|
||||
end,
|
||||
total,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 桌面端左侧总数信息 */}
|
||||
{!unified && !isMobile && showRange && (
|
||||
<span
|
||||
className='text-sm select-none'
|
||||
style={{ color: 'var(--ui-color-text-2)' }}
|
||||
>
|
||||
{totalText}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* 右侧分页控件 */}
|
||||
total > 0 && (
|
||||
<Pagination
|
||||
className={!isMobile && (unified || !showRange) ? 'ml-auto' : undefined}
|
||||
currentPage={currentPage}
|
||||
pageSize={pageSize}
|
||||
total={total}
|
||||
pageSizeOpts={pageSizeOpts}
|
||||
showSizeChanger={showSizeChanger}
|
||||
onPageSizeChange={onPageSizeChange}
|
||||
onPageChange={onPageChange}
|
||||
preventPageChangeOnPageSizeChange={preventPageChangeOnPageSizeChange}
|
||||
size={unified || isMobile ? 'small' : 'default'}
|
||||
showQuickJumper={isMobile}
|
||||
showTotal={unified ? (total) => t('共 {{total}} 条', { total }) : true}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ export const useRedemptionsData = () => {
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
|
||||
const [tokenCount, setTokenCount] = useState(0);
|
||||
const [appliedKeyword, setAppliedKeyword] = useState('');
|
||||
const [selectedKeys, setSelectedKeys] = useState([]);
|
||||
|
||||
// Edit state
|
||||
@@ -75,18 +76,12 @@ export const useRedemptionsData = () => {
|
||||
};
|
||||
|
||||
// Search redemption codes
|
||||
const searchRedemptions = async () => {
|
||||
const { searchKeyword } = getFormValues();
|
||||
if (searchKeyword === '') {
|
||||
await loadRedemptions(1, pageSize);
|
||||
return;
|
||||
}
|
||||
|
||||
const loadSearchResults = async (keyword, page, size) => {
|
||||
setSearching(true);
|
||||
try {
|
||||
const res = await API.get(
|
||||
`/api/redemption/search?keyword=${searchKeyword}&p=1&page_size=${pageSize}`,
|
||||
);
|
||||
const res = await API.get('/api/redemption/search', {
|
||||
params: { keyword, p: page, page_size: size },
|
||||
});
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
const newPageData = data.items;
|
||||
@@ -98,8 +93,20 @@ export const useRedemptionsData = () => {
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
} finally {
|
||||
setSearching(false);
|
||||
}
|
||||
setSearching(false);
|
||||
};
|
||||
|
||||
const loadPage = (page, size, keyword = appliedKeyword) =>
|
||||
keyword
|
||||
? loadSearchResults(keyword, page, size)
|
||||
: loadRedemptions(page, size);
|
||||
|
||||
const searchRedemptions = () => {
|
||||
const { searchKeyword } = getFormValues();
|
||||
setAppliedKeyword(searchKeyword);
|
||||
return loadPage(1, pageSize, searchKeyword);
|
||||
};
|
||||
|
||||
// Manage redemption codes (CRUD operations)
|
||||
@@ -144,36 +151,19 @@ export const useRedemptionsData = () => {
|
||||
};
|
||||
|
||||
// Refresh data
|
||||
const refresh = async (page = activePage) => {
|
||||
const { searchKeyword } = getFormValues();
|
||||
if (searchKeyword === '') {
|
||||
await loadRedemptions(page, pageSize);
|
||||
} else {
|
||||
await searchRedemptions();
|
||||
}
|
||||
};
|
||||
const refresh = (page = activePage) => loadPage(page, pageSize);
|
||||
|
||||
// Handle page change
|
||||
const handlePageChange = (page) => {
|
||||
setActivePage(page);
|
||||
const { searchKeyword } = getFormValues();
|
||||
if (searchKeyword === '') {
|
||||
loadRedemptions(page, pageSize);
|
||||
} else {
|
||||
searchRedemptions();
|
||||
}
|
||||
return loadPage(page, pageSize);
|
||||
};
|
||||
|
||||
// Handle page size change
|
||||
const handlePageSizeChange = (size) => {
|
||||
setPageSize(size);
|
||||
setActivePage(1);
|
||||
const { searchKeyword } = getFormValues();
|
||||
if (searchKeyword === '') {
|
||||
loadRedemptions(1, size);
|
||||
} else {
|
||||
searchRedemptions();
|
||||
}
|
||||
return loadPage(1, size);
|
||||
};
|
||||
|
||||
// Row selection configuration
|
||||
@@ -279,7 +269,7 @@ export const useRedemptionsData = () => {
|
||||
showError(reason);
|
||||
});
|
||||
});
|
||||
useEffect(() => onScopeChange(), [onScopeChange, pageSize]);
|
||||
useEffect(() => onScopeChange(), [onScopeChange]);
|
||||
|
||||
return {
|
||||
// Data state
|
||||
|
||||
@@ -19,7 +19,7 @@ export const useTokensData = (openFluentNotification) => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
const [tokenCount, setTokenCount] = useState(0);
|
||||
const [pageSize, setPageSize] = useState(5);
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
const [searching, setSearching] = useState(false);
|
||||
|
||||
// Selection state
|
||||
@@ -319,7 +319,7 @@ export const useTokensData = (openFluentNotification) => {
|
||||
showError(reason);
|
||||
});
|
||||
});
|
||||
useEffect(() => onScopeChange(), [onScopeChange, pageSize]);
|
||||
useEffect(() => onScopeChange(), [onScopeChange]);
|
||||
|
||||
return {
|
||||
// Basic state
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
ConsoleListTable,
|
||||
} from '../../components/console/ConsolePrimitives';
|
||||
import ConsoleCollection from '../../components/console/ConsoleCollection';
|
||||
import TableEmpty from '../../components/common/table/TableEmpty';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import { createCardProPagination } from '../../helpers/utils';
|
||||
import React, { useEffect, useState, useCallback } from 'react';
|
||||
@@ -24,6 +25,7 @@ import {
|
||||
Modal,
|
||||
TextArea,
|
||||
Spin,
|
||||
Table,
|
||||
Typography,
|
||||
} from '@/components/ui';
|
||||
import {
|
||||
@@ -599,7 +601,9 @@ const AdminInvoice = () => {
|
||||
}}
|
||||
/>
|
||||
</Text>
|
||||
<ConsoleListTable
|
||||
<Table
|
||||
className='console-list-table'
|
||||
empty={<TableEmpty />}
|
||||
dataSource={detailData.topup_list}
|
||||
rowKey='id'
|
||||
pagination={{ pageSize: 10 }}
|
||||
|
||||
@@ -519,7 +519,6 @@ const AdminOrder = () => {
|
||||
setPageSize(size);
|
||||
},
|
||||
showTotal: true,
|
||||
showSizeChanger: false,
|
||||
}}
|
||||
scroll={{ x: 1100 }}
|
||||
size='middle'
|
||||
|
||||
@@ -279,7 +279,7 @@ export default function ListPanel({
|
||||
? {
|
||||
size: 'small',
|
||||
pageSize: server ? server.pageSize : pageSize,
|
||||
total: server ? server.total : filtered.length,
|
||||
total: server?.total,
|
||||
currentPage: server ? server.page : page,
|
||||
onPageChange: (next) => {
|
||||
setPage(next);
|
||||
|
||||
@@ -610,7 +610,7 @@ export default function PartnerPortal({
|
||||
columns={billColumns}
|
||||
pagination={
|
||||
visibleBills.length > 0
|
||||
? { pageSize: 10, current: billPage, onChange: setBillPage }
|
||||
? { pageSize: 10, current: billPage, onPageChange: setBillPage }
|
||||
: false
|
||||
}
|
||||
scroll={{ x: 1120 }}
|
||||
@@ -771,7 +771,7 @@ export default function PartnerPortal({
|
||||
? {
|
||||
pageSize: 10,
|
||||
current: detailPage,
|
||||
onChange: setDetailPage,
|
||||
onPageChange: setDetailPage,
|
||||
}
|
||||
: false
|
||||
}
|
||||
@@ -1058,7 +1058,7 @@ export default function PartnerPortal({
|
||||
? {
|
||||
pageSize: 10,
|
||||
current: customerPage,
|
||||
onChange: setCustomerPage,
|
||||
onPageChange: setCustomerPage,
|
||||
}
|
||||
: false
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
Tooltip,
|
||||
Modal,
|
||||
Badge,
|
||||
Select,
|
||||
} from '@/components/ui';
|
||||
import {
|
||||
ChevronUp,
|
||||
@@ -49,7 +48,6 @@ const VideoTaskQueue = ({
|
||||
const isCompact = useIsMobile();
|
||||
const [selectedTasks, setSelectedTasks] = useState([]);
|
||||
const [windowHeight, setWindowHeight] = useState(window.innerHeight);
|
||||
const [pageSize, setPageSize] = useState(5); // 新增:分页大小状态
|
||||
|
||||
// 监听窗口高度变化
|
||||
useEffect(() => {
|
||||
@@ -425,19 +423,6 @@ const VideoTaskQueue = ({
|
||||
<Tag size={!isCompact ? 'default' : 'small'} color='red'>
|
||||
{t('失败')}: {taskStats.failed}
|
||||
</Tag>
|
||||
{/* 分页大小选择器 */}
|
||||
<Select
|
||||
size={!isCompact ? 'default' : 'small'}
|
||||
value={pageSize}
|
||||
onChange={setPageSize}
|
||||
style={{ width: !isCompact ? '120px' : '100px' }}
|
||||
>
|
||||
<Select.Option value={3}>3 {t('条/页')}</Select.Option>
|
||||
<Select.Option value={5}>5 {t('条/页')}</Select.Option>
|
||||
<Select.Option value={10}>10 {t('条/页')}</Select.Option>
|
||||
<Select.Option value={20}>20 {t('条/页')}</Select.Option>
|
||||
<Select.Option value={50}>50 {t('条/页')}</Select.Option>
|
||||
</Select>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
@@ -448,11 +433,7 @@ const VideoTaskQueue = ({
|
||||
dataSource={tasks}
|
||||
rowKey='task_id'
|
||||
scroll={{ x: 'max-content' }}
|
||||
pagination={{
|
||||
pageSize: pageSize,
|
||||
showSizeChanger: false,
|
||||
size: !isCompact ? 'default' : 'small',
|
||||
}}
|
||||
pagination={{ pageSize: 10 }}
|
||||
rowSelection={{
|
||||
selectedRowKeys: selectedTasks,
|
||||
onChange: setSelectedTasks,
|
||||
|
||||
@@ -33,6 +33,8 @@ import { Modal, Pagination } from '@/components/ui';
|
||||
import { ShieldCheck } from 'lucide-react';
|
||||
import Joyride, { STATUS, ACTIONS, EVENTS } from 'react-joyride';
|
||||
import { useTokensData } from '../../hooks/tokens/useTokensData';
|
||||
import { useFilterSearch } from '../../hooks/common/useFilterSearch';
|
||||
import { collectPagedItems } from '../../helpers/paging';
|
||||
import EditTokenModal from '../../components/table/tokens/modals/EditTokenModal';
|
||||
import {
|
||||
API,
|
||||
@@ -484,6 +486,9 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
openFluentNotificationRef.current?.(key),
|
||||
);
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const [searchResult, setSearchResult] = useState(null);
|
||||
const [searchLoading, setSearchLoading] = useState(false);
|
||||
const searchRequest = useRef(0);
|
||||
const [showKeys, setShowKeys] = useState({});
|
||||
const [modelsSheetVisible, setModelsSheetVisible] = useState(false);
|
||||
const [selectedToken, setSelectedToken] = useState(null);
|
||||
@@ -498,6 +503,7 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
activePage,
|
||||
tokenCount,
|
||||
pageSize,
|
||||
loadTokens,
|
||||
showEdit,
|
||||
editingToken,
|
||||
setEditingToken,
|
||||
@@ -702,7 +708,7 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
okType: 'danger',
|
||||
onOk: async () => {
|
||||
await manageToken(token.id, 'delete', token);
|
||||
refresh();
|
||||
refreshKeyList();
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -725,15 +731,80 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
if (!handled) showInfo(t('暂无可用客服'));
|
||||
};
|
||||
|
||||
// Filter tokens(本页原本即输即筛;“搜索”/回车只是立即应用当前输入,不发请求)
|
||||
const filteredTokens = tokens.filter(
|
||||
(token) =>
|
||||
!searchValue ||
|
||||
token.name?.toLowerCase().includes(searchValue.toLowerCase()) ||
|
||||
token.key?.toLowerCase().includes(searchValue.toLowerCase()) ||
|
||||
token.group?.toLowerCase().includes(searchValue.toLowerCase()),
|
||||
const displayedPageSize = searchResult?.pageSize ?? pageSize;
|
||||
const listLoading = loading || searchLoading;
|
||||
|
||||
const runSearch = async (value, page = 1) => {
|
||||
const id = ++searchRequest.current;
|
||||
const query = value.trim().toLowerCase();
|
||||
if (!query) {
|
||||
setSearchLoading(false);
|
||||
setSearchResult(null);
|
||||
return loadTokens(1, displayedPageSize);
|
||||
}
|
||||
setSearchLoading(true);
|
||||
try {
|
||||
const { items, total, message, truncated } = await collectPagedItems(
|
||||
(p, size) => API.get('/api/token/', { params: { p, page_size: size } }),
|
||||
{ shouldAbort: () => id !== searchRequest.current },
|
||||
);
|
||||
if (id !== searchRequest.current) return;
|
||||
if (message || truncated || items.length < total) {
|
||||
showError(message || originalT('加载失败'));
|
||||
return;
|
||||
}
|
||||
const matches = items.filter((token) =>
|
||||
[token.name, token.key, token.group].some((value) =>
|
||||
value?.toLowerCase().includes(query),
|
||||
),
|
||||
);
|
||||
setSearchResult({
|
||||
query,
|
||||
items: matches,
|
||||
page: Math.min(
|
||||
page,
|
||||
Math.max(1, Math.ceil(matches.length / displayedPageSize)),
|
||||
),
|
||||
pageSize: displayedPageSize,
|
||||
});
|
||||
} catch (error) {
|
||||
if (id === searchRequest.current && !error?.isAxiosError) {
|
||||
showError(originalT('加载失败'));
|
||||
}
|
||||
} finally {
|
||||
if (id === searchRequest.current) setSearchLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
|
||||
(value = searchValue) => runSearch(value),
|
||||
);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
searchRequest.current += 1;
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const resetSearch = () => {
|
||||
cancelPendingSearch();
|
||||
setSearchValue('');
|
||||
runSearch('');
|
||||
};
|
||||
|
||||
const refreshKeyList = () =>
|
||||
searchResult ? runSearch(searchResult.query, searchResult.page) : refresh();
|
||||
|
||||
const displayedPage = searchResult?.page ?? activePage;
|
||||
const displayedTotal = searchResult?.items.length ?? tokenCount;
|
||||
const displayedTokens = searchResult
|
||||
? searchResult.items.slice(
|
||||
(displayedPage - 1) * displayedPageSize,
|
||||
displayedPage * displayedPageSize,
|
||||
)
|
||||
: tokens;
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 新手引导 */}
|
||||
@@ -880,8 +951,9 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
<div className='km-panels'>
|
||||
<ConsoleCollectionSearch className='km-card km-search-card tour-search-input'>
|
||||
<ConsoleFilterGrid
|
||||
onReset={() => setSearchValue('')}
|
||||
onSearch={() => setSearchValue(searchValue.trim())}
|
||||
onReset={resetSearch}
|
||||
onSearch={submitSearch}
|
||||
loading={listLoading}
|
||||
>
|
||||
<ConsoleFilterField label={t('密钥查询')} id='km-search-input'>
|
||||
<Input
|
||||
@@ -889,7 +961,14 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
prefix={<ActionSearch size={14} />}
|
||||
placeholder={t('搜索密钥名称、Key 或分组')}
|
||||
value={searchValue}
|
||||
onChange={(event) => setSearchValue(event.target.value)}
|
||||
onChange={(event) => {
|
||||
const value = event.target.value;
|
||||
searchRequest.current += 1;
|
||||
setSearchLoading(false);
|
||||
setSearchValue(value);
|
||||
scheduleSearch(value);
|
||||
}}
|
||||
autoComplete='off'
|
||||
allowClear
|
||||
/>
|
||||
</ConsoleFilterField>
|
||||
@@ -928,8 +1007,8 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
</div>
|
||||
|
||||
<KeyTable
|
||||
tokens={filteredTokens}
|
||||
loading={loading}
|
||||
tokens={displayedTokens}
|
||||
loading={listLoading}
|
||||
visibleColumns={visibleColumns}
|
||||
emptyText={<TableEmpty />}
|
||||
onCopy={copyText}
|
||||
@@ -942,17 +1021,28 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
t={t}
|
||||
/>
|
||||
|
||||
{tokenCount > 0 ? (
|
||||
{displayedTotal > 0 ? (
|
||||
<Pagination
|
||||
className='km-pagination'
|
||||
size='small'
|
||||
total={tokenCount}
|
||||
currentPage={activePage}
|
||||
pageSize={pageSize}
|
||||
showSizeChanger
|
||||
showTotal={(total) => t('共 {{total}} 条', { total })}
|
||||
onPageChange={handlePageChange}
|
||||
onPageSizeChange={handlePageSizeChange}
|
||||
total={displayedTotal}
|
||||
currentPage={displayedPage}
|
||||
pageSize={displayedPageSize}
|
||||
loading={listLoading}
|
||||
onPageChange={
|
||||
searchResult
|
||||
? (page) => setSearchResult({ ...searchResult, page })
|
||||
: handlePageChange
|
||||
}
|
||||
onPageSizeChange={
|
||||
searchResult
|
||||
? (pageSize) =>
|
||||
setSearchResult({
|
||||
...searchResult,
|
||||
page: 1,
|
||||
pageSize,
|
||||
})
|
||||
: handlePageSizeChange
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
</Card>
|
||||
@@ -961,7 +1051,7 @@ const KeyManagement = ({ embedded = false }) => {
|
||||
|
||||
{/* 创建/编辑抽屉 */}
|
||||
<EditTokenModal
|
||||
refresh={refresh}
|
||||
refresh={refreshKeyList}
|
||||
editingToken={editingToken}
|
||||
visiable={showEdit}
|
||||
handleClose={closeEdit}
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
RefreshCw as ActionRefreshCw,
|
||||
} from '@/components/common/icons/ActionIcons';
|
||||
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import Table from '../../components/ui/CenterActionTable';
|
||||
import { Table } from '@/components/ui';
|
||||
import { Empty, Spin, Button, Modal, Tooltip, Statistic, theme } from 'antd';
|
||||
import { Server, ChevronRight, Clock } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -414,16 +414,6 @@ const GroupMonitor = () => {
|
||||
);
|
||||
}, [selectedGroup?.model_stats]);
|
||||
|
||||
const modalPagination = useMemo(
|
||||
() => ({
|
||||
pageSize: 10,
|
||||
size: 'small',
|
||||
showSizeChanger: false,
|
||||
hideOnSinglePage: true,
|
||||
}),
|
||||
[],
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className='flex flex-col items-center justify-center py-20'>
|
||||
@@ -714,7 +704,7 @@ const GroupMonitor = () => {
|
||||
<Table
|
||||
columns={modelColumns}
|
||||
dataSource={modalDataSource}
|
||||
pagination={modalPagination}
|
||||
pagination={{ pageSize: 10 }}
|
||||
size='middle'
|
||||
rowKey='model'
|
||||
scroll={{ x: 680 }}
|
||||
|
||||
@@ -377,18 +377,7 @@ export default function SettingsChats(props) {
|
||||
columns={columns}
|
||||
dataSource={filteredConfigs}
|
||||
rowKey='id'
|
||||
pagination={{
|
||||
pageSize: 10,
|
||||
showSizeChanger: false,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) =>
|
||||
t('共 {{total}} 项,当前显示 {{start}}-{{end}} 项', {
|
||||
total,
|
||||
start: range[0],
|
||||
end: range[1],
|
||||
count: total,
|
||||
}),
|
||||
}}
|
||||
pagination={{ pageSize: 10 }}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
@@ -1686,7 +1686,6 @@ export default function ModelCostSettings() {
|
||||
pagination={{
|
||||
currentPage,
|
||||
pageSize,
|
||||
total: filteredRows.length,
|
||||
showSizeChanger: true,
|
||||
pageSizeOpts: [10, 20, 50, 100],
|
||||
onPageChange: setCurrentPage,
|
||||
|
||||
@@ -1202,7 +1202,6 @@ export default function ModelOfficialPriceSettings(props) {
|
||||
pagination={{
|
||||
currentPage,
|
||||
pageSize,
|
||||
total: filteredModels.length,
|
||||
showSizeChanger: true,
|
||||
pageSizeOpts: [10, 20, 50, 100],
|
||||
onPageChange: (page) => setCurrentPage(page),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { Alert } from 'antd';
|
||||
import { Button, Pagination, Tag, Toast, Typography } from '@/components/ui';
|
||||
import { Alert, Pagination } from 'antd';
|
||||
import { Button, Tag, Toast, Typography } from '@/components/ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Building2 } from 'lucide-react';
|
||||
@@ -756,10 +756,11 @@ const SkillMarket = () => {
|
||||
}
|
||||
pagination={
|
||||
<Pagination
|
||||
currentPage={result.page}
|
||||
current={result.page}
|
||||
pageSize={PAGE_SIZE}
|
||||
total={result.total}
|
||||
onPageChange={setPage}
|
||||
showSizeChanger={false}
|
||||
onChange={setPage}
|
||||
/>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -46,6 +46,7 @@ import { MarkdownRenderer } from '../../components/common/markdown/MarkdownRende
|
||||
import QuotaInput from '../../components/common/ui/QuotaInput';
|
||||
|
||||
const { Text } = Typography;
|
||||
const DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
const Invite = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -86,14 +87,14 @@ const Invite = () => {
|
||||
const [inviteesLoading, setInviteesLoading] = useState(false);
|
||||
const [inviteesTotal, setInviteesTotal] = useState(0);
|
||||
const [inviteesPage, setInviteesPage] = useState(1);
|
||||
const [inviteesPageSize, setInviteesPageSize] = useState(DEFAULT_PAGE_SIZE);
|
||||
|
||||
// 收益明细
|
||||
const [rebates, setRebates] = useState([]);
|
||||
const [rebatesLoading, setRebatesLoading] = useState(false);
|
||||
const [rebatesTotal, setRebatesTotal] = useState(0);
|
||||
const [rebatesPage, setRebatesPage] = useState(1);
|
||||
|
||||
const pageSize = 10;
|
||||
const [rebatesPageSize, setRebatesPageSize] = useState(DEFAULT_PAGE_SIZE);
|
||||
|
||||
// 获取统计信息
|
||||
const fetchStats = async () => {
|
||||
@@ -126,12 +127,12 @@ const Invite = () => {
|
||||
};
|
||||
|
||||
// 获取邀请人员明细
|
||||
const fetchInvitees = async (page = 1) => {
|
||||
const fetchInvitees = async (page = 1, size = DEFAULT_PAGE_SIZE) => {
|
||||
setInviteesLoading(true);
|
||||
try {
|
||||
const res = await API.get(
|
||||
`/api/user/self/invite/invitees?page=${page}&size=${pageSize}`,
|
||||
);
|
||||
const res = await API.get('/api/user/self/invite/invitees', {
|
||||
params: { page, size },
|
||||
});
|
||||
if (res.data.success) {
|
||||
setInvitees(res.data.data || []);
|
||||
setInviteesTotal(res.data.total || 0);
|
||||
@@ -146,12 +147,12 @@ const Invite = () => {
|
||||
};
|
||||
|
||||
// 获取收益明细
|
||||
const fetchRebates = async (page = 1) => {
|
||||
const fetchRebates = async (page = 1, size = DEFAULT_PAGE_SIZE) => {
|
||||
setRebatesLoading(true);
|
||||
try {
|
||||
const res = await API.get(
|
||||
`/api/user/self/invite/rebates?page=${page}&size=${pageSize}`,
|
||||
);
|
||||
const res = await API.get('/api/user/self/invite/rebates', {
|
||||
params: { page, size },
|
||||
});
|
||||
if (res.data.success) {
|
||||
setRebates(res.data.data || []);
|
||||
setRebatesTotal(res.data.total || 0);
|
||||
@@ -558,11 +559,16 @@ const Invite = () => {
|
||||
loading={inviteesLoading}
|
||||
pagination={{
|
||||
currentPage: inviteesPage,
|
||||
pageSize: pageSize,
|
||||
pageSize: inviteesPageSize,
|
||||
total: inviteesTotal,
|
||||
onPageChange: (page) => {
|
||||
setInviteesPage(page);
|
||||
fetchInvitees(page);
|
||||
fetchInvitees(page, inviteesPageSize);
|
||||
},
|
||||
onPageSizeChange: (size) => {
|
||||
setInviteesPage(1);
|
||||
setInviteesPageSize(size);
|
||||
fetchInvitees(1, size);
|
||||
},
|
||||
}}
|
||||
className='invite-clean-table'
|
||||
@@ -590,11 +596,16 @@ const Invite = () => {
|
||||
loading={rebatesLoading}
|
||||
pagination={{
|
||||
currentPage: rebatesPage,
|
||||
pageSize: pageSize,
|
||||
pageSize: rebatesPageSize,
|
||||
total: rebatesTotal,
|
||||
onPageChange: (page) => {
|
||||
setRebatesPage(page);
|
||||
fetchRebates(page);
|
||||
fetchRebates(page, rebatesPageSize);
|
||||
},
|
||||
onPageSizeChange: (size) => {
|
||||
setRebatesPage(1);
|
||||
setRebatesPageSize(size);
|
||||
fetchRebates(1, size);
|
||||
},
|
||||
}}
|
||||
className='invite-clean-table'
|
||||
|
||||
@@ -70,6 +70,7 @@ const Invoice = () => {
|
||||
const [invoices, setInvoices] = useState([]);
|
||||
const [invoicesTotal, setInvoicesTotal] = useState(0);
|
||||
const [invoicesPage, setInvoicesPage] = useState(1);
|
||||
const [invoicesPageSize, setInvoicesPageSize] = useState(10);
|
||||
const [invoicesLoading, setInvoicesLoading] = useState(false);
|
||||
|
||||
// 详情弹窗
|
||||
@@ -109,7 +110,7 @@ const Invoice = () => {
|
||||
setInvoicesLoading(true);
|
||||
try {
|
||||
const res = await API.get('/api/user/invoice/self', {
|
||||
params: { p: invoicesPage, page_size: 10 },
|
||||
params: { p: invoicesPage, page_size: invoicesPageSize },
|
||||
});
|
||||
if (res.data.success) {
|
||||
setInvoices(res.data.data?.items || []);
|
||||
@@ -120,7 +121,7 @@ const Invoice = () => {
|
||||
} finally {
|
||||
setInvoicesLoading(false);
|
||||
}
|
||||
}, [invoicesPage]);
|
||||
}, [invoicesPage, invoicesPageSize]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!nuonuoEnabled) return;
|
||||
@@ -527,8 +528,12 @@ const Invoice = () => {
|
||||
pagination={{
|
||||
currentPage: invoicesPage,
|
||||
total: invoicesTotal,
|
||||
pageSize: 10,
|
||||
pageSize: invoicesPageSize,
|
||||
onPageChange: setInvoicesPage,
|
||||
onPageSizeChange: (size) => {
|
||||
setInvoicesPage(1);
|
||||
setInvoicesPageSize(size);
|
||||
},
|
||||
showTotal: true,
|
||||
}}
|
||||
scroll={{ x: 800 }}
|
||||
|
||||
@@ -145,7 +145,7 @@ async function modelTestFixture() {
|
||||
),
|
||||
Typography: { Text: 'Text' },
|
||||
},
|
||||
'../../../ui/CenterActionTable': 'Table',
|
||||
'@/components/ui': { Table: 'Table' },
|
||||
'lucide-react': { Search: 'Search' },
|
||||
'./model-test-modal.css': {},
|
||||
'../../../../helpers': {},
|
||||
@@ -180,13 +180,13 @@ async function modelTestFixture() {
|
||||
};
|
||||
}
|
||||
|
||||
test('Model test dialog passes the complete filtered list to native Ant pagination', async () => {
|
||||
test('Model test dialog passes the complete filtered list to local table pagination', async () => {
|
||||
const { table, models } = await modelTestFixture();
|
||||
assert.deepEqual(
|
||||
Array.from(table.dataSource, (row) => row.model),
|
||||
models,
|
||||
);
|
||||
assert.equal(table.pagination.total, 24);
|
||||
assert.equal(table.pagination.total, undefined);
|
||||
assert.equal(table.pagination.current, 2);
|
||||
assert.equal(table.pagination.pageSize, 5);
|
||||
const html = renderToStaticMarkup(React.createElement(AntTable, table));
|
||||
|
||||
@@ -185,6 +185,19 @@ for (const cfg of [
|
||||
fn: 'fetchInvoices',
|
||||
expectedPath: '/api/invoice/list',
|
||||
},
|
||||
{
|
||||
file: 'src/pages/UserCenter/Invoice.jsx',
|
||||
fn: 'fetchInvoices',
|
||||
expectedPath: '/api/user/invoice/self',
|
||||
values: { invoicesPage: 3, invoicesPageSize: 50 },
|
||||
},
|
||||
{
|
||||
file: 'src/hooks/redemptions/useRedemptionsData.jsx',
|
||||
fn: 'loadSearchResults',
|
||||
expectedPath: '/api/redemption/search',
|
||||
args: ['pagination-fixture', 3, 50],
|
||||
values: { setRedemptionFormat: () => {} },
|
||||
},
|
||||
{
|
||||
file: 'src/pages/AdminOrganizations/index.jsx',
|
||||
fn: 'fetchOrgs',
|
||||
@@ -354,10 +367,16 @@ test('Resizing emits one size callback and never a stale page request', () => {
|
||||
events.onChange(3, 50);
|
||||
assert.deepEqual(calls, [['size', 50]]);
|
||||
events.onChange(2, 10);
|
||||
assert.deepEqual(calls.slice(1), [
|
||||
['page', 2],
|
||||
['change', 2, 10],
|
||||
]);
|
||||
assert.deepEqual(calls.slice(1), [['page', 2]]);
|
||||
});
|
||||
test('Combined change handlers receive page one with the new size', () => {
|
||||
const calls = [];
|
||||
const events = pagination.centerPaginationEvents({
|
||||
pageSize: 20,
|
||||
onChange: (page, size) => calls.push([page, size]),
|
||||
});
|
||||
events.onChange(3, 50);
|
||||
assert.deepEqual(calls, [[1, 50]]);
|
||||
});
|
||||
test('Legacy Ant resize handlers receive page one exactly once', () => {
|
||||
const calls = [];
|
||||
@@ -424,6 +443,36 @@ test('Tables with pagination false or omitted never gain a paginator', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('Supplied page rows pass through, while complete datasets are sliced locally', () => {
|
||||
const dataSource = Array.from({ length: 25 }, (_, index) => ({
|
||||
id: index + 1,
|
||||
name: `pagination-row-${index + 1}-end`,
|
||||
}));
|
||||
const render = (config) =>
|
||||
renderToStaticMarkup(
|
||||
Table({
|
||||
rowKey: 'id',
|
||||
columns: [{ dataIndex: 'name' }],
|
||||
dataSource,
|
||||
pagination: { currentPage: 2, pageSize: 10, ...config },
|
||||
}),
|
||||
);
|
||||
|
||||
const local = render({});
|
||||
assert.match(local, /pagination-row-11-end/);
|
||||
assert.doesNotMatch(local, /pagination-row-(1|21)-end/);
|
||||
assert.match(local, /ant-pagination-options-size-changer/);
|
||||
|
||||
const supplied = render({ total: 75, onPageSizeChange() {} });
|
||||
assert.match(supplied, /pagination-row-1-end/);
|
||||
assert.match(supplied, /pagination-row-25-end/);
|
||||
assert.match(supplied, /ant-pagination-options-size-changer/);
|
||||
assert.doesNotMatch(
|
||||
render({ total: 75 }),
|
||||
/ant-pagination-options-size-changer/,
|
||||
);
|
||||
});
|
||||
|
||||
test('Existing unpaginated tables keep pagination disabled after other UI edits', async () => {
|
||||
const expected = JSON.parse(
|
||||
await fs.readFile(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { paginationEvents } from '../src/components/ui/pagination.js';
|
||||
import { centerPaginationEvents } from '../src/components/ui/pagination.js';
|
||||
import test from 'node:test';
|
||||
import { runInNewContext } from 'node:vm';
|
||||
import React from 'react';
|
||||
@@ -48,18 +48,14 @@ const { createCardProPagination } = loadUtils({
|
||||
const loadUsersPage = await compile('../src/components/table/users/index.jsx');
|
||||
|
||||
function paginationProps(element) {
|
||||
const pagination = React.Children.toArray(element.props.children).find(
|
||||
(child) => child.type === 'antd-pagination',
|
||||
);
|
||||
assert.ok(pagination, 'The helper must render Ant Design Pagination');
|
||||
return pagination.props;
|
||||
assert.equal(element.type, 'antd-pagination');
|
||||
return element.props;
|
||||
}
|
||||
|
||||
function foundationFor(props) {
|
||||
const events = paginationEvents(props);
|
||||
const events = centerPaginationEvents(props);
|
||||
return {
|
||||
changePageSize: (size) => {
|
||||
events.onShowSizeChange(props.currentPage, size);
|
||||
events.onChange(props.currentPage, size);
|
||||
},
|
||||
goPage: (page) => events.onChange(page, props.pageSize),
|
||||
@@ -70,7 +66,7 @@ for (const option of [{}, { preventPageChangeOnPageSizeChange: false }]) {
|
||||
const mode = Object.hasOwn(option, 'preventPageChangeOnPageSizeChange')
|
||||
? 'explicit false'
|
||||
: 'default';
|
||||
test(`other tables retain existing resize page callback: ${mode}`, () => {
|
||||
test(`other tables avoid a second page callback on resize: ${mode}`, () => {
|
||||
const calls = [];
|
||||
const props = paginationProps(
|
||||
createCardProPagination({
|
||||
@@ -85,11 +81,7 @@ for (const option of [{}, { preventPageChangeOnPageSizeChange: false }]) {
|
||||
|
||||
foundationFor(props).changePageSize(20);
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
['size', 20],
|
||||
['page', 2],
|
||||
]);
|
||||
assert.equal(props.preventPageChangeOnPageSizeChange, false);
|
||||
assert.deepEqual(calls, [['size', 20]]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,10 +122,8 @@ for (const isMobile of [false, true]) {
|
||||
foundationFor(props).changePageSize(20);
|
||||
|
||||
assert.deepEqual(calls, [['size', 20]]);
|
||||
assert.equal(props.preventPageChangeOnPageSizeChange, true);
|
||||
assert.equal(props.onPageSizeChange, usersData.handlePageSizeChange);
|
||||
assert.equal(props.onPageChange, usersData.handlePageChange);
|
||||
assert.equal(props.size, isMobile ? 'small' : 'default');
|
||||
|
||||
// The hook owns the reset; verify navigation after its next render.
|
||||
usersData.activePage = 1;
|
||||
@@ -176,28 +166,18 @@ for (const [name, render] of [
|
||||
],
|
||||
['Pagination', (props) => React.createElement(Pagination, props)],
|
||||
]) {
|
||||
test(`${name} renders legacy boolean showTotal without crashing`, () => {
|
||||
test(`${name} renders the standard translated total`, () => {
|
||||
const element = render({ total: 25, pageSize: 10, showTotal: true });
|
||||
const html = renderToStaticMarkup(element);
|
||||
assert.match(html, /class="ant-pagination-total-text">25<\/li>/);
|
||||
assert.match(html, /class="ant-pagination-total-text"/);
|
||||
});
|
||||
|
||||
test(`${name} preserves a custom total renderer and its range arguments`, () => {
|
||||
const showTotal = (total, range) => `${range.join('-')} of ${total}`;
|
||||
const element = render({ total: 25, pageSize: 10, showTotal });
|
||||
const props = name === 'Table' ? element.props.pagination : element.props;
|
||||
assert.equal(props.showTotal, showTotal);
|
||||
assert.match(renderToStaticMarkup(element), /1-10 of 25/);
|
||||
test(`${name} uses the same total appearance even with legacy overrides`, () => {
|
||||
const expected = renderToStaticMarkup(render({ total: 25, pageSize: 10 }));
|
||||
for (const showTotal of [false, () => 'custom range']) {
|
||||
assert.equal(renderToStaticMarkup(render({ total: 25, pageSize: 10, showTotal })), expected);
|
||||
}
|
||||
});
|
||||
|
||||
for (const showTotal of [false, undefined]) {
|
||||
test(`${name} hides the total when showTotal is ${showTotal}`, () => {
|
||||
const html = renderToStaticMarkup(
|
||||
render({ total: 25, pageSize: 10, showTotal }),
|
||||
);
|
||||
assert.doesNotMatch(html, /ant-pagination-total-text/);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test('Table keeps pagination disabled for settings tables without pagination', () => {
|
||||
|
||||
Reference in New Issue
Block a user