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