diff --git a/resources/views/business/pages/refunds/non-jingxi-refund-data.blade.php b/resources/views/business/pages/refunds/non-jingxi-refund-data.blade.php index bef557ce..c538a7c9 100644 --- a/resources/views/business/pages/refunds/non-jingxi-refund-data.blade.php +++ b/resources/views/business/pages/refunds/non-jingxi-refund-data.blade.php @@ -301,6 +301,42 @@ text-align: left; white-space: nowrap; } + .refund-summary-detail__table td.is-copyable { + position: relative; + padding-right: 3.3rem; + cursor: copy; + transition: background 120ms ease, box-shadow 120ms ease; + } + .refund-summary-detail__table td.is-copyable:hover, + .refund-summary-detail__table td.is-copyable:focus-visible { + background: #fffaf0; + box-shadow: inset 0 0 0 1px var(--vip-content-accent, #b9954f); + outline: none; + } + .refund-summary-detail__table td.is-copyable::after { + position: absolute; + top: 50%; + right: 0.35rem; + padding: 0.1rem 0.3rem; + border-radius: 4px; + background: var(--vip-content-accent-dark, #856632); + color: var(--vip-surface, #ffffff); + content: "复制"; + font-size: 0.625rem; + line-height: 1.35; + opacity: 0; + pointer-events: none; + transform: translateY(-50%); + transition: opacity 120ms ease; + } + .refund-summary-detail__table td.is-copyable:hover::after, + .refund-summary-detail__table td.is-copyable:focus-visible::after, + .refund-summary-detail__table td.is-copyable[data-copy-state="copied"]::after, + .refund-summary-detail__table td.is-copyable[data-copy-state="failed"]::after { + opacity: 1; + } + .refund-summary-detail__table td.is-copyable[data-copy-state="copied"]::after { content: "已复制"; } + .refund-summary-detail__table td.is-copyable[data-copy-state="failed"]::after { content: "复制失败"; } .refund-summary-detail__table th { position: sticky; top: 0; z-index: 2; background: var(--vip-content-accent-soft, #f7f0de); font-weight: 600; } .refund-summary-detail__table .is-number { text-align: right; font-variant-numeric: tabular-nums; } .refund-summary-detail__pagination { @@ -545,6 +581,45 @@ return `${year}年${Number(monthNumber)}月`; }; const detailLabel = () => `${monthLabel(selected.month)} · ${selected.platform || '全部平台'}`; + const copyStateTimers = new WeakMap(); + const fallbackCopy = (text) => { + const input = document.createElement('textarea'); + input.value = text; + input.setAttribute('readonly', ''); + input.style.position = 'fixed'; + input.style.opacity = '0'; + input.style.pointerEvents = 'none'; + document.body.appendChild(input); + input.select(); + const copied = document.execCommand('copy'); + input.remove(); + if (!copied) throw new Error('copy_failed'); + }; + const copyText = async (text) => { + if (navigator.clipboard && window.isSecureContext) { + await navigator.clipboard.writeText(text); + return; + } + fallbackCopy(text); + }; + const showCopyState = (cell, state) => { + const previousTimer = copyStateTimers.get(cell); + if (previousTimer) window.clearTimeout(previousTimer); + cell.dataset.copyState = state; + copyStateTimers.set(cell, window.setTimeout(() => { + delete cell.dataset.copyState; + copyStateTimers.delete(cell); + }, 1200)); + }; + const copyCell = async (cell) => { + const value = cell.dataset.copyValue ?? cell.textContent.trim(); + try { + await copyText(value); + showCopyState(cell, 'copied'); + } catch (_) { + showCopyState(cell, 'failed'); + } + }; const render = (payload) => { const table = document.createElement('table'); @@ -573,11 +648,17 @@ columns.forEach(([, key, isNumber]) => { const cell = document.createElement('td'); if (isNumber) cell.className = 'is-number'; - cell.textContent = key.includes('amount') || key === 'quantity' + const value = key.includes('amount') || key === 'quantity' ? moneyValue(data[key]) : key === 'refund_date' ? dateValue(data[key]) : textValue(data[key]); + cell.textContent = value; + cell.dataset.copyValue = value; + cell.classList.add('is-copyable'); + cell.tabIndex = 0; + cell.title = '点击复制'; + cell.setAttribute('aria-label', `复制:${value}`); row.appendChild(cell); }); body.appendChild(row); @@ -635,6 +716,18 @@ }); }); + detailScroll.addEventListener('click', (event) => { + const cell = event.target.closest('td.is-copyable'); + if (cell) copyCell(cell); + }); + detailScroll.addEventListener('keydown', (event) => { + if (event.key !== 'Enter' && event.key !== ' ') return; + const cell = event.target.closest('td.is-copyable'); + if (!cell) return; + event.preventDefault(); + copyCell(cell); + }); + root.querySelectorAll('[data-refund-summary-detail-page]').forEach((button) => { button.addEventListener('click', () => { const current = Number(pagination.dataset.currentPage || 1); diff --git a/tests/Feature/Business/NonJingxiRefundPageTest.php b/tests/Feature/Business/NonJingxiRefundPageTest.php index d2bdea94..168605ad 100644 --- a/tests/Feature/Business/NonJingxiRefundPageTest.php +++ b/tests/Feature/Business/NonJingxiRefundPageTest.php @@ -207,6 +207,9 @@ class NonJingxiRefundPageTest extends FeatureTestCase ->assertDontSeeText('5,641 条待确认') ->assertSeeText('导出全部明细') ->assertSee('data-refund-all-export', false) + ->assertSee('is-copyable', false) + ->assertSee('dataset.copyValue', false) + ->assertSee('navigator.clipboard.writeText', false) ->assertSee('from=2026-10-01&to=2026-11-04', false) ->assertDontSee('data-refund-month-export', false) ->assertSee('data-refund-page="pending-confirmation"', false)