diff --git a/public/js/admin.js b/public/js/admin.js index ef89b95..9c3926c 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -576,38 +576,43 @@ } } + // 通用:按钮短暂反馈(已复制/复制失败)并自动恢复 + // 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。 + function tempButtonFeedback(btn, ok, origAttr) { + try { + var key = String(origAttr || 'data-orig-text'); + + var orig = btn.getAttribute(key); + if (!orig) { + orig = String(btn.textContent || ''); + btn.setAttribute(key, orig); + } + + var nextText = ok ? '已复制' : '复制失败'; + btn.textContent = nextText; + btn.disabled = true; + + setTimeout(function(){ + try { + btn.textContent = orig; + btn.disabled = false; + } catch (e) {} + }, 1200); + } catch (e) {} + } + + function markCopied(btn, ok) { + // 兼容:保留函数名,供测试护栏与未来复用 + tempButtonFeedback(btn, ok, 'data-orig-text'); + } + // 批次页:一键复制 run_id(渐进增强) (function(){ var btn = qs('[data-action="copy-run-id"][data-run-id]'); if(!btn){return;} function markCopiedRunId(ok){ - try { - // 复用通用按钮反馈逻辑 - if (typeof tempButtonFeedback === 'function') { - tempButtonFeedback(btn, ok, 'data-orig-text-run-id'); - return; - } - } catch (e) {} - - // 降级:保留旧逻辑(极端情况下 tempButtonFeedback 不可用) - 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) {} + tempButtonFeedback(btn, ok, 'data-orig-text-run-id'); } btn.addEventListener('click', function(){ @@ -646,34 +651,6 @@ var btns = document.querySelectorAll('[data-action="copy-link"][data-href]'); if(!btns || btns.length === 0){return;} - function tempButtonFeedback(btn, ok, origAttr) { - try { - var key = String(origAttr || 'data-orig-text'); - - var orig = btn.getAttribute(key); - if (!orig) { - orig = String(btn.textContent || ''); - btn.setAttribute(key, orig); - } - - var nextText = ok ? '已复制' : '复制失败'; - btn.textContent = nextText; - btn.disabled = true; - - setTimeout(function(){ - try { - btn.textContent = orig; - btn.disabled = false; - } catch (e) {} - }, 1200); - } catch (e) {} - } - - function markCopied(btn, ok) { - // 兼容:保留函数名,供测试护栏与未来复用 - tempButtonFeedback(btn, ok, 'data-orig-text'); - } - btns.forEach(function(btn){ btn.addEventListener('click', function(){ var href = btn.getAttribute('data-href') || ''; diff --git a/tests/Feature/AdminJsTempButtonFeedbackShouldBeDefinedBeforeCopyRunIdHandlerTest.php b/tests/Feature/AdminJsTempButtonFeedbackShouldBeDefinedBeforeCopyRunIdHandlerTest.php new file mode 100644 index 0000000..8bc0a6f --- /dev/null +++ b/tests/Feature/AdminJsTempButtonFeedbackShouldBeDefinedBeforeCopyRunIdHandlerTest.php @@ -0,0 +1,25 @@ +assertIsString($js); + + $posTemp = strpos($js, 'function tempButtonFeedback'); + $posRunId = strpos($js, 'copy-run-id'); + + $this->assertNotFalse($posTemp); + $this->assertNotFalse($posRunId); + + $this->assertTrue($posTemp < $posRunId, 'tempButtonFeedback should be defined before copy-run-id handler'); + } +}