diff --git a/.gitignore b/.gitignore
index 0acd1d6d..c458d63a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,6 +55,9 @@
!/tests/widget-system/circular-button-icon-margin-contract.test.cjs
!/tests/widget-system/single-cover-height-contract.test.cjs
!/tests/widget-system/frontend-lifecycle-contract.test.cjs
+!/tests/admin/
+/tests/admin/*
+!/tests/admin/charge-cards-page-contract.test.cjs
!/tests/front-submit/
/tests/front-submit/*
!/tests/front-submit/video-cover-contract.test.cjs
diff --git a/src/Admin/Native/PayChargeCards.php b/src/Admin/Native/PayChargeCards.php
index 03630fea..49655b21 100644
--- a/src/Admin/Native/PayChargeCards.php
+++ b/src/Admin/Native/PayChargeCards.php
@@ -51,8 +51,9 @@ class PayChargeCards {
}
$tab = isset($_GET['tab']) ? sanitize_key((string) wp_unslash($_GET['tab'])) : '';
+ $s = isset($_REQUEST['s']) ? sanitize_text_field((string) wp_unslash($_REQUEST['s'])) : '';
$page_title = __('卡密管理', 'aksrt');
- $head_but = '' . esc_html__('添加卡密', 'aksrt') . '';
+ $head_but = '';
// 页面级动作(参考主题在渲染前处理 add / delete)。
$action = isset($_REQUEST['action']) ? sanitize_key((string) wp_unslash($_REQUEST['action'])) : '';
@@ -62,6 +63,7 @@ class PayChargeCards {
$this->handle_delete();
}
+ // 标题右侧按钮是页面头部的一部分,只在此处输出一次(列表页同样如此,由 render_list 负责列表本体)。
switch ($tab) {
case 'add':
$page_title = __('添加卡密', 'aksrt');
@@ -72,6 +74,14 @@ class PayChargeCards {
$page_title = __('导出卡密', 'aksrt');
$head_but = '' . esc_html__('返回列表', 'aksrt') . '';
break;
+
+ default:
+ $head_but = '' . esc_html__('添加卡密', 'aksrt') . '';
+ $head_but .= '' . esc_html__('导出卡密', 'aksrt') . '';
+ if ($s !== '') {
+ $head_but .= '
' . sprintf(esc_html__('搜索 “%s” 的内容', 'aksrt'), esc_html($s)) . '
';
+ }
+ break;
}
echo '';
@@ -84,7 +94,7 @@ class PayChargeCards {
} elseif ($tab === 'export') {
$this->render_export_form();
} else {
- $this->render_list();
+ $this->render_list($s);
}
echo '
';
@@ -94,17 +104,19 @@ class PayChargeCards {
* 列表
* ------------------------------------------------------------------ */
- private function render_list(): void {
+ /**
+ * @param string $s 搜索词(由页面头部统一解析后传入,用于提示、过滤链接与查询)。
+ */
+ private function render_list(string $s): void {
$svc = \AKSRT\Payment\ChargeCard::get_instance();
- $s = isset($_REQUEST['s']) ? sanitize_text_field((string) wp_unslash($_REQUEST['s'])) : '';
- $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
- $type = isset($_GET['type']) ? sanitize_key((string) wp_unslash($_GET['type'])) : '';
- $other = isset($_GET['other']) ? sanitize_text_field((string) wp_unslash($_GET['other'])) : '';
- $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'] ?? 30)));
+ $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
+ $type = isset($_GET['type']) ? sanitize_key((string) wp_unslash($_GET['type'])) : '';
+ $other = isset($_GET['other']) ? sanitize_text_field((string) wp_unslash($_GET['other'])) : '';
+ $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'] ?? 30)));
// 参考主题:status=0 表示未使用;本主题规范状态为 active。
if ($status === '0' || $status === 'active') {
@@ -116,15 +128,7 @@ class PayChargeCards {
$type = '';
}
- // 标题右侧按钮与过滤链接。
- $head_but = '';
- if ($s !== '') {
- $head_but .= '' . sprintf(esc_html__('搜索 “%s” 的内容', 'aksrt'), esc_html($s)) . '
';
- } else {
- $head_but .= '' . esc_html__('添加卡密', 'aksrt') . '';
- $head_but .= '' . esc_html__('导出卡密', 'aksrt') . '';
- }
-
+ // 过滤链接(标题右侧按钮与搜索提示由页面头部统一输出)。
$sub_but = [
['name' => __('全部', 'aksrt'), 'href' => $this->page_url],
];
@@ -148,7 +152,6 @@ class PayChargeCards {
';
- echo $head_but; // phpcs:ignore WordPress.Security.EscapeOutput -- 已转义。
echo '';
$result = $svc->get_list([
@@ -203,10 +206,9 @@ class PayChargeCards {
$meta = is_array($decoded) ? $decoded : [];
}
+ // 自定义卡密不展示状态;其余类型按状态着色(类型链接统一在下方链表中生成)。
$status_html = '';
- if ($msg['type'] === 'custom') {
- $type_html = '' . esc_html__('自定义卡密', 'aksrt') . '';
- } else {
+ if ($msg['type'] !== 'custom') {
$status_html = '' . esc_html__('未使用', 'aksrt') . '';
if ($msg['status'] === 'used') {
$status_html = '' . esc_html__('已使用', 'aksrt') . '';
@@ -1029,8 +1031,11 @@ class PayChargeCards {