From e955b5a1e0157ce117727b2e0028c8df197c0aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 17:03:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(js):=20=E5=A4=8D=E5=88=B6run=5Fid=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=A2=9E=E5=8A=A0=E7=9F=AD=E6=9A=82=E5=8F=8D=E9=A6=88?= =?UTF-8?q?=E5=B9=B6=E8=87=AA=E5=8A=A8=E6=81=A2=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/admin.js | 22 +++++++++++++++++++ ...onShouldHaveTemporaryFeedbackLogicTest.php | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/Feature/AdminJsCopyRunIdButtonShouldHaveTemporaryFeedbackLogicTest.php diff --git a/public/js/admin.js b/public/js/admin.js index 849c242..72d327d 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -581,14 +581,36 @@ var btn = qs('[data-action="copy-run-id"][data-run-id]'); if(!btn){return;} + function markCopiedRunId(ok){ + try { + var orig = btn.getAttribute('data-orig-text-run-id'); + if (!orig) { + orig = String(btn.textContent || ''); + btn.setAttribute('data-orig-text-run-id', orig); + } + + btn.textContent = ok ? '已复制' : '复制失败'; + btn.disabled = true; + + setTimeout(function(){ + try { + btn.textContent = orig; + btn.disabled = false; + } catch (e) {} + }, 1200); + } catch (e) {} + } + btn.addEventListener('click', function(){ 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) {} }).catch(function(){ + markCopiedRunId(false); try { window.alert('复制失败,请手动复制 run_id:' + runId); } catch (e) {} }); }); diff --git a/tests/Feature/AdminJsCopyRunIdButtonShouldHaveTemporaryFeedbackLogicTest.php b/tests/Feature/AdminJsCopyRunIdButtonShouldHaveTemporaryFeedbackLogicTest.php new file mode 100644 index 0000000..0c6759c --- /dev/null +++ b/tests/Feature/AdminJsCopyRunIdButtonShouldHaveTemporaryFeedbackLogicTest.php @@ -0,0 +1,22 @@ +assertIsString($js); + + $this->assertStringContainsString('data-orig-text-run-id', $js); + $this->assertStringContainsString("'已复制'", $js); + $this->assertStringContainsString("'复制失败'", $js); + } +}