From f6805bfd171d08c1bea1a97d3328df82200c28f6 Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Thu, 29 Oct 2026 13:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC58=E6=89=B9=E7=BB=AD29=EF=BC=9APHP?= =?UTF-8?q?=E7=A7=AF=E5=88=86HTML=E6=B1=A1=E6=9F=93=E4=BF=AE=E5=A4=8D+clos?= =?UTF-8?q?eModal=E7=BC=BA=E5=A4=B1=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - adminDeduct/adminAddBonds 用 exit(json_encode()) 改为 jsonResponse() jsonResponse 内部清空所有缓冲区再输出,避免PHP警告污染JSON - admin.php 添加 closeModal 函数(原本缺少,showModal 路径会调用) --- admin.php | 5 +++++ api/admin.php | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/admin.php b/admin.php index 809868a..66634e9 100644 --- a/admin.php +++ b/admin.php @@ -2117,6 +2117,11 @@ function showModal(title, message, defaultValue, customHtml) { }); } +// ★ 第58批续29-问题3:添加 closeModal 函数(admin.php 原本缺少) +function closeModal() { + document.querySelectorAll('[data-modal-overlay]').forEach(el => el.remove()); +} + // ===== 自定义背景系统(第46批):纯色 / 图片URL / API壁纸(必应) 三模式 ===== let _wpPendingUrl = null; // 待应用的图片URL(预览/获取后暂存,点应用才生效) diff --git a/api/admin.php b/api/admin.php index 94ff641..2bf993d 100644 --- a/api/admin.php +++ b/api/admin.php @@ -153,8 +153,8 @@ function adminDeduct() { $player = getParam('player'); $amount = (int)getParam('amount', 0); $reason = getParam('reason', '管理员扣减'); - if (!$player) exit(json_encode(['success' => false, 'message' => 'Missing player'], JSON_UNESCAPED_UNICODE)); - if ($amount <= 0) exit(json_encode(['success' => false, 'message' => 'Invalid amount'], JSON_UNESCAPED_UNICODE)); + if (!$player) jsonResponse(['success' => false, 'message' => 'Missing player']); + if ($amount <= 0) jsonResponse(['success' => false, 'message' => 'Invalid amount']); $db = getDB(); $db->exec("CREATE TABLE IF NOT EXISTS bond_cache (player_name TEXT PRIMARY KEY, amount INTEGER DEFAULT 0, updated_at INTEGER DEFAULT 0)"); try { @@ -162,7 +162,7 @@ function adminDeduct() { $stmt->bindValue(':name', $player, SQLITE3_TEXT); $row = $stmt->execute()->fetchArray(SQLITE3_ASSOC); $current = $row ? $row['amount'] : 0; - if ($current < $amount) exit(json_encode(['success' => false, 'message' => "Insufficient: $current"], JSON_UNESCAPED_UNICODE)); + if ($current < $amount) jsonResponse(['success' => false, 'message' => "Insufficient: $current"]); $newAmount = $current - $amount; $stmt = $db->prepare("UPDATE bond_cache SET amount = :amount, updated_at = :time WHERE player_name = :name"); $stmt->bindValue(':amount', $newAmount, SQLITE3_INTEGER); @@ -185,10 +185,10 @@ function adminDeduct() { // ★ 通知Java插件立即拉取 notifyJavaPluginImmediatePull(); - exit(json_encode(['success' => true, 'message' => 'OK', 'remaining' => $newAmount], JSON_UNESCAPED_UNICODE)); + jsonResponse(['success' => true, 'message' => 'OK', 'remaining' => $newAmount]); } catch (Exception $e) { @error_log('[Function] Error: ' . $e->getMessage()); - exit(json_encode(['success' => false, 'message' => 'Internal error'], JSON_UNESCAPED_UNICODE)); + jsonResponse(['success' => false, 'message' => 'Internal error'], 500); } } @@ -197,8 +197,8 @@ function adminAddBonds() { $player = getParam('player'); $amount = (int)getParam('amount', 0); $reason = getParam('reason', '管理员充值'); - if (!$player) exit(json_encode(['success' => false, 'message' => 'Missing player'], JSON_UNESCAPED_UNICODE)); - if ($amount <= 0) exit(json_encode(['success' => false, 'message' => 'Invalid amount'], JSON_UNESCAPED_UNICODE)); + if (!$player) jsonResponse(['success' => false, 'message' => 'Missing player']); + if ($amount <= 0) jsonResponse(['success' => false, 'message' => 'Invalid amount']); $db = getDB(); $db->exec("CREATE TABLE IF NOT EXISTS bond_cache (player_name TEXT PRIMARY KEY, amount INTEGER DEFAULT 0, updated_at INTEGER DEFAULT 0)"); try { @@ -228,10 +228,10 @@ function adminAddBonds() { // ★ 通知Java插件立即拉取 notifyJavaPluginImmediatePull(); - exit(json_encode(['success' => true, 'message' => 'OK', 'new_amount' => $newAmount], JSON_UNESCAPED_UNICODE)); + jsonResponse(['success' => true, 'message' => 'OK', 'new_amount' => $newAmount]); } catch (Exception $e) { @error_log('[Function] Error: ' . $e->getMessage()); - exit(json_encode(['success' => false, 'message' => 'Internal error'], JSON_UNESCAPED_UNICODE)); + jsonResponse(['success' => false, 'message' => 'Internal error'], 500); } }