feat(js): 复制run_id按钮增加短暂反馈并自动恢复
This commit is contained in:
@@ -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) {}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminJsCopyRunIdButtonShouldHaveTemporaryFeedbackLogicTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_admin_js_should_include_temporary_feedback_for_copy_run_id_button(): void
|
||||
{
|
||||
$js = file_get_contents(public_path('js/admin.js'));
|
||||
|
||||
$this->assertIsString($js);
|
||||
|
||||
$this->assertStringContainsString('data-orig-text-run-id', $js);
|
||||
$this->assertStringContainsString("'已复制'", $js);
|
||||
$this->assertStringContainsString("'复制失败'", $js);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user