From c245d872ca3cb9871b2375d82b33d01119ac2bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 17:37:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(js):=20=E5=A4=8D=E5=88=B6=E6=88=90?= =?UTF-8?q?=E5=8A=9Ftoast=E6=96=87=E6=A1=88=E6=94=B6=E6=95=9B=E4=B8=BAtoas?= =?UTF-8?q?tCopied=E7=BB=9F=E4=B8=80=E5=8F=A3=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/admin.js | 18 +++++++++++++++-- ...dminJsToastCopiedHelperShouldExistTest.php | 20 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/AdminJsToastCopiedHelperShouldExistTest.php diff --git a/public/js/admin.js b/public/js/admin.js index 33cc9bc..9ccaa19 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -594,6 +594,20 @@ return toast('error', text, 9000); } + // 复制反馈文案统一口径(更像后台系统的短反馈,不塞超长 URL) + function toastCopied(label, detail) { + var l = String(label || '').trim(); + var d = String(detail || '').trim(); + var msg = '已复制'; + if (l) { + msg += l; + } + if (d) { + msg += ':' + d; + } + return toastSuccess(msg); + } + // 通用:按钮短暂反馈(已复制/复制失败)并自动恢复 // 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。 function tempButtonFeedback(btn, ok, origAttr) { @@ -638,7 +652,7 @@ copyToClipboard(runId).then(function(){ markCopiedRunId(true); // 成功反馈优先 toast;若 toast 不可用也无需 alert(按钮已提供“已复制”短反馈)。 - toastSuccess('已复制 run_id:' + runId); + toastCopied('run_id', runId); }).catch(function(){ markCopiedRunId(false); if (toastError('复制失败,请手动复制 run_id:' + runId)) { @@ -679,7 +693,7 @@ copyToClipboard(abs).then(function(){ markCopied(btn, true); // 成功反馈优先 toast;若 toast 不可用也无需 alert(按钮已提供“已复制”短反馈)。 - toastSuccess('已复制' + label + '链接'); + toastCopied(label + '链接', ''); }).catch(function(){ markCopied(btn, false); if (toastError('复制失败,请手动复制' + label + '链接')) { diff --git a/tests/Feature/AdminJsToastCopiedHelperShouldExistTest.php b/tests/Feature/AdminJsToastCopiedHelperShouldExistTest.php new file mode 100644 index 0000000..2ec313e --- /dev/null +++ b/tests/Feature/AdminJsToastCopiedHelperShouldExistTest.php @@ -0,0 +1,20 @@ +assertIsString($js); + + $this->assertStringContainsString('function toastCopied', $js); + $this->assertStringContainsString("msg = '已复制'", $js); + } +}