refactor(js): tempButtonFeedback提升为通用并前置于run_id复制处理
This commit is contained in:
@@ -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(渐进增强)
|
// 批次页:一键复制 run_id(渐进增强)
|
||||||
(function(){
|
(function(){
|
||||||
var btn = qs('[data-action="copy-run-id"][data-run-id]');
|
var btn = qs('[data-action="copy-run-id"][data-run-id]');
|
||||||
if(!btn){return;}
|
if(!btn){return;}
|
||||||
|
|
||||||
function markCopiedRunId(ok){
|
function markCopiedRunId(ok){
|
||||||
try {
|
tempButtonFeedback(btn, ok, 'data-orig-text-run-id');
|
||||||
// 复用通用按钮反馈逻辑
|
|
||||||
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) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btn.addEventListener('click', function(){
|
btn.addEventListener('click', function(){
|
||||||
@@ -646,34 +651,6 @@
|
|||||||
var btns = document.querySelectorAll('[data-action="copy-link"][data-href]');
|
var btns = document.querySelectorAll('[data-action="copy-link"][data-href]');
|
||||||
if(!btns || btns.length === 0){return;}
|
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){
|
btns.forEach(function(btn){
|
||||||
btn.addEventListener('click', function(){
|
btn.addEventListener('click', function(){
|
||||||
var href = btn.getAttribute('data-href') || '';
|
var href = btn.getAttribute('data-href') || '';
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminJsTempButtonFeedbackShouldBeDefinedBeforeCopyRunIdHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_temp_button_feedback_should_be_defined_before_copy_run_id_handler(): void
|
||||||
|
{
|
||||||
|
$js = file_get_contents(public_path('js/admin.js'));
|
||||||
|
$this->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user