From c1a2b091f2aaad16e4acf3e48d10dd14ac9158d7 Mon Sep 17 00:00:00 2001 From: Nurs Date: Thu, 17 Sep 2026 03:42:55 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BC=D1=83=D1=82=D0=B0=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20-=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D1=8C=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D1=8E?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=BA=D0=BE=D0=BF=D0=B8=D0=B8=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- excel-editor.js | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/excel-editor.js b/excel-editor.js index 9bc2d2a..ce47050 100644 --- a/excel-editor.js +++ b/excel-editor.js @@ -202,22 +202,25 @@ function processMapping() { } }); - // Сопоставляем данные + // Сопоставляем данные (без мутации!) let matched = 0; let notMatched = 0; let filled = 0; const previewRows = templateData.slice(0, 10).map((templateRow, index) => { + // Создаём КОПИЮ строки, чтобы не мутировать исходные данные + const rowCopy = { ...templateRow }; const keyValue = normalizeValue(templateRow[templateKeyField]); const mainRow = mainMap.get(keyValue); if (mainRow) { matched++; - // Заполняем пустые поля + // Заполняем пустые поля в копии fieldsToFill.forEach(field => { - if (!templateRow[field] && mainRow[field]) { + const isEmpty = rowCopy[field] === null || rowCopy[field] === undefined || rowCopy[field] === ''; + if (isEmpty && mainRow[field] !== null && mainRow[field] !== undefined) { filled++; - templateRow[field] = mainRow[field]; + rowCopy[field] = mainRow[field]; } }); } else { @@ -225,7 +228,8 @@ function processMapping() { } return { - templateRow, + templateRow: rowCopy, + originalRow: templateRow, mainRow, matched: !!mainRow }; @@ -268,10 +272,12 @@ function processMapping() { previewRows.forEach(row => { bodyHtml += ''; allFields.forEach(field => { - const value = row.templateRow[field] !== undefined ? row.templateRow[field] : ''; - const fromMain = row.mainRow && row.mainRow[field] && !row.templateRow[field]; - const cellStyle = fromMain ? 'background: var(--kt-ai-success-bg); font-weight: 600;' : ''; - bodyHtml += '' + escapeHtml(value) + ''; + const originalValue = row.originalRow[field]; + const newValue = row.templateRow[field]; + const wasEmpty = originalValue === null || originalValue === undefined || String(originalValue).trim() === ''; + const filled = wasEmpty && newValue !== null && newValue !== undefined; + const cellStyle = filled ? 'background: var(--kt-ai-success-bg); font-weight: 600;' : ''; + bodyHtml += '' + escapeHtml(newValue !== null && newValue !== undefined ? newValue : '') + ''; }); bodyHtml += '' + (row.matched ? '✓' : '✗') + ''; }); @@ -290,21 +296,27 @@ function processFiles() { const { templateData, fieldsToFill, mainMap, templateKeyField } = mappedResult; - // Полная обработка всех данных + // Полная обработка всех данных (без мутации!) let totalFilled = 0; const resultData = templateData.map(row => { + // Создаём КОПИЮ строки + const newRow = { ...row }; const keyValue = normalizeValue(row[templateKeyField]); const mainRow = mainMap.get(keyValue); if (mainRow) { fieldsToFill.forEach(field => { - if (!row[field] && mainRow[field]) { - row[field] = mainRow[field]; + // Проверяем на пустое значение (null, undefined, пустая строка) + const isEmpty = newRow[field] === null || newRow[field] === undefined || String(newRow[field]).trim() === ''; + const hasValueInMain = mainRow[field] !== null && mainRow[field] !== undefined; + + if (isEmpty && hasValueInMain) { + newRow[field] = mainRow[field]; totalFilled++; } }); } - return row; + return newRow; }); // Создаём Excel файл