Skip to content

Commit fcbabd4

Browse files
pythonHuangclaude
andcommitted
fix: 报表行高调整预览无效/新增空行预览高度极小-渲染引擎应用rows[].height到tr与td(HTML)+Excel行高同步+设计器插入/删除行同步行类型与数据集绑定索引
Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent 247fe07 commit fcbabd4

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎Juggle.Application/Services/Impl/ReportExecutionService.cs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ private static string RenderHtmlCore(JsonElement root, Dictionary<string, DataTa
145145
sb.AppendLine("<table>");
146146
foreach (var rr in materialized)
147147
{
148-
sb.Append("<tr>");
148+
// 应用设计器的行高设置
149+
var rowHeight = GetRowHeight(root, rr.TemplateRow);
150+
sb.Append("<tr");
151+
if (rowHeight > 0) sb.Append($" style='height:{rowHeight}px'");
152+
sb.Append(">");
149153
var used = new HashSet<int>();
150154
for (int ci = 0; ci < maxCols; ci++)
151155
{
@@ -159,6 +163,7 @@ private static string RenderHtmlCore(JsonElement root, Dictionary<string, DataTa
159163
if (rr.DataIndex != null) rowspan = 1; // 数据扩展行不支持跨行合并
160164

161165
var style = hasCell ? "border:1px solid #ccc;" + ReadCellStyle(cell) : "border:1px solid #ccc;";
166+
if (rowHeight > 0) style += $"height:{rowHeight}px;";
162167
if (colspan > 1) sb.Append($"<td colspan='{colspan}' style='{style}'>");
163168
else sb.Append($"<td style='{style}'>");
164169
sb.Append(value);
@@ -368,6 +373,19 @@ private static string FormatNum(double d)
368373
private static int GetColCount(JsonElement root)
369374
=> root.TryGetProperty("cols", out var colsEl) && colsEl.ValueKind == JsonValueKind.Array ? colsEl.GetArrayLength() : 0;
370375

376+
/// <summary>读取模板行的行高(px),无设置为 0。</summary>
377+
private static int GetRowHeight(JsonElement root, int rowIndex)
378+
{
379+
if (root.TryGetProperty("rows", out var rowsEl) && rowsEl.ValueKind == JsonValueKind.Array
380+
&& rowIndex >= 0 && rowIndex < rowsEl.GetArrayLength())
381+
{
382+
var rowEl = rowsEl[rowIndex];
383+
if (rowEl.TryGetProperty("height", out var he) && he.ValueKind == JsonValueKind.Number)
384+
return Math.Max(0, he.GetInt32());
385+
}
386+
return 0;
387+
}
388+
371389
private static int GetInt(JsonElement el, string prop, int def)
372390
=> el.TryGetProperty(prop, out var v) ? Math.Max(1, v.GetInt32()) : def;
373391

@@ -418,6 +436,9 @@ private static byte[] ExportExcelCore(JsonElement root, Dictionary<string, DataT
418436
int outRow = 0;
419437
foreach (var rr in materialized)
420438
{
439+
// 应用设计器的行高设置
440+
var rowHeight = GetRowHeight(root, rr.TemplateRow);
441+
if (rowHeight > 0) ws.Row(outRow + 1).Height = rowHeight;
421442
var used = new HashSet<int>();
422443
for (int ci = 0; ci < maxCols; ci++)
423444
{

‎JuggleNet6.Frontend/src/views/report/ReportDesigner.vue‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,14 @@ function insertRow(dir: number) {
823823
}
824824
cells.value = newCells
825825
rowHeights.value.splice(r, 0, 25)
826+
rowTypes.value.splice(r, 0, 'header')
827+
// 数据集绑定按新行号重映射
828+
const newDs: Record<number, string> = {}
829+
for (const [k, v] of Object.entries(rowDatasets.value)) {
830+
const idx = Number(k)
831+
newDs[idx >= r ? idx + 1 : idx] = v
832+
}
833+
rowDatasets.value = newDs
826834
maxRows.value++
827835
if (dir > 0) selR.value++
828836
}
@@ -840,6 +848,15 @@ function deleteRow() {
840848
}
841849
cells.value = newCells
842850
rowHeights.value.splice(r, 1)
851+
rowTypes.value.splice(r, 1)
852+
// 数据集绑定按新行号重映射
853+
const newDs: Record<number, string> = {}
854+
for (const [k, v] of Object.entries(rowDatasets.value)) {
855+
const idx = Number(k)
856+
if (idx > r) newDs[idx - 1] = v
857+
else if (idx < r) newDs[idx] = v
858+
}
859+
rowDatasets.value = newDs
843860
maxRows.value--
844861
selR.value = Math.min(selR.value, maxRows.value - 1)
845862
}

0 commit comments

Comments
 (0)