From 78b009aef97b053c88796635ef40a0315b6cbefc Mon Sep 17 00:00:00 2001 From: chenxi Date: Thu, 29 Oct 2026 17:33:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=86=BB=E7=BB=93=E4=BA=BA=E5=B7=A5?= =?UTF-8?q?=E8=B4=B9=E7=94=A8=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E5=AD=90=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../labor-expenses.blade.php | 37 ++++++++++++++++++- .../Business/LaborExpensePageAccessTest.php | 12 ++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/resources/views/business/pages/financial-operations/labor-expenses.blade.php b/resources/views/business/pages/financial-operations/labor-expenses.blade.php index 87ba5e39..22ab7f3d 100644 --- a/resources/views/business/pages/financial-operations/labor-expenses.blade.php +++ b/resources/views/business/pages/financial-operations/labor-expenses.blade.php @@ -550,7 +550,7 @@ data-labor-column="{{ $field['key'] }}" data-labor-header="{{ $field['key'] }}" data-labor-group="{{ $field['group'] }}" - @if (in_array($field['key'], ['A', 'B', 'C'], true)) data-finance-fixed="true" @endif + @if (in_array($field['key'], ['A', 'B', 'C', 'D', 'E'], true)) data-finance-fixed="true" @endif @if (!empty($field['formula'])) title="公式:{{ $field['formula'] }}" @endif >{{ $field['label'] }} @endforeach @@ -586,6 +586,7 @@ const fields = @json($laborFields); const fieldMap = Object.fromEntries(fields.map((field) => [field.key, field])); + const fixedStartColumns = ['A', 'B', 'C', 'D', 'E']; const table = root.querySelector('[data-labor-expense-table]'); const tbody = root.querySelector('[data-labor-rows]'); const formulaFields = fields.filter((field) => field.formula); @@ -840,11 +841,37 @@ return ordered; }; + const updateFixedColumnOffsets = () => { + const leafHeader = table.tHead?.rows?.[table.tHead.rows.length - 1]; + if (!leafHeader) return; + + let left = 0; + const positions = new Map(); + fixedStartColumns.forEach((key) => { + const header = [...leafHeader.cells].find( + (cell) => cell.dataset.laborColumn === key + ); + if (!header) return; + positions.set(key, left); + left += header.getBoundingClientRect().width; + }); + + table.querySelectorAll('thead th[data-labor-group="base"]').forEach((cell) => { + cell.style.left = '0px'; + }); + table.querySelectorAll( + 'thead [data-labor-column], tbody [data-labor-column]' + ).forEach((cell) => { + const position = positions.get(cell.dataset.laborColumn); + if (Number.isFinite(position)) cell.style.left = `${position}px`; + }); + }; + const cellFor = (field, index) => { const cell = document.createElement('td'); cell.dataset.financeColumnKey = field.key; cell.dataset.laborColumn = field.key; - if (['A', 'B', 'C'].includes(field.key)) cell.dataset.financeFixed = 'true'; + if (fixedStartColumns.includes(field.key)) cell.dataset.financeFixed = 'true'; const header = table.querySelector(`thead th[data-finance-column-key="${field.key}"]`); if (header?.classList.contains('is-column-hidden')) cell.classList.add('is-column-hidden'); @@ -970,6 +997,8 @@ } [...tbody.querySelectorAll('tr[data-labor-row]')].forEach((rowElement, index) => updateOutputs(rowElement, index)); updateSummary(); + updateFixedColumnOffsets(); + window.requestAnimationFrame(updateFixedColumnOffsets); }; const sumCalculated = (key) => { @@ -1092,6 +1121,10 @@ } }); + window.addEventListener('resize', () => { + window.requestAnimationFrame(updateFixedColumnOffsets); + }); + renderRows(); })(); diff --git a/tests/Feature/Business/LaborExpensePageAccessTest.php b/tests/Feature/Business/LaborExpensePageAccessTest.php index a6a337cc..37aa6904 100644 --- a/tests/Feature/Business/LaborExpensePageAccessTest.php +++ b/tests/Feature/Business/LaborExpensePageAccessTest.php @@ -130,6 +130,18 @@ class LaborExpensePageAccessTest extends FeatureTestCase '/]*data-labor-action-group[^>]*data-finance-fixed="end"[^>]*>/s', $html ); + foreach (['A', 'B', 'C', 'D', 'E'] as $column) { + $this->assertMatchesRegularExpression( + '/]*data-labor-column="' . + $column . + '"[^>]*data-finance-fixed="true"[^>]*>/s', + $html + ); + } + $this->assertStringContainsString( + "const fixedStartColumns = ['A', 'B', 'C', 'D', 'E'];", + $html + ); foreach ([ 'B' => 'base', 'J' => 'original', -- 2.47.2