From 6f92fff471abd0b6225f098e512193e59ed3b620 Mon Sep 17 00:00:00 2001 From: lzx_win <2602107437@qq.com> Date: Mon, 13 Oct 2025 09:37:49 +0800 Subject: [PATCH] 1 --- .../views/applet/course-page/components/ContentEditor.vue | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jeecgboot-vue3/src/views/applet/course-page/components/ContentEditor.vue b/jeecgboot-vue3/src/views/applet/course-page/components/ContentEditor.vue index 486cd6f..b025405 100644 --- a/jeecgboot-vue3/src/views/applet/course-page/components/ContentEditor.vue +++ b/jeecgboot-vue3/src/views/applet/course-page/components/ContentEditor.vue @@ -181,13 +181,14 @@ watch( if (!c.style.fontFamily) c.style.fontFamily = 'SimSun'; if (!c.style.fontWeight) c.style.fontWeight = 'normal'; if (typeof c.isLead === 'undefined') c.isLead = false; - // 单位归一化:如果是 px,替换为 rpx;如果是纯数字,补 rpx + // 单位归一化:如果是 px,替换为 rpx;如果是纯数字,补 rpx;如果已经是 rpx,保持不变 if (typeof c.style.fontSize === 'string') { if (/px$/i.test(c.style.fontSize)) { c.style.fontSize = c.style.fontSize.replace(/px$/i, 'rpx'); } else if (/^\d+$/.test(c.style.fontSize)) { c.style.fontSize = `${c.style.fontSize}rpx`; } + // 如果已经是 rpx 格式,不做任何处理,避免重复添加单位 } } return c; @@ -278,8 +279,13 @@ function getFontSizeNumber(component: any) { function setFontSizeNumber(component: any, value: number) { ensureStyle(component); - // 统一以 rpx 保存,满足前端要求 - component.style.fontSize = `${value}rpx`; + // 确保value是有效数字,然后统一以 rpx 保存 + const numValue = Number(value); + if (isNaN(numValue) || numValue <= 0) { + component.style.fontSize = '30rpx'; // 默认值 + } else { + component.style.fontSize = `${numValue}rpx`; + } emitUpdate(); }