From e93fda474bd706791acdbee276cfd6744290070f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 17:17:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor(js):=20=E6=8F=90=E7=82=BCtoast?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E5=87=BD=E6=95=B0=E5=B9=B6=E4=BF=9D=E7=95=99?= =?UTF-8?q?toastSuccess=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/admin.js | 15 +++++++++++--- .../AdminJsToastHelperShouldExistTest.php | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/AdminJsToastHelperShouldExistTest.php diff --git a/public/js/admin.js b/public/js/admin.js index 9c3926c..e748ade 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -546,7 +546,7 @@ }); } - function toastSuccess(text) { + function toast(type, text, ttlMs) { try { var container = qs('[data-role="toast-container"]'); if (!container) { @@ -554,7 +554,7 @@ } var t = document.createElement('div'); - t.className = 'toast toast-success'; + t.className = 'toast toast-' + String(type || 'info'); t.setAttribute('role', 'status'); var c = document.createElement('div'); @@ -564,11 +564,16 @@ t.appendChild(c); container.appendChild(t); + var ttl = Number(ttlMs || 2500); + if (!isFinite(ttl) || ttl <= 0) { + ttl = 2500; + } + setTimeout(function () { try { container.removeChild(t); } catch (e) {} - }, 2500); + }, ttl); return true; } catch (e) { @@ -576,6 +581,10 @@ } } + function toastSuccess(text) { + return toast('success', text, 2500); + } + // 通用:按钮短暂反馈(已复制/复制失败)并自动恢复 // 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。 function tempButtonFeedback(btn, ok, origAttr) { diff --git a/tests/Feature/AdminJsToastHelperShouldExistTest.php b/tests/Feature/AdminJsToastHelperShouldExistTest.php new file mode 100644 index 0000000..730b68f --- /dev/null +++ b/tests/Feature/AdminJsToastHelperShouldExistTest.php @@ -0,0 +1,20 @@ +assertIsString($js); + $this->assertStringContainsString('function toast(', $js); + $this->assertStringContainsString("toast('success'", $js); + } +}