增加字体大小设置

This commit is contained in:
2026-07-03 11:45:16 +08:00
parent 451dd2330b
commit c3bd7960d0
28 changed files with 894 additions and 94 deletions
+57
View File
@@ -0,0 +1,57 @@
/**
* 字体大小工具函数
* 提供响应式字体大小计算能力
*/
const FONT_BASE = 16 // Android 默认字体大小基准
const MIN_SCALE = 0.85
const MAX_SCALE = 1.45
/**
* 获取当前字体缩放比例
* @returns {number} 缩放比例 (0.85 ~ 1.45)
*/
function getFontScale() {
if (getApp().globalData && getApp().globalData.fontScale) {
return getApp().globalData.fontScale
}
const stored = uni.getStorageSync('fontScale')
if (stored) {
return parseFloat(stored)
}
return 1
}
/**
* 计算响应式字体大小
* @param {number} basePx - 基础字体大小(px)
* @param {boolean} round - 是否四舍五入取整
* @returns {string} - 如 "15px" 或 "14.5px"
*/
function responsiveSize(basePx, round = true) {
const scale = getFontScale()
const size = basePx * scale
if (round) {
return `${Math.round(size)}px`
}
return `${Math.round(size * 10) / 10}px`
}
export default {
getFontScale,
responsiveSize,
// 常用预设
presets: {
xs: () => responsiveSize(10),
sm: () => responsiveSize(11),
base: () => responsiveSize(13),
md: () => responsiveSize(14),
lg: () => responsiveSize(16),
xl: () => responsiveSize(20),
xxl: () => responsiveSize(24)
}
}