diff --git a/public/js/admin.js b/public/js/admin.js index 9ccaa19..89fec19 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -608,6 +608,19 @@ return toastSuccess(msg); } + function toastCopyFailed(label, detail) { + var l = String(label || '').trim(); + var d = String(detail || '').trim(); + var msg = '复制失败'; + if (l) { + msg += '(' + l + ')'; + } + if (d) { + msg += ':' + d; + } + return toastError(msg); + } + // 通用:按钮短暂反馈(已复制/复制失败)并自动恢复 // 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。 function tempButtonFeedback(btn, ok, origAttr) { @@ -655,7 +668,7 @@ toastCopied('run_id', runId); }).catch(function(){ markCopiedRunId(false); - if (toastError('复制失败,请手动复制 run_id:' + runId)) { + if (toastCopyFailed('run_id', '请手动复制:' + runId)) { return; } try { window.alert('复制失败,请手动复制 run_id:' + runId); } catch (e) {} @@ -696,7 +709,7 @@ toastCopied(label + '链接', ''); }).catch(function(){ markCopied(btn, false); - if (toastError('复制失败,请手动复制' + label + '链接')) { + if (toastCopyFailed(label + '链接', '请手动复制')) { return; } try { window.alert('复制失败,请手动复制' + label + '链接'); } catch (e) {} diff --git a/tests/Feature/AdminJsCopyFailuresShouldUseToastErrorFirstTest.php b/tests/Feature/AdminJsCopyFailuresShouldUseToastErrorFirstTest.php index 6a13389..7bd1a91 100644 --- a/tests/Feature/AdminJsCopyFailuresShouldUseToastErrorFirstTest.php +++ b/tests/Feature/AdminJsCopyFailuresShouldUseToastErrorFirstTest.php @@ -15,6 +15,10 @@ class AdminJsCopyFailuresShouldUseToastErrorFirstTest extends TestCase $this->assertIsString($js); // 复制失败时应优先 toastError(alert 作为降级) - $this->assertStringContainsString("toastError('复制失败", $js); + // 允许通过 wrapper(toastCopyFailed)间接调用 toastError。 + $this->assertTrue( + str_contains($js, "toastError('复制失败") || str_contains($js, 'toastCopyFailed('), + 'copy failures should use toastError (directly or via toastCopyFailed wrapper)' + ); } } diff --git a/tests/Feature/AdminJsToastCopyFailedHelperShouldExistTest.php b/tests/Feature/AdminJsToastCopyFailedHelperShouldExistTest.php new file mode 100644 index 0000000..fcd8a87 --- /dev/null +++ b/tests/Feature/AdminJsToastCopyFailedHelperShouldExistTest.php @@ -0,0 +1,21 @@ +assertIsString($js); + + $this->assertStringContainsString('function toastCopyFailed', $js); + $this->assertStringContainsString("msg = '复制失败'", $js); + $this->assertStringContainsString("return toastError(msg)", $js); + } +}