feat(batch): 复制治理链接补齐label并复制绝对URL

This commit is contained in:
萝卜
2026-03-17 16:55:34 +08:00
parent d219712567
commit da085a239f
3 changed files with 61 additions and 6 deletions

View File

@@ -594,6 +594,22 @@
});
})();
function absoluteUrl(href) {
var h = String(href || '');
if (!h) {
return '';
}
// 已是绝对链接
if (h.indexOf('http://') === 0 || h.indexOf('https://') === 0) {
return h;
}
// 仅将站内相对路径补齐为绝对链接
if (h.indexOf('/') === 0 && window.location && window.location.origin) {
return String(window.location.origin) + h;
}
return h;
}
// 批次页:一键复制治理集合链接(例如:本批次失败 / 按Top原因
(function(){
var btns = document.querySelectorAll('[data-action="copy-link"][data-href]');
@@ -602,13 +618,16 @@
btns.forEach(function(btn){
btn.addEventListener('click', function(){
var href = btn.getAttribute('data-href') || '';
copyToClipboard(href).then(function(){
if (toastSuccess('已复制链接')) {
var label = btn.getAttribute('data-label') || '链接';
var abs = absoluteUrl(href);
copyToClipboard(abs).then(function(){
if (toastSuccess('已复制' + label + '链接')) {
return;
}
try { window.alert('已复制链接'); } catch (e) {}
try { window.alert('已复制' + label + '链接'); } catch (e) {}
}).catch(function(){
try { window.alert('复制失败,请手动复制链接'); } catch (e) {}
try { window.alert('复制失败,请手动复制' + label + '链接'); } catch (e) {}
});
});
});

View File

@@ -124,12 +124,12 @@
@if(($governanceLinks['failed'] ?? '') !== '')
<span class="muted"></span>
<a class="link" href="{{ $governanceLinks['failed'] }}">本批次失败</a>
<button type="button" class="btn btn-secondary btn-xs" data-action="copy-link" data-role="copy-failed-link" data-href="{{ $governanceLinks['failed'] }}">复制链接</button>
<button type="button" class="btn btn-secondary btn-xs" data-action="copy-link" data-role="copy-failed-link" data-label="本批次失败" data-href="{{ $governanceLinks['failed'] }}">复制链接</button>
@endif
@if(($governanceLinks['top_reason'] ?? '') !== '')
<span class="muted"></span>
<a class="link" href="{{ $governanceLinks['top_reason'] }}">按Top原因</a>
<button type="button" class="btn btn-secondary btn-xs" data-action="copy-link" data-role="copy-top-reason-link" data-href="{{ $governanceLinks['top_reason'] }}">复制链接</button>
<button type="button" class="btn btn-secondary btn-xs" data-action="copy-link" data-role="copy-top-reason-link" data-label="按Top原因" data-href="{{ $governanceLinks['top_reason'] }}">复制链接</button>
@endif
@if(($governanceLinks['retry_syncable'] ?? '') !== '')
<span class="muted"></span>

View File

@@ -0,0 +1,36 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformBatchShowPageCopyLinkButtonsShouldIncludeLabelsTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_batch_show_page_copy_link_buttons_should_include_data_label(): void
{
$this->loginAsPlatformAdmin();
$runId = 'BAS_COPY_LABEL_0001';
$html = $this->get('/admin/platform-batches/show?type=bas&run_id=' . $runId)
->assertOk()
->getContent();
// 至少校验“本批次失败”的复制按钮携带 label
$this->assertStringContainsString('data-role="copy-failed-link"', $html);
$this->assertStringContainsString('data-label="本批次失败"', $html);
}
}