This commit is contained in:
2025-06-04 15:17:35 +08:00
parent acf942d7fb
commit 83e9cbcf14

View File

@@ -8541,55 +8541,46 @@ function shouldColor(rowIndex, cellIndex, row) {
}
return false;
}
function addRowIdToData(data) {
console.log('data at line 8526:', data)
function addRowIdToData(content) {
console.log('每行data数据1', content)
var data = JSON.parse(JSON.stringify(content))
let idCounter = 0; // Initialize an ID counter
// Iterate through each row
for (let i = 0; i < data.length; i++) {
// Assign an ID to the current row
data[i].rowId = `row-${idCounter}`;
idCounter++;
// Check for rowspan and propagate the same ID to merged cells
for (let j = 0; j < data[i].length; j++) {
const cell = data[i][j];
// If the cell has a rowspan attribute, propagate the same ID across all affected rows
if (cell&&cell.text&&cell.rowspan && cell.rowspan > 1) {
if (cell && cell.text && cell.rowspan && cell.rowspan > 1) {
for (let k = 0; k < cell.rowspan; k++) {
if (data[i + k]) {
// Ensure that all cells in the same column and across the rows have the same rowId
data[i + k][j] ={...data[i + k][j],rowId:`row-${idCounter - 1}`} ;
data[i + k][j] = { ...data[i + k][j], rowId: `row-${idCounter - 1}` };
}
}
}
}
}
console.log('每行data数据:', JSON.parse(JSON.stringify(data)))
const seenIds = [];
data.map((row, rowIndex) => {
// row= row.filter(cell => cell.cellId)
row.map((cell, cellIndex) => {
if (cell.rowId) {
row.rowId = cell.rowId
}
})
})
data.forEach(row => {
if (row.rowId && !seenIds.includes(row.rowId)) {
seenIds.push(row.rowId); // Mark this rowId as seen
}
});
console.log('data at line 最新8534:', seenIds, data)
const rowIds = seenIds.filter((_, index) => index % 2 === 0);
const rowData = data;
console.log(rowIds);
const rowData = data
return { rowData, rowIds }
}
@@ -8639,7 +8630,8 @@ function initArticleHtmlFun(arr, result, html_type) {
const { header, content } = splitTable(tableList);
var { rowData, rowIds } = addRowIdToData(content)
console.log('content at line 8641:', content); // 打印深拷贝的内容
var { rowData, rowIds } = addRowIdToData(JSON.parse(JSON.stringify(content)))
console.log('content at line 8542:', rowIds, rowData)
// console.log('contentList at line 8571:', contentList)
@@ -8672,11 +8664,16 @@ ${rowData
<tr class="table-content-row ${row.rowId && rowIds.includes(row.rowId) ? 'oddColor' : ''}" >
${row
.map((cell, cellIndex) => {
return `
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 ``
}
})
.join('')}
</tr>
@@ -9122,32 +9119,33 @@ function initArticleHtml(htmlData, refs, type) {
function isHeaderRow(rowIndex, table) {
console.log('table at line 697:', table)
var head = table[0]
console.log('head at line 699:', head[0].rowspan)
return rowIndex < head[0].rowspan; // 假设前两行是表头
}
function splitTable(tableList) {
// 获取头部行数
const headerRowCount = tableList[0][0].rowspan || 1; // 默认第一行是头部行,获取该行的 rowspan
// 用 isHeaderRow 判断头部行
const header = [];
const content = [];
let cellIdCounter = 0; // 初始化计数器,用于为每个单元格生成唯一的 cellId
tableList.forEach((row, rowIndex) => {
row.forEach((cell, cellIndex) => {
cell.cellId = `cell-${cellIdCounter}`;
cellIdCounter++;
});
if (isHeaderRow(rowIndex, tableList)) {
header.push(row); // 将头部行添加到 header 数组
} else {
content.push(row); // 将内容行添加到 table 数组
}
});
//
console.log('header:', header); // 打印头部行数据
console.log('table:', content); // 打印内容行数据
console.log('table打印内容行数据:', content); // 打印内容行数据
return { header, content };
}