From 5a72d89e6f031fc1eca7a7a5962530bdf66046c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 17:31:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(js):=20=E5=A4=8D=E5=88=B6=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E4=B8=8D=E5=86=8Dalert(=E4=BB=85toast+=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E7=9F=AD=E5=8F=8D=E9=A6=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/admin.js | 13 ++++-------- ...dminJsCopySuccessShouldNotUseAlertTest.php | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 tests/Feature/AdminJsCopySuccessShouldNotUseAlertTest.php diff --git a/public/js/admin.js b/public/js/admin.js index 27909b3..33cc9bc 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -637,10 +637,8 @@ var runId = btn.getAttribute('data-run-id') || ''; copyToClipboard(runId).then(function(){ markCopiedRunId(true); - if (toastSuccess('已复制 run_id:' + runId)) { - return; - } - try { window.alert('已复制 run_id:' + runId); } catch (e) {} + // 成功反馈优先 toast;若 toast 不可用也无需 alert(按钮已提供“已复制”短反馈)。 + toastSuccess('已复制 run_id:' + runId); }).catch(function(){ markCopiedRunId(false); if (toastError('复制失败,请手动复制 run_id:' + runId)) { @@ -680,11 +678,8 @@ var abs = absoluteUrl(href); copyToClipboard(abs).then(function(){ markCopied(btn, true); - - if (toastSuccess('已复制' + label + '链接')) { - return; - } - try { window.alert('已复制' + label + '链接'); } catch (e) {} + // 成功反馈优先 toast;若 toast 不可用也无需 alert(按钮已提供“已复制”短反馈)。 + toastSuccess('已复制' + label + '链接'); }).catch(function(){ markCopied(btn, false); if (toastError('复制失败,请手动复制' + label + '链接')) { diff --git a/tests/Feature/AdminJsCopySuccessShouldNotUseAlertTest.php b/tests/Feature/AdminJsCopySuccessShouldNotUseAlertTest.php new file mode 100644 index 0000000..d147da8 --- /dev/null +++ b/tests/Feature/AdminJsCopySuccessShouldNotUseAlertTest.php @@ -0,0 +1,20 @@ +assertIsString($js); + + // 成功路径不应再依赖 alert(用 toast + 按钮短反馈即可) + $this->assertStringNotContainsString("window.alert('已复制", $js); + } +}