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); + } +}