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) . ''); ?> - › - » - -
-
-