合并单元格
This commit is contained in:
@@ -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++;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 把 rowId 实际写进每个单元格
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const rowId = rowIdMap[i];
|
||||
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 (!data[i][j]) data[i][j] = {};
|
||||
data[i][j].rowId = rowId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('每行data数据:', JSON.parse(JSON.stringify(data)))
|
||||
console.log('每行data数据111:', JSON.parse(JSON.stringify(data)))
|
||||
const seenIds = [];
|
||||
|
||||
|
||||
@@ -8658,22 +8675,32 @@ ${header
|
||||
`;
|
||||
})
|
||||
.join('')}
|
||||
${rowData
|
||||
${rowData
|
||||
.map((row, i) => {
|
||||
return `
|
||||
<tr class="table-content-row ${row.rowId && rowIds.includes(row.rowId) ? 'oddColor' : ''}" >
|
||||
<tr class="table-content-row ${row.rowId && rowIds.includes(row.rowId) ? 'oddColor' : ''}">
|
||||
${row
|
||||
.map((cell, cellIndex) => {
|
||||
if (cell && cell.cellId) {
|
||||
return `
|
||||
<td colspan="${cell.colspan || 1}" rowspan="${cell.rowspan || 1}" >
|
||||
<span style="font-family: 'Charis SIL';">${cell.text || ''}</span>
|
||||
</td>
|
||||
`;
|
||||
} else {
|
||||
return ``
|
||||
}
|
||||
.map((cell) => {
|
||||
if (!cell || !cell.cellId) return '';
|
||||
|
||||
const content = cell.text || '';
|
||||
const isBase64Image = /^<img\s+[^>]*src=["']data:image\//i.test(content);
|
||||
|
||||
const finalContent = isBase64Image
|
||||
? content.replace(
|
||||
/<img\s+([^>]*?)src=["'](data:image\/[^"']+)["']([^>]*)>/gi,
|
||||
(match, preAttrs, src, postAttrs) => {
|
||||
const safeSrc = src.replace(/'/g, "\\'");
|
||||
return `<img ${preAttrs}src="${src}"${postAttrs} style="cursor:pointer;" onclick="picPreview('${safeSrc}')" />`;
|
||||
}
|
||||
)
|
||||
: content;
|
||||
|
||||
|
||||
return `
|
||||
<td colspan="${cell.colspan || 1}" rowspan="${cell.rowspan || 1}">
|
||||
<span style="font-family: 'Charis SIL';">${finalContent}</span>
|
||||
</td>`;
|
||||
})
|
||||
.join('')}
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user