合并单元格
This commit is contained in:
@@ -8544,24 +8544,41 @@ function shouldColor(rowIndex, cellIndex, row) {
|
|||||||
function addRowIdToData(content) {
|
function addRowIdToData(content) {
|
||||||
console.log('每行data数据1', content)
|
console.log('每行data数据1', content)
|
||||||
var data = JSON.parse(JSON.stringify(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++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
data[i].rowId = `row-${idCounter}`;
|
if (usedRows.has(i)) continue;
|
||||||
idCounter++;
|
|
||||||
|
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++) {
|
for (let j = 0; j < data[i].length; j++) {
|
||||||
const cell = data[i][j];
|
if (!data[i][j]) data[i][j] = {};
|
||||||
if (cell && cell.text && cell.rowspan && cell.rowspan > 1) {
|
data[i][j].rowId = rowId;
|
||||||
for (let k = 0; k < cell.rowspan; k++) {
|
|
||||||
if (data[i + k]) {
|
|
||||||
|
|
||||||
data[i + k][j] = { ...data[i + k][j], rowId: `row-${idCounter - 1}` };
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
console.log('每行data数据111:', JSON.parse(JSON.stringify(data)))
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log('每行data数据:', JSON.parse(JSON.stringify(data)))
|
|
||||||
const seenIds = [];
|
const seenIds = [];
|
||||||
|
|
||||||
|
|
||||||
@@ -8663,17 +8680,27 @@ ${rowData
|
|||||||
return `
|
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
|
${row
|
||||||
.map((cell, cellIndex) => {
|
.map((cell) => {
|
||||||
if (cell && cell.cellId) {
|
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 `
|
return `
|
||||||
<td colspan="${cell.colspan || 1}" rowspan="${cell.rowspan || 1}">
|
<td colspan="${cell.colspan || 1}" rowspan="${cell.rowspan || 1}">
|
||||||
<span style="font-family: 'Charis SIL';">${cell.text || ''}</span>
|
<span style="font-family: 'Charis SIL';">${finalContent}</span>
|
||||||
</td>
|
</td>`;
|
||||||
`;
|
|
||||||
} else {
|
|
||||||
return ``
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.join('')}
|
.join('')}
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user