diff --git a/js/article.js b/js/article.js index a41f32f..39b2f79 100644 --- a/js/article.js +++ b/js/article.js @@ -8544,24 +8544,41 @@ function shouldColor(rowIndex, cellIndex, row) { function addRowIdToData(content) { console.log('每行data数据1', content) var data = JSON.parse(JSON.stringify(content)) - let idCounter = 0; // Initialize an ID counter + const rowIdMap = {}; + const usedRows = new Set(); + let idCounter = 0; + for (let i = 0; i < data.length; i++) { - data[i].rowId = `row-${idCounter}`; - idCounter++; - for (let j = 0; j < data[i].length; j++) { - const cell = data[i][j]; - if (cell && cell.text && cell.rowspan && cell.rowspan > 1) { - for (let k = 0; k < cell.rowspan; k++) { - if (data[i + k]) { - - data[i + k][j] = { ...data[i + k][j], rowId: `row-${idCounter - 1}` }; - - } - } + if (usedRows.has(i)) continue; + + const rowId = `row-${idCounter++}`; + rowIdMap[i] = rowId; + usedRows.add(i); + + const row = data[i]; + for (let j = 0; j < row.length; j++) { + const cell = row[j]; + if (cell?.rowspan && cell.rowspan > 1) { + for (let k = 1; k < cell.rowspan; k++) { + const nextRowIndex = i + k; + if (nextRowIndex < data.length && !rowIdMap[nextRowIndex]) { + rowIdMap[nextRowIndex] = rowId; + usedRows.add(nextRowIndex); } + } } + } } - console.log('每行data数据:', JSON.parse(JSON.stringify(data))) + + // 把 rowId 实际写进每个单元格 + for (let i = 0; i < data.length; i++) { + const rowId = rowIdMap[i]; + for (let j = 0; j < data[i].length; j++) { + if (!data[i][j]) data[i][j] = {}; + data[i][j].rowId = rowId; + } + } + console.log('每行data数据111:', JSON.parse(JSON.stringify(data))) const seenIds = []; @@ -8658,25 +8675,35 @@ ${header `; }) .join('')} -${rowData + ${rowData .map((row, i) => { return ` - - ${row - .map((cell, cellIndex) => { - if (cell && cell.cellId) { - return ` - - ${cell.text || ''} - - `; - } else { - return `` - } + + ${row + .map((cell) => { + if (!cell || !cell.cellId) return ''; + const content = cell.text || ''; + const isBase64Image = /^]*src=["']data:image\//i.test(content); + + const finalContent = isBase64Image + ? content.replace( + /]*?)src=["'](data:image\/[^"']+)["']([^>]*)>/gi, + (match, preAttrs, src, postAttrs) => { + const safeSrc = src.replace(/'/g, "\\'"); + return ``; + } + ) + : content; + + + return ` + + ${finalContent} + `; }) - .join('')} - + .join('')} + `; }) .join('')}