From ab03430df1a0e26daeab33b0c782a6a6c0354fb1 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Sun, 27 Sep 2026 03:14:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ui):=20rem=20=E5=9F=BA=E5=87=86?= =?UTF-8?q?=E5=8D=95=E7=82=B9=E6=94=B6=E6=95=9B=E5=88=B0=20render-common/r?= =?UTF-8?q?em-base.js=EF=BC=8C=E6=96=B0=E5=A2=9E=20styles/base.css=20?= =?UTF-8?q?=E5=85=A8=E7=AB=99=E5=9F=BA=E7=A1=80=E6=A0=B7=E5=BC=8F=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - rem 基准:设计宽 1280 / 底座 100 / 缩放 1(只缩不放),html font-size = clamp(50px, 7.8125vw, 100px) - App.vue 改为调用 applyRemBase(),APP-PLUS 侧 !important 覆盖与 H5 同一公式(平板 960 宽 → 75px) - styles/base.css::root 设计 token、12 类元素 ::after 重置、.page/.page-main 骨架、H5 组件库(picker/uni-*)修正由 App.vue 迁入 - electron/main.js 限制最小窗口 1024x640,避免窄窗横向溢出;pages.json 背景色改 token #E8EAED --- electron/main.js | 4 + src/App.vue | 58 +++++------ src/pages.json | 4 +- src/render-common/rem-base.js | 56 +++++++++++ src/styles/base.css | 179 ++++++++++++++++++++++++++++++++++ 5 files changed, 263 insertions(+), 38 deletions(-) create mode 100644 src/render-common/rem-base.js create mode 100644 src/styles/base.css diff --git a/electron/main.js b/electron/main.js index e58943b..0f7a53b 100644 --- a/electron/main.js +++ b/electron/main.js @@ -96,6 +96,10 @@ async function createWindow() { const win = new BrowserWindow({ width: 1200, height: 800, + // 全站按 1280 设计宽做 rem 缩放(<1280 等比缩、下限 640px 对应 0.5 倍), + // 窗口再窄就会出现横向溢出(页面 min-width 约 614px),故限制最小尺寸 + minWidth: 1024, + minHeight: 640, webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, diff --git a/src/App.vue b/src/App.vue index 0f2fcce..d29f815 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,14 +1,10 @@ diff --git a/src/pages.json b/src/pages.json index be17176..6fd874c 100644 --- a/src/pages.json +++ b/src/pages.json @@ -44,7 +44,7 @@ "globalStyle": { "navigationBarTextStyle": "black", "navigationBarTitleText": "wms_worker_station", - "navigationBarBackgroundColor": "#F8F8F8", - "backgroundColor": "#F8F8F8" + "navigationBarBackgroundColor": "#E8EAED", + "backgroundColor": "#E8EAED" } } diff --git a/src/render-common/rem-base.js b/src/render-common/rem-base.js new file mode 100644 index 0000000..b79b6d8 --- /dev/null +++ b/src/render-common/rem-base.js @@ -0,0 +1,56 @@ +/** + * rem 基准(H5 / Electron 唯一来源,各页面请勿再各写一份,否则系数会漂移) + * + * 设计稿 1280 宽,底座与缩放分开(两个因子都是标准值,不要再往里塞观感): + * BASE_FONT_SIZE = 100 ← 设计底座:1rem = 设计稿 100px(rem 值 = 设计稿 px ÷ 100) + * REM_SCALE = 1 ← 显示缩放:标准值 1(1 = 不动;不考虑改) + * 缩放 = min(1, vw / 1280) ← 视口缩放:默认 1,只缩不放,只看宽度 + * html.fontSize = BASE_FONT_SIZE × REM_SCALE × 缩放 + * + * 满格(宽度 ≥1280)= 100px(1280 / 1920 / 2560 / 4K 都一样,也不看窗口高度); + * 窄于 1280 时按比例缩小,缩到一半(640 宽)为止 → 下限 50px。 + * 换算:CSS 里的 rem 值 × 100 = 屏幕实际 px(0.22rem → 22px)。 + * rem 值约定:最多 2 位小数(2026-09-25 全站四舍五入统一)。 + * 字号偏大不通过动基准解决,而是在 CSS 里改 font-size 值(2026-09-25 已把全站 font-size ×0.85)。 + * + * 注意:真机 APP-PLUS 不参与本计算,由 App.vue 中 `html { font-size: 7.8125vw !important }` + * 承担(uni-app 框架会把 html font-size 以内联样式锁为 窗口宽/23.4375;7.8125vw = 100/1280)。 + */ + +export const DESIGN_WIDTH = 1280 +// 设计底座:1280 宽设计稿下 1rem = 100px(rem 值 = 设计稿 px ÷ 100) +export const BASE_FONT_SIZE = 100 +// 显示缩放:标准值 1(不要再拿它当观感旋钮;字号大小改 CSS 里的 font-size 值) +export const REM_SCALE = 1 +// 缩放下限:窗口窄于设计稿一半后不再缩小(100 × 0.5 = 50px) +export const MIN_SCALE = 0.5 + +/** + * 计算当前视口的缩放比(未四舍五入)。 + * @returns {{ width: number, height: number, scale: number } | null} 无 DOM 环境(APP 逻辑层)返回 null + */ +export function calcRemBase () { + if (typeof document === 'undefined' || !document.documentElement) return null + const docEl = document.documentElement + const win = typeof window !== 'undefined' ? window : null + const width = docEl.clientWidth || (win && win.innerWidth) || DESIGN_WIDTH + const height = docEl.clientHeight || (win && win.innerHeight) || 0 + // 缩放默认 1:只看宽度 —— 窗口窄于设计稿才按比例缩小,宽于 1280(或窗口矮)不缩小不放大 + const scale = Math.max(MIN_SCALE, Math.min(1, width / DESIGN_WIDTH)) + return { width, height, scale } +} + +/** + * 应用 html font-size,幂等、可重复调用(首次渲染与 resize 共用)。 + * @returns {number | null} 实际写入的 px 值;无 DOM 环境返回 null + */ +export function applyRemBase () { + const info = calcRemBase() + if (!info) return null + // 保留 1 位小数:避免 33.1078125px 这类长小数带来的亚像素抖动与噪音日志 + const fontSize = Math.round(BASE_FONT_SIZE * REM_SCALE * info.scale * 10) / 10 + document.documentElement.style.fontSize = fontSize + 'px' + console.log('[rem] 1rem =', fontSize + 'px', '(= 底座 ' + BASE_FONT_SIZE + ' × 缩放 ' + REM_SCALE + ' × 视口 ' + Number(info.scale.toFixed(4)) + ')', + '视口 =', info.width + '×' + info.height) + return fontSize +} diff --git a/src/styles/base.css b/src/styles/base.css new file mode 100644 index 0000000..e8b328f --- /dev/null +++ b/src/styles/base.css @@ -0,0 +1,179 @@ +/** + * WMS 工作台 · 全局基准样式(base) + * + * 【怎么被加载】App.vue 的