Skip to content

Commit 9ff676f

Browse files
pythonHuangclaude
andcommitted
fix: 报表文字颜色/背景色设置无效-颜色选择器@change未传值导致style.color/bgColor写入undefined,改为读取v-model最新值写入选中单元格(支持清空)+预览补全underline/fontName样式与颜色空值防御(HTML+Excel)
Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent fcbabd4 commit 9ff676f

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,12 @@ private static string ReadCellStyle(JsonElement cell)
397397
{
398398
if (sEl.TryGetProperty("bold", out var b) && b.ValueKind == JsonValueKind.True) style += "font-weight:bold;";
399399
if (sEl.TryGetProperty("italic", out var it) && it.ValueKind == JsonValueKind.True) style += "font-style:italic;";
400-
if (sEl.TryGetProperty("fontSize", out var fs)) style += $"font-size:{fs.GetInt32()}px;";
401-
if (sEl.TryGetProperty("color", out var cl)) style += $"color:{cl.GetString()};";
402-
if (sEl.TryGetProperty("bgColor", out var bg)) style += $"background-color:{bg.GetString()};";
403-
if (sEl.TryGetProperty("align", out var al)) style += $"text-align:{al.GetString()};";
400+
if (sEl.TryGetProperty("underline", out var un) && un.ValueKind == JsonValueKind.True) style += "text-decoration:underline;";
401+
if (sEl.TryGetProperty("fontSize", out var fs) && fs.ValueKind == JsonValueKind.Number) style += $"font-size:{fs.GetInt32()}px;";
402+
if (sEl.TryGetProperty("fontName", out var fn) && fn.ValueKind == JsonValueKind.String) style += $"font-family:{fn.GetString()};";
403+
if (sEl.TryGetProperty("color", out var cl) && cl.ValueKind == JsonValueKind.String) style += $"color:{cl.GetString()};";
404+
if (sEl.TryGetProperty("bgColor", out var bg) && bg.ValueKind == JsonValueKind.String) style += $"background-color:{bg.GetString()};";
405+
if (sEl.TryGetProperty("align", out var al) && al.ValueKind == JsonValueKind.String) style += $"text-align:{al.GetString()};";
404406
if (sEl.TryGetProperty("border", out var bd) && bd.ValueKind == JsonValueKind.False) style = style.Replace("border:1px solid #ccc;", "");
405407
}
406408
return style;
@@ -460,10 +462,13 @@ private static byte[] ExportExcelCore(JsonElement root, Dictionary<string, DataT
460462
if (cell.TryGetProperty("style", out var se))
461463
{
462464
if (se.TryGetProperty("bold", out var b) && b.ValueKind == JsonValueKind.True) xlCell.Style.Font.Bold = true;
463-
if (se.TryGetProperty("fontSize", out var fs)) xlCell.Style.Font.FontSize = fs.GetDouble();
464-
if (se.TryGetProperty("color", out var cl)) xlCell.Style.Font.FontColor = XLColor.FromHtml(cl.GetString()!);
465-
if (se.TryGetProperty("bgColor", out var bg)) xlCell.Style.Fill.BackgroundColor = XLColor.FromHtml(bg.GetString()!);
466-
if (se.TryGetProperty("align", out var al))
465+
if (se.TryGetProperty("italic", out var it) && it.ValueKind == JsonValueKind.True) xlCell.Style.Font.Italic = true;
466+
if (se.TryGetProperty("underline", out var un) && un.ValueKind == JsonValueKind.True) xlCell.Style.Font.Underline = XLFontUnderlineValues.Single;
467+
if (se.TryGetProperty("fontSize", out var fs) && fs.ValueKind == JsonValueKind.Number) xlCell.Style.Font.FontSize = fs.GetDouble();
468+
if (se.TryGetProperty("fontName", out var fn) && fn.ValueKind == JsonValueKind.String) xlCell.Style.Font.FontName = fn.GetString()!;
469+
if (se.TryGetProperty("color", out var cl) && cl.ValueKind == JsonValueKind.String) xlCell.Style.Font.FontColor = XLColor.FromHtml(cl.GetString()!);
470+
if (se.TryGetProperty("bgColor", out var bg) && bg.ValueKind == JsonValueKind.String) xlCell.Style.Fill.BackgroundColor = XLColor.FromHtml(bg.GetString()!);
471+
if (se.TryGetProperty("align", out var al) && al.ValueKind == JsonValueKind.String)
467472
xlCell.Style.Alignment.Horizontal = al.GetString() switch
468473
{
469474
"center" => XLAlignmentHorizontalValues.Center,

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
<el-button :type="italicActive?'primary':''" @click="applyStyle('italic')"><i>I</i></el-button>
5858
<el-button @click="applyStyle('underline')"><u>U</u></el-button>
5959
</el-button-group>
60-
<el-color-picker v-model="selColor" size="small" @change="applyStyle('color')" />
61-
<el-color-picker v-model="selBgColor" size="small" @change="applyStyle('bgColor')" />
60+
<el-color-picker v-model="selColor" size="small" @change="onColorChange('color')" />
61+
<el-color-picker v-model="selBgColor" size="small" @change="onColorChange('bgColor')" />
6262
<el-button-group size="small">
6363
<el-button @click="applyStyle('align','left')">左</el-button>
6464
<el-button @click="applyStyle('align','center')">中</el-button>
@@ -771,11 +771,17 @@ function applyStyle(prop:string, val?:any) {
771771
if (prop==='bold') { style.bold = val!==undefined?val:!style.bold; boldActive.value=style.bold }
772772
else if (prop==='italic') { style.italic = val!==undefined?val:!style.italic; italicActive.value=style.italic }
773773
else if (prop==='underline') { style.underline = val!==undefined?val:!style.underline }
774+
else if (val===null || val===undefined) { delete (style as any)[prop] } // 清除颜色等
774775
else { (style as any)[prop] = val }
775776
cells.value[key] = {...existing, style}
776777
})
777778
}
778779
780+
/** 颜色选择器变更(v-model 已更新,读取最新值写入选中单元格) */
781+
function onColorChange(prop: 'color' | 'bgColor') {
782+
applyStyle(prop, prop==='color' ? selColor.value : selBgColor.value)
783+
}
784+
779785
function toggleBorder() { pushHistory(); forEachSelected((r,c)=>{const key=`${r},${c}`,ex=cells.value[key]||{value:''},s=ex.style||{}; s.border=s.border===false?true:false; cells.value[key]={...ex,style:s}}) }
780786
781787
function mergeSelected() {

0 commit comments

Comments
 (0)