From c3bd7960d0daf2a0614f1579286e583507b3a88b Mon Sep 17 00:00:00 2001 From: zhangzhen Date: Fri, 3 Jul 2026 11:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E4=BD=93=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 10 +- components/common/inout-history.vue | 8 +- components/common/scan-records.vue | 10 +- main.js | 14 + pages.json | 12 + pages/home/home.vue | 16 +- pages/index/index.vue | 18 +- pages/inout/in.vue | 8 +- pages/inout/out.vue | 6 +- pages/ledger/ledger-in.vue | 18 +- pages/login/login.vue | 12 +- pages/settings/device.vue | 8 +- pages/settings/index.vue | 31 +- pages/settings/other-settings.vue | 297 ++++++++++++++++++ pages/settings/waste-list.vue | 6 +- pages/testpages/bleconfig.vue | 6 +- pages/testpages/font-test.vue | 164 ++++++++++ pages/waste/adjust.vue | 2 +- pages/waste/manifest.vue | 4 +- pages/waste/reprint.vue | 14 +- pages/weigh/generate.vue | 4 +- store/index.js | 4 +- store/modules/font.js | 184 +++++++++++ styles/index.scss | 24 +- styles/variables.scss | 31 +- uni.scss | 12 +- .../components/uni-section/uni-section.vue | 8 +- utils/fontSize.js | 57 ++++ 28 files changed, 894 insertions(+), 94 deletions(-) create mode 100644 pages/settings/other-settings.vue create mode 100644 pages/testpages/font-test.vue create mode 100644 store/modules/font.js create mode 100644 utils/fontSize.js diff --git a/App.vue b/App.vue index 1f95316..a58039e 100644 --- a/App.vue +++ b/App.vue @@ -3,6 +3,9 @@ export default { onLaunch() { console.log('App Launch') + // 🔥 初始化字体缩放(使用 Vuex) + this.$store.dispatch('font/initFontScale') + // 从本地存储恢复登录状态 const token = uni.getStorageSync('token') const userInfo = uni.getStorageSync('userInfo') @@ -25,7 +28,6 @@ export default { // 初始化扫码模式配置 this.$store.dispatch('scan/initScanMode') } - } } @@ -37,5 +39,11 @@ export default { page { height: 100%; + + /* + * 使用 rem 方案后,不需要设置 font-size + * 所有元素使用 rem 单位,会自动相对于根字体大小计算 + * 根字体大小由 JavaScript 动态设置(document.documentElement.style.fontSize) + */ } diff --git a/components/common/inout-history.vue b/components/common/inout-history.vue index b75c9fe..27752bd 100644 --- a/components/common/inout-history.vue +++ b/components/common/inout-history.vue @@ -53,7 +53,7 @@ export default { } .section-title { - font-size: 14px; + font-size: $font-size-md; font-weight: 500; color: #333; } @@ -64,7 +64,7 @@ export default { } .empty-text { - font-size: 13px; + font-size: $font-size-base; color: #999; } @@ -77,12 +77,12 @@ export default { border-radius: 8px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); - font-size: 13px; + font-size: $font-size-base; padding: 12px; } .record-text { - font-size: 13px; + font-size: $font-size-base; color: #333; flex: 1; overflow: hidden; diff --git a/components/common/scan-records.vue b/components/common/scan-records.vue index c03e100..53a2e9a 100644 --- a/components/common/scan-records.vue +++ b/components/common/scan-records.vue @@ -54,13 +54,13 @@ export default { } .section-title { - font-size: 14px; + font-size: $font-size-md; font-weight: 500; color: #333; } .clear-btn { - font-size: 13px; + font-size: $font-size-base; color: #666; padding: 4px 12px; } @@ -71,7 +71,7 @@ export default { } .empty-text { - font-size: 13px; + font-size: $font-size-base; color: #999; } @@ -80,7 +80,7 @@ export default { border-radius: 8px; // margin: 0 16px 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); - font-size: 13px; + font-size: $font-size-base; padding: 12px; } @@ -117,7 +117,7 @@ export default { } .record-time { - font-size: 12px; + font-size: $font-size-xs; color: #999; min-width: 70px; text-align: right; diff --git a/main.js b/main.js index 94919bf..81f4343 100644 --- a/main.js +++ b/main.js @@ -42,6 +42,20 @@ Vue.prototype.$hideLoading = function() { uni.hideLoading() } +// 全局字体工具 +Vue.prototype.$fontSize = require('./utils/fontSize').default + +// 🔥 全局混入:每个页面显示时自动应用字体设置 +Vue.mixin({ + onShow() { + // 从 Vuex 读取字体设置并应用到 DOM + const scale = this.$store.state.font.fontScale + if (scale && scale !== 1.0) { + this.$store.dispatch('font/applyFontScale', scale) + } + } +}) + App.mpType = 'app' const app = new Vue({ diff --git a/pages.json b/pages.json index 8434ac8..38dd84c 100644 --- a/pages.json +++ b/pages.json @@ -109,6 +109,12 @@ "navigationBarTitleText": "环境配置" } }, + { + "path": "pages/settings/other-settings", + "style": { + "navigationBarTitleText": "其他设置" + } + }, { "path": "pages/settings/devices/printer", "style": { @@ -194,6 +200,12 @@ "navigationBarTitleText": "自动打印" } }, + { + "path": "pages/testpages/font-test", + "style": { + "navigationBarTitleText": "字体缩放测试" + } + }, /* #endif */ { "path": "pages/weigh/generate", diff --git a/pages/home/home.vue b/pages/home/home.vue index a4b55ee..52c6a6f 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -115,20 +115,20 @@ export default { border-radius: 0 0 20px 20px; } .home-hospital { - font-size: 17px; + font-size: $font-size-lg; font-weight: 700; display: flex; align-items: center; gap: 6px; } .home-welcome { - font-size: 12px; + font-size: $font-size-xs; opacity: 0.85; margin-top: 4px; } .quick-section { padding: 16px 16px 8px; } .section-title { - font-size: 14px; + font-size: $font-size-md; font-weight: 600; color: $text-primary; margin-bottom: 12px; @@ -158,7 +158,7 @@ export default { justify-content: center; } .quick-item text { - font-size: 13px; + font-size: $font-size-base; color: $text-primary; font-weight: 500; text-align: center; @@ -182,12 +182,12 @@ export default { display: flex; align-items: center; justify-content: center; - font-size: 18px; + font-size: $font-size-lg; background: #f0f0f0; flex-shrink: 0; } .recent-info { flex: 1; } -.recent-info .name { font-size: 13px; color: $text-primary; font-weight: 500; } -.recent-info .detail { font-size: 11px; color: $text-placeholder; margin-top: 2px; } -.recent-time { font-size: 10px; color: #bbbbbb; } +.recent-info .name { font-size: $font-size-base; color: $text-primary; font-weight: 500; } +.recent-info .detail { font-size: $font-size-xs; color: $text-placeholder; margin-top: 2px; } +.recent-time { font-size: calc(10 * var(--font-scale) * 1px); color: #bbbbbb; } diff --git a/pages/index/index.vue b/pages/index/index.vue index 7ecb785..6522d22 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -124,23 +124,23 @@ export default { } - diff --git a/pages/inout/in.vue b/pages/inout/in.vue index 7d04272..36acf54 100644 --- a/pages/inout/in.vue +++ b/pages/inout/in.vue @@ -434,7 +434,7 @@ export default { // 单位文本 .unit-text { - font-size: 14px; + font-size: $font-size-md; color: #666; margin-left: 8px; } @@ -443,7 +443,7 @@ export default { .hazard-tag { padding: 4rpx 16rpx; border-radius: 4rpx; - font-size: 12px; + font-size: $font-size-xs; color: #fff; } @@ -455,7 +455,7 @@ export default { .btn-sm { padding: 0 12px; - font-size: 13px; + font-size: $font-size-base; height: 32px; line-height: 32px; } @@ -476,7 +476,7 @@ export default { } .scan-status-text { - font-size: 13px; + font-size: $font-size-base; color: #007AFF; } diff --git a/pages/inout/out.vue b/pages/inout/out.vue index 8dd2c09..0c6747a 100644 --- a/pages/inout/out.vue +++ b/pages/inout/out.vue @@ -368,7 +368,7 @@ export default { // 单位文本 .unit-text { - font-size: 14px; + font-size: $font-size-md; color: #666; margin-left: 8px; } @@ -380,14 +380,14 @@ export default { // 提示文本 .hint-text { - font-size: 12px; + font-size: $font-size-xs; color: #999; margin-top: 4px; } .btn-sm { padding: 0 12px; - font-size: 13px; + font-size: $font-size-base; height: 32px; line-height: 32px; } diff --git a/pages/ledger/ledger-in.vue b/pages/ledger/ledger-in.vue index 11c6a57..03b387c 100644 --- a/pages/ledger/ledger-in.vue +++ b/pages/ledger/ledger-in.vue @@ -18,8 +18,8 @@ 入库时间{{ item.time }} - - + + @@ -50,3 +50,17 @@ export default { } } + + diff --git a/pages/login/login.vue b/pages/login/login.vue index 4dced01..9492d15 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -137,14 +137,14 @@ export default { .login-title { color: #ffffff; - font-size: 22px; + font-size: $font-size-xl; font-weight: 700; margin-bottom: 6px; } .login-subtitle { color: rgba(255, 255, 255, 0.8); - font-size: 13px; + font-size: $font-size-base; margin-bottom: 32px; } @@ -164,7 +164,7 @@ export default { border-radius: 10px; padding: 0 16px; color: #ffffff; - font-size: 15px; + font-size: $font-size-md; } .login-input::placeholder { @@ -178,7 +178,7 @@ export default { color: #1890ff; border: none; border-radius: 10px; - font-size: 16px; + font-size: $font-size-lg; font-weight: 700; line-height: 48px; } @@ -188,14 +188,14 @@ export default { align-items: center; gap: 6px; color: rgba(255, 255, 255, 0.8); - font-size: 12px; + font-size: $font-size-xs; margin-top: 12px; } .login-version { padding-top: 24px; color: rgba(255, 255, 255, 0.5); - font-size: 11px; + font-size: $font-size-xs; text-align: center; } diff --git a/pages/settings/device.vue b/pages/settings/device.vue index 3f03a4d..8e2a08d 100644 --- a/pages/settings/device.vue +++ b/pages/settings/device.vue @@ -42,8 +42,7 @@ 说明 - - {{ scanMode === 'uniapp' ? '使用默认摄像头扫码' : scanMode === 'idata' ? '仅支持 iData 设备内置扫码' : '通用 Android PDA 设备' }} + {{ scanMode === 'uniapp' ? '使用默认摄像头扫码' : scanMode === 'idata' ? '仅支持 iData 设备内置扫码' : '通用 Android PDA 设备' }} @@ -300,4 +299,9 @@ export default { gap: $spacing-sm; margin-top: $spacing-base; } + +.value-desc { + font-size: $font-size-xs; + color: #999; +} diff --git a/pages/settings/index.vue b/pages/settings/index.vue index 6158b74..8e1cf4f 100644 --- a/pages/settings/index.vue +++ b/pages/settings/index.vue @@ -98,7 +98,22 @@ - + + + + + + + + 其他设置 + 字体大小、显示设置 + + {{ currentFontLabel }} + + + + + @@ -112,7 +127,7 @@ - + @@ -136,15 +151,22 @@ + + diff --git a/pages/settings/waste-list.vue b/pages/settings/waste-list.vue index ad19614..1e468d3 100644 --- a/pages/settings/waste-list.vue +++ b/pages/settings/waste-list.vue @@ -46,7 +46,7 @@ export default { border-bottom: 1px solid #f0f0f0; .page-title { - font-size: 18px; + font-size: $font-size-lg; font-weight: 600; color: #333333; } @@ -66,12 +66,12 @@ export default { justify-content: space-between; .item-name { - font-size: 15px; + font-size: $font-size-md; color: #333333; } .item-code { - font-size: 14px; + font-size: $font-size-base; color: #999999; margin-left: auto; } diff --git a/pages/testpages/bleconfig.vue b/pages/testpages/bleconfig.vue index a318805..50f6348 100644 --- a/pages/testpages/bleconfig.vue +++ b/pages/testpages/bleconfig.vue @@ -157,14 +157,16 @@ export default { }; - diff --git a/pages/waste/adjust.vue b/pages/waste/adjust.vue index 110b4c3..d06af63 100644 --- a/pages/waste/adjust.vue +++ b/pages/waste/adjust.vue @@ -271,7 +271,7 @@ export default { } .type-modal-close { - font-size: 18px; + font-size: $font-size-lg; color: $text-placeholder; padding: 4px; } diff --git a/pages/waste/manifest.vue b/pages/waste/manifest.vue index 573cb45..16cd3c8 100644 --- a/pages/waste/manifest.vue +++ b/pages/waste/manifest.vue @@ -327,7 +327,7 @@ export default { align-items: center; } .data-card-toggle { - font-size: 12px; + font-size: $font-size-xs; color: #999; font-weight: 400; } @@ -338,7 +338,7 @@ export default { .data-card-tag { padding: 2px 8px; border-radius: 4px; - font-size: 12px; + font-size: $font-size-xs; &.orange { background-color: #fff7e6; color: #fa8c16; diff --git a/pages/waste/reprint.vue b/pages/waste/reprint.vue index f07baba..0a2f6f3 100644 --- a/pages/waste/reprint.vue +++ b/pages/waste/reprint.vue @@ -184,14 +184,14 @@ export default { color: #ffffff; text-align: center; padding: 8px 12px; - font-size: 14px; + font-size: $font-size-md; font-weight: 600; display: flex; justify-content: space-between; align-items: center; } .label-toggle { - font-size: 12px; + font-size: $font-size-xs; font-weight: 400; opacity: 0.9; } @@ -211,24 +211,24 @@ export default { } .label-section-title { padding: 10px 0 6px; - font-size: 12px; + font-size: $font-size-xs; font-weight: 600; color: $primary-color; border-bottom: 1px solid $border-light; margin-bottom: 4px; &:first-child { padding-top: 0; } } -.label-key { color: $text-secondary; font-size: 13px; } -.label-val { color: $text-primary; font-size: 13px; font-weight: 500; } +.label-key { color: $text-secondary; font-size: $font-size-base; } +.label-val { color: $text-primary; font-size: $font-size-base; font-weight: 500; } .label-code { - font-size: 11px !important; + font-size: $font-size-xs !important; word-break: break-all; text-align: right; max-width: 60%; } .label-reprint { text-align: center; - font-size: 20px; + font-size: $font-size-xl; font-weight: 700; color: $danger-color; margin-top: 8px; diff --git a/pages/weigh/generate.vue b/pages/weigh/generate.vue index c735364..17f2486 100644 --- a/pages/weigh/generate.vue +++ b/pages/weigh/generate.vue @@ -438,7 +438,7 @@ export default { .btn-sm { padding: 0 12px; - font-size: 13px; + font-size: $font-size-base; height: 32px; line-height: 32px; } @@ -457,7 +457,7 @@ export default { text { margin-left: 4px; - font-size: 14px; + font-size: $font-size-md; color: #333; } } diff --git a/store/index.js b/store/index.js index f80e36d..1556938 100644 --- a/store/index.js +++ b/store/index.js @@ -10,6 +10,7 @@ import sync from './modules/sync' import print from './modules/print' import scale from './modules/scale' import scan from './modules/scan' +import font from './modules/font' export default new Vuex.Store({ modules: { @@ -18,7 +19,8 @@ export default new Vuex.Store({ sync, print, scale, - scan + scan, + font }, strict: process.env.NODE_ENV !== 'production' }) \ No newline at end of file diff --git a/store/modules/font.js b/store/modules/font.js new file mode 100644 index 0000000..1f8b7fa --- /dev/null +++ b/store/modules/font.js @@ -0,0 +1,184 @@ +export default { + namespaced: true, + + state: { + // 字体缩放比例:1.0=默认, 1.25=大, 1.5=较大, 2.0=最大 + fontScale: 1.0, + // 字体大小标签 + fontScaleLabel: '默认' + }, + + mutations: { + /** + * 设置字体缩放比例 + * @param {Object} state - Vuex state + * @param {Object} payload - { scale: number, label: string } + */ + SET_FONT_SCALE(state, payload) { + state.fontScale = payload.scale + state.fontScaleLabel = payload.label + } + }, + + actions: { + /** + * 初始化字体设置 + * 从本地存储读取用户设置,如果没有则使用默认值 + */ + initFontScale({ commit }) { + try { + // 优先读取用户手动设置 + const savedFontSize = uni.getStorageSync('userFontScale') + + if (savedFontSize) { + const fontLabels = { + 1.0: '默认', + 1.25: '大', + 1.5: '较大', + 2.0: '最大' + } + + const label = fontLabels[savedFontSize] || '自定义' + commit('SET_FONT_SCALE', { scale: savedFontSize, label }) + + console.log('[Vuex字体] 初始化成功,使用用户设置:', savedFontSize) + } else { + // 读取系统自动检测的字体缩放 + const systemScale = uni.getStorageSync('fontScale') || 1.0 + + const fontLabels = { + 1.0: '默认', + 1.25: '大', + 1.5: '较大', + 2.0: '最大' + } + + const label = fontLabels[systemScale] || '跟随系统' + commit('SET_FONT_SCALE', { scale: systemScale, label }) + + console.log('[Vuex字体] 初始化成功,使用系统设置:', systemScale) + } + } catch (error) { + console.error('[Vuex字体] 初始化失败:', error) + commit('SET_FONT_SCALE', { scale: 1.0, label: '默认' }) + } + }, + + /** + * 设置字体缩放 + * @param {Object} param - { commit, dispatch } + * @param {Object} payload - { scale: number, label: string } + */ + setFontScale({ commit, dispatch }, payload) { + try { + // 更新 Vuex state + commit('SET_FONT_SCALE', payload) + + // 持久化到本地存储 + uni.setStorageSync('userFontScale', payload.scale) + + console.log('[Vuex字体] 字体已设置为:', payload.label, '(', payload.scale, ')') + + // 应用字体变化到 DOM + dispatch('applyFontScale', payload.scale) + } catch (error) { + console.error('[Vuex字体] 设置失败:', error) + } + }, + + /** + * 应用字体缩放到 DOM + * 直接操作根元素字体大小,使所有 rem 单位自动缩放 + */ + applyFontScale(_, scale) { + const rootFontSize = Math.round(16 * scale * 100) / 100 // 16px 基准 + + console.log(`[Vuex字体] 应用字体缩放: ${rootFontSize}px (scale=${scale})`) + + // #ifdef H5 || APP-PLUS + try { + // 设置 document.documentElement + if (typeof document !== 'undefined' && document.documentElement) { + document.documentElement.style.fontSize = rootFontSize + 'px' + console.log('[Vuex字体] ✓ documentElement.fontSize 已设置为', rootFontSize + 'px') + } + + // 设置所有 page 元素 + if (typeof document !== 'undefined') { + const pages = document.querySelectorAll('page') + if (pages.length > 0) { + pages.forEach(p => p.style.fontSize = rootFontSize + 'px') + console.log('[Vuex字体] ✓ 已设置', pages.length, '个 page 元素') + } + + // 设置 body + if (document.body) { + document.body.style.fontSize = rootFontSize + 'px' + } + } + } catch (e) { + console.warn('[Vuex字体] DOM操作失败:', e) + } + // #endif + + // #ifdef APP-PLUS + // 广播到所有 webview,确保已打开的页面也更新字体 + setTimeout(() => { + try { + const allWebviews = plus.webview.all() + let count = 0 + allWebviews.forEach(webview => { + try { + const fontSize = rootFontSize + 'px' + webview.evalJS(` + if (document.documentElement) document.documentElement.style.fontSize = '${fontSize}'; + if (document.body) document.body.style.fontSize = '${fontSize}'; + document.querySelectorAll('page').forEach(function(p){ p.style.fontSize = '${fontSize}'; }); + `) + count++ + } catch (e2) {} + }) + console.log(`[Vuex字体] 已广播到 ${count}/${allWebviews.length} 个webview`) + } catch (e) { + console.warn('[Vuex字体] 广播失败:', e) + } + }, 200) + // #endif + + // 保存到本地存储,以便其他页面读取 + uni.setStorageSync('fontScale', scale) + }, + + /** + * 重置字体为默认大小 + */ + resetFontScale({ commit, dispatch }) { + try { + // 清除用户设置 + uni.removeStorageSync('userFontScale') + + // 更新 Vuex state + commit('SET_FONT_SCALE', { scale: 1.0, label: '默认' }) + + // 应用默认字体 + dispatch('applyFontScale', 1.0) + + console.log('[Vuex字体] 已恢复默认字体大小') + } catch (error) { + console.error('[Vuex字体] 重置失败:', error) + } + } + }, + + getters: { + /** + * 获取当前字体缩放比例 + */ + fontScale: state => state.fontScale, + + /** + * 获取当前字体大小标签 + */ + fontScaleLabel: state => state.fontScaleLabel + } +} diff --git a/styles/index.scss b/styles/index.scss index 3cf6f66..7177237 100644 --- a/styles/index.scss +++ b/styles/index.scss @@ -7,6 +7,12 @@ page { font-size: $font-size-base; color: $text-primary; line-height: 1.5; + + /* + * 使用 rem 方案后,不需要设置固定的 font-size + * 所有元素使用 rem 单位,会自动相对于根字体大小计算 + * 根字体大小由 JavaScript 动态设置(document.documentElement.style.fontSize) + */ } /* 清除默认样式 */ @@ -92,7 +98,7 @@ button { .back-btn { margin-right: 8px; - font-size: 20px; + font-size: $font-size-xl; padding: 4px; } @@ -542,7 +548,7 @@ button { flex-shrink: 0; .iconfont { - font-size: 22px; + font-size: $font-size-xl; } } @@ -574,7 +580,7 @@ button { .ledger-arrow { color: #cccccc; - font-size: 16px; + font-size: $font-size-md; } /* 设置页面 */ @@ -601,7 +607,7 @@ button { display: flex; align-items: center; justify-content: center; - font-size: 24px; + font-size: $font-size-xl; } .settings-name { @@ -643,7 +649,7 @@ button { display: flex; align-items: center; justify-content: center; - font-size: 16px; + font-size: $font-size-lg; background: #f0f0f0; margin-right: $spacing-base; flex-shrink: 0; @@ -674,7 +680,7 @@ button { .s-arrow { color: #cccccc; - font-size: 14px; + font-size: $font-size-md; } .version-info { @@ -708,7 +714,7 @@ button { display: flex; align-items: center; justify-content: center; - font-size: 18px; + font-size: $font-size-lg; background: #f0f0f0; flex-shrink: 0; } @@ -732,7 +738,7 @@ button { .sub-menu-arrow { color: #cccccc; - font-size: 14px; + font-size: $font-size-md; } /* 设备管理 */ @@ -756,7 +762,7 @@ button { } .device-icon { - font-size: 18px; + font-size: $font-size-lg; } .device-title { diff --git a/styles/variables.scss b/styles/variables.scss index ec89403..7309839 100644 --- a/styles/variables.scss +++ b/styles/variables.scss @@ -1,3 +1,25 @@ +// ============================================ +// 📌 字体大小 - 使用 rem 单位(推荐方案) +// ============================================ +// 核心原理: +// 1. rem 相对于根元素(page/html)的字体大小计算 +// 2. 只需要修改根字体大小,所有 rem 会自动缩放 +// 3. 基准:1rem = 16px(浏览器默认值) +// 4. 字体缩放时,修改 document.documentElement.style.fontSize 即可 + +// 基础字号(基于 16px 基准) +$font-size-xs: 0.625rem; // 10px / 16px +$font-size-sm: 0.6875rem; // 11px / 16px +$font-size-base: 0.8125rem; // 13px / 16px +$font-size-md: 0.875rem; // 14px / 16px +$font-size-lg: 1rem; // 16px / 16px +$font-size-xl: 1.25rem; // 20px / 16px +$font-size-xxl: 1.5rem; // 24px / 16px + +// ============================================ +// 📌 SCSS 变量(主题、颜色等) +// ============================================ + // 主题色 $primary-color: #1890ff; $success-color: #52c41a; @@ -43,15 +65,6 @@ $border-radius-md: 10px; $border-radius-lg: 14px; $border-radius-xl: 20px; -// 字体大小 -$font-size-xs: 10px; -$font-size-sm: 11px; -$font-size-base: 13px; -$font-size-md: 14px; -$font-size-lg: 16px; -$font-size-xl: 20px; -$font-size-xxl: 24px; - // 间距 $spacing-xs: 4px; $spacing-sm: 8px; diff --git a/uni.scss b/uni.scss index 4148f1f..bb463ef 100644 --- a/uni.scss +++ b/uni.scss @@ -39,9 +39,9 @@ $uni-border-color:#c8c7cc; /* 尺寸变量 */ /* 文字尺寸 */ -$uni-font-size-sm:12px; -$uni-font-size-base:14px; -$uni-font-size-lg:16px; +$uni-font-size-sm:0.75rem; +$uni-font-size-base:0.875rem; +$uni-font-size-lg:1rem; /* 图片尺寸 */ $uni-img-size-sm:20px; @@ -69,11 +69,11 @@ $uni-opacity-disabled: 0.3; // 组件禁用态的透明度 /* 文章场景相关 */ $uni-color-title: #2C405A; // 文章标题颜色 -$uni-font-size-title:20px; +$uni-font-size-title:1.25rem; $uni-color-subtitle: #555555; // 二级标题颜色 -$uni-font-size-subtitle:26px; +$uni-font-size-subtitle:1.625rem; $uni-color-paragraph: #3F536E; // 文章段落颜色 -$uni-font-size-paragraph:15px; +$uni-font-size-paragraph:0.9375rem; // 导入自定义变量文件 @import '@/styles/variables.scss'; diff --git a/uni_modules/uni-section/components/uni-section/uni-section.vue b/uni_modules/uni-section/components/uni-section/uni-section.vue index 9a52e0b..896d01b 100644 --- a/uni_modules/uni-section/components/uni-section/uni-section.vue +++ b/uni_modules/uni-section/components/uni-section/uni-section.vue @@ -5,8 +5,8 @@ - {{ title }} - {{ subTitle }} + {{ title }} + {{ subTitle }} @@ -53,7 +53,7 @@ }, titleFontSize: { type: String, - default: '14px' + default: '' }, titleColor:{ type: String, @@ -65,7 +65,7 @@ }, subTitleFontSize: { type: String, - default: '12px' + default: '' }, subTitleColor: { type: String, diff --git a/utils/fontSize.js b/utils/fontSize.js new file mode 100644 index 0000000..6c6960b --- /dev/null +++ b/utils/fontSize.js @@ -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) + } +}