From da085a239f982e0d1db25d8bff4ebdaaa5f03620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 16:55:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(batch):=20=E5=A4=8D=E5=88=B6=E6=B2=BB?= =?UTF-8?q?=E7=90=86=E9=93=BE=E6=8E=A5=E8=A1=A5=E9=BD=90label=E5=B9=B6?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E7=BB=9D=E5=AF=B9URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/admin.js | 27 +++++++++++--- .../admin/platform_batches/show.blade.php | 4 +-- ...CopyLinkButtonsShouldIncludeLabelsTest.php | 36 +++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 tests/Feature/AdminPlatformBatchShowPageCopyLinkButtonsShouldIncludeLabelsTest.php diff --git a/public/js/admin.js b/public/js/admin.js index 9642fac..3228712 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -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) {} }); }); }); diff --git a/resources/views/admin/platform_batches/show.blade.php b/resources/views/admin/platform_batches/show.blade.php index 4ba2e6d..4106cde 100644 --- a/resources/views/admin/platform_batches/show.blade.php +++ b/resources/views/admin/platform_batches/show.blade.php @@ -124,12 +124,12 @@ @if(($governanceLinks['failed'] ?? '') !== '') 本批次失败 - + @endif @if(($governanceLinks['top_reason'] ?? '') !== '') 按Top原因 - + @endif @if(($governanceLinks['retry_syncable'] ?? '') !== '') diff --git a/tests/Feature/AdminPlatformBatchShowPageCopyLinkButtonsShouldIncludeLabelsTest.php b/tests/Feature/AdminPlatformBatchShowPageCopyLinkButtonsShouldIncludeLabelsTest.php new file mode 100644 index 0000000..7468c1d --- /dev/null +++ b/tests/Feature/AdminPlatformBatchShowPageCopyLinkButtonsShouldIncludeLabelsTest.php @@ -0,0 +1,36 @@ +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); + } +}