From 7b83893cf6920dbb58b56f5297cb6d0f9de07a6d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Oct 2026 22:22:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E6=94=AF=E4=BB=98=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E5=88=97=E8=A1=A8=E9=A1=B5=E7=BB=9F=E4=B8=80=E4=B8=BA?= =?UTF-8?q?=20WP=20=E5=8E=9F=E7=94=9F=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 七个支付中心列表页(订单明细 / 售后服务 / 付费文章 / 优惠码 / 创作分成 / 提现审核 / 卡密管理)的分页收敛到共享助手 AdminListPagination,改用 WP 原生 paginate_links() 渲染。 - 基准 URL 显式以 page 参数 + 当前筛选参数拼装,不再让两个参数的 add_query_arg('paged', ...) 退回 $_SERVER['REQUEST_URI']:链接不再随当前 请求形态漂移,列条件也不再丢失 - 售后服务从写死的 limit => 100 改为 limit/offset 分页,总数接上原本零调用的 AfterSaleService::count();after_sale_status 先按状态常量归一,保证 count() 与 admin_list() 口径一致,分页条不说谎 - 每页 20 条,统一来自 AdminListPagination::DEFAULT_PER_PAGE - 每页在查询前夹取页码,越界时回退到最后一页并重查,杜绝「空表且没有分页条」 的死胡同;页码夹取与早退也一并收敛到助手 - 提现审核的翻页链接排除 retry_id / retry_key 两个一次性动作参数 - 订单明细的标签页与翻页链接共用同一份筛选参数,不再各写一份 清理死代码:五个页面里近乎复制的 render_pagination()(其中订单明细与提现审核 两份从未被调用)、两页重复的内联 paginate_links 块、卡密管理的 render_pagenavi() 及其 docblock、PayChargeCards::DEFAULT_PER_PAGE 常量,以及只服务自定义禁用 按钮的 .tablenav-pages a.disabled 规则。 验证:tests/admin/ 76 项通过(新增 pay-pages-pagination.test.cjs,重写 charge-cards-pagination.test.cjs);用 git show HEAD 取出原文件对比,订单明细 与售后服务两页在新旧实现下渲染输出逐字节相同。 --- src/Admin/Native/AdminListPagination.php | 74 +++++++ src/Admin/Native/PayChargeCards.php | 59 +----- src/Admin/Native/PayCoupons.php | 44 ++-- src/Admin/Native/PayIncome.php | 45 ++-- src/Admin/Native/PayOrders.php | 126 ++++++----- src/Admin/Native/PayProducts.php | 43 ++-- src/Admin/Native/PayWithdrawals.php | 57 ++--- tests/admin/charge-cards-pagination.test.cjs | 95 ++++----- tests/admin/pay-pages-pagination.test.cjs | 210 +++++++++++++++++++ tests/dev/render-after-sales-harness.php | 5 +- 10 files changed, 516 insertions(+), 242 deletions(-) create mode 100644 src/Admin/Native/AdminListPagination.php create mode 100644 tests/admin/pay-pages-pagination.test.cjs diff --git a/src/Admin/Native/AdminListPagination.php b/src/Admin/Native/AdminListPagination.php new file mode 100644 index 00000000..6e5891fc --- /dev/null +++ b/src/Admin/Native/AdminListPagination.php @@ -0,0 +1,74 @@ + $query_args 当前筛选参数,不含 paged。 + */ + public static function render( + string $page_slug, + int $total_count, + int $current_page, + int $per_page, + array $query_args = [] + ): void { + if ($total_count <= 0 || $per_page <= 0) { + return; + } + + $total_pages = max(1, (int) ceil($total_count / $per_page)); + $current_page = min(max(1, $current_page), $total_pages); + + if ($total_pages <= 1) { + return; + } + + // 显式基准 URL:不再让 add_query_arg() 只有两个参数时退回 $_SERVER['REQUEST_URI']。 + $base = add_query_arg(array_merge(['page' => $page_slug], $query_args), admin_url('admin.php')); + $base = add_query_arg('paged', '%#%', $base); + + echo '
'; + echo '' . esc_html(sprintf( + /* translators: %s: 记录总数 */ + __('共 %s 项', 'aksrt'), + number_format_i18n($total_count) + )) . ''; + echo paginate_links([ + 'base' => $base, + 'format' => '', + 'current' => $current_page, + 'total' => $total_pages, + 'prev_text' => '«', + 'next_text' => '»', + ]); // phpcs:ignore WordPress.Security.EscapeOutput -- paginate_links 自行转义。 + echo '
'; + } +} diff --git a/src/Admin/Native/PayChargeCards.php b/src/Admin/Native/PayChargeCards.php index 592b48f9..63911d10 100644 --- a/src/Admin/Native/PayChargeCards.php +++ b/src/Admin/Native/PayChargeCards.php @@ -21,9 +21,6 @@ class PayChargeCards { public const NONCE = 'aksrt_card_pass_page'; public const EXPORT_AJAX_ACTION = 'aksrt_card_pass_export'; - /** 每页条数默认值;列表页可由 ice_perpage 覆盖(无界面控件,仅供 URL / 程序化调用)。 */ - public const DEFAULT_PER_PAGE = 20; - private static $instance = null; /** @var string 当前页面 URL */ @@ -119,7 +116,8 @@ class PayChargeCards { $orderby = isset($_GET['orderby']) ? sanitize_key((string) wp_unslash($_GET['orderby'])) : 'modified_time'; $order = isset($_GET['desc']) ? (strtoupper((string) wp_unslash($_GET['desc'])) === 'ASC' ? 'ASC' : 'DESC') : 'DESC'; $paged = max(1, (int) ($_GET['paged'] ?? 1)); - $per_page = max(1, min(100, (int) ($_REQUEST['ice_perpage'] ?? self::DEFAULT_PER_PAGE))); + // 每页条数默认值取自共享助手;ice_perpage 仅作为 URL 参数被尊重,无界面控件。 + $per_page = max(1, min(100, (int) ($_REQUEST['ice_perpage'] ?? AdminListPagination::DEFAULT_PER_PAGE))); // 参考主题:status=0 表示未使用;本主题规范状态为 active。 if ($status === '0' || $status === 'active') { @@ -297,7 +295,7 @@ class PayChargeCards { echo ''; echo '
'; - $this->render_pagenavi($count_all, $per_page, $query_args); + AdminListPagination::render(self::PAGE_SLUG, $count_all, $paged, $per_page, $query_args); } /* ------------------------------------------------------------------ @@ -1059,67 +1057,18 @@ class PayChargeCards { if ($order === 'ASC') { $args['desc'] = 'ASC'; } - if ($per_page !== self::DEFAULT_PER_PAGE) { + if ($per_page !== AdminListPagination::DEFAULT_PER_PAGE) { $args['ice_perpage'] = (string) $per_page; } return $args; } - /** - * 分页(参考主题 zibpay_admin_pagenavi 同款结构与禁用逻辑)。 - * - * 与参考实现的两处差异,均为缺陷修复: - * 1) 页码先夹到 [1, total_pages]。历史写法在此处会出现「第 2 页 / 共 1 页」这类越界状态, - * 四个分支一个都不命中,上一页/下一页同时停在 '#',按钮既不禁用也点不动。 - * 2) 链接基于显式基准 URL(page_url + 当前筛选条件),不再依赖 REQUEST_URI。 - * - * @param array $query_args 当前筛选参数(不含 paged)。 - */ - private function render_pagenavi(int $total_count, int $number_per_page, array $query_args = []): void { - if ($total_count <= 0 || $number_per_page <= 0) { - return; - } - - $total_pages = max(1, (int) ceil($total_count / $number_per_page)); - $current_page = min(max(1, (int) ($_GET['paged'] ?? 1)), $total_pages); - - $base = $query_args ? add_query_arg($query_args, $this->page_url) : $this->page_url; - $page_url = static function (int $page) use ($base): string { - return add_query_arg('paged', $page, $base); - }; - - $on_first = $current_page <= 1; - $on_last = $current_page >= $total_pages; - - $first_page_url = $on_first ? '#' : $page_url(1); - $prev_page_url = $on_first ? '#' : $page_url($current_page - 1); - $next_page_url = $on_last ? '#' : $page_url($current_page + 1); - $last_page_url = $on_last ? '#' : $page_url($total_pages); - ?> -
-
- - - « - ‹ - ' . esc_html((string) $total_pages) . ''); ?> - › - » - -
-
-