|
|
|
@ -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(); |
|
|
|
} |
|
|
|
|
|
|
|
|