diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index d959c9a..44d6272 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1638,7 +1638,9 @@ class PlatformOrderController extends Controller if ($existing !== '' && str_starts_with($existing, 'BAS')) { $res = $res ->with('warning_link_href', '/admin/platform-batches/show?type=bas&run_id=' . urlencode($existing)) - ->with('warning_link_label', '进入上次批次复盘'); + ->with('warning_link_label', '进入上次批次复盘') + ->with('warning_copy_text', $existing) + ->with('warning_copy_label', '复制run_id'); } return $res; @@ -1789,7 +1791,9 @@ class PlatformOrderController extends Controller if ($existing !== '' && str_starts_with($existing, 'BMPA')) { $res = $res ->with('warning_link_href', '/admin/platform-batches/show?type=bmpa&run_id=' . urlencode($existing)) - ->with('warning_link_label', '进入上次批次复盘'); + ->with('warning_link_label', '进入上次批次复盘') + ->with('warning_copy_text', $existing) + ->with('warning_copy_label', '复制run_id'); } return $res; diff --git a/public/js/admin.js b/public/js/admin.js index 89fec19..4091927 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -718,6 +718,30 @@ }); })(); + // 通用:复制任意文本(用于 flash 提示中的“复制run_id”等) + (function(){ + var btns = document.querySelectorAll('[data-action="copy-text"][data-copy-text]'); + if(!btns || btns.length === 0){return;} + + btns.forEach(function(btn){ + btn.addEventListener('click', function(){ + var text = btn.getAttribute('data-copy-text') || ''; + var label = btn.getAttribute('data-copy-label') || '文本'; + + copyToClipboard(text).then(function(){ + markCopied(btn, true); + toastCopied(label, text); + }).catch(function(){ + markCopied(btn, false); + if (toastCopyFailed(label, '请手动复制:' + text)) { + return; + } + try { window.alert('复制失败,请手动复制:' + text); } catch (e) {} + }); + }); + }); + })(); + // 续费缺订阅治理:订单详情页“绑定订阅ID”输入框,小交互增强: // - 输入后按 Enter 直接提交 // - 自动聚焦,减少点击 diff --git a/resources/views/admin/layouts/app.blade.php b/resources/views/admin/layouts/app.blade.php index 52be026..4818ed1 100644 --- a/resources/views/admin/layouts/app.blade.php +++ b/resources/views/admin/layouts/app.blade.php @@ -97,10 +97,15 @@ @php $flashWarningLinkHref = \App\Support\BackUrl::sanitizeForLinks((string) session('warning_link_href')); $flashWarningLinkLabel = (string) (session('warning_link_label') ?: '查看'); + $flashWarningCopyText = (string) (session('warning_copy_text') ?: ''); + $flashWarningCopyLabel = (string) (session('warning_copy_label') ?: '复制'); @endphp @if($flashWarningLinkHref !== '') {{ $flashWarningLinkLabel }} @endif + @if($flashWarningCopyText !== '') + + @endif @endif @endif diff --git a/tests/Feature/AdminFlashWarningShouldSupportCopyTextButtonTest.php b/tests/Feature/AdminFlashWarningShouldSupportCopyTextButtonTest.php new file mode 100644 index 0000000..1929b0c --- /dev/null +++ b/tests/Feature/AdminFlashWarningShouldSupportCopyTextButtonTest.php @@ -0,0 +1,39 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_flash_warning_should_render_copy_text_button_when_session_keys_present(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->withSession([ + 'warning' => '重复提交', + 'warning_link_href' => '/admin/platform-batches/show?type=bas&run_id=BAS202603171234560001', + 'warning_link_label' => '进入上次批次复盘', + 'warning_copy_text' => 'BAS202603171234560001', + 'warning_copy_label' => '复制run_id', + ])->get('/admin'); + + $res->assertOk(); + $res->assertSee('复制run_id'); + $res->assertSee('data-action="copy-text"', false); + $res->assertSee('data-copy-text="BAS202603171234560001"', false); + } +}