feat(batch): 复制治理链接补齐label并复制绝对URL
This commit is contained in:
@@ -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原因)
|
// 批次页:一键复制治理集合链接(例如:本批次失败 / 按Top原因)
|
||||||
(function(){
|
(function(){
|
||||||
var btns = document.querySelectorAll('[data-action="copy-link"][data-href]');
|
var btns = document.querySelectorAll('[data-action="copy-link"][data-href]');
|
||||||
@@ -602,13 +618,16 @@
|
|||||||
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') || '';
|
||||||
copyToClipboard(href).then(function(){
|
var label = btn.getAttribute('data-label') || '链接';
|
||||||
if (toastSuccess('已复制链接')) {
|
|
||||||
|
var abs = absoluteUrl(href);
|
||||||
|
copyToClipboard(abs).then(function(){
|
||||||
|
if (toastSuccess('已复制' + label + '链接')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try { window.alert('已复制链接'); } catch (e) {}
|
try { window.alert('已复制' + label + '链接'); } catch (e) {}
|
||||||
}).catch(function(){
|
}).catch(function(){
|
||||||
try { window.alert('复制失败,请手动复制链接'); } catch (e) {}
|
try { window.alert('复制失败,请手动复制' + label + '链接'); } catch (e) {}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -124,12 +124,12 @@
|
|||||||
@if(($governanceLinks['failed'] ?? '') !== '')
|
@if(($governanceLinks['failed'] ?? '') !== '')
|
||||||
<span class="muted">|</span>
|
<span class="muted">|</span>
|
||||||
<a class="link" href="{{ $governanceLinks['failed'] }}">本批次失败</a>
|
<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
|
@endif
|
||||||
@if(($governanceLinks['top_reason'] ?? '') !== '')
|
@if(($governanceLinks['top_reason'] ?? '') !== '')
|
||||||
<span class="muted">|</span>
|
<span class="muted">|</span>
|
||||||
<a class="link" href="{{ $governanceLinks['top_reason'] }}">按Top原因</a>
|
<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
|
@endif
|
||||||
@if(($governanceLinks['retry_syncable'] ?? '') !== '')
|
@if(($governanceLinks['retry_syncable'] ?? '') !== '')
|
||||||
<span class="muted">|</span>
|
<span class="muted">|</span>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user