From 923e8ea5abcc10e46967a4f4d67d23d1965b0cf1 Mon Sep 17 00:00:00 2001 From: Iain Date: Fri, 22 Jul 2022 15:25:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E6=B7=BB=E5=8A=A0=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E7=A8=BF=E5=AE=BD=E5=BA=A6=E8=AE=BE=E7=BD=AE(px?= =?UTF-8?q?=E8=BD=ACrem=E7=9B=B8=E5=85=B3)=EF=BC=8C=E9=BB=98=E8=AE=A4375?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E8=AE=BE=E7=BD=AE=E4=B8=BA750?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/App.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/App.ts b/packages/core/src/App.ts index 4ff3db7e..45a65186 100644 --- a/packages/core/src/App.ts +++ b/packages/core/src/App.ts @@ -36,6 +36,7 @@ interface AppOptionsConfig { config?: MApp; platform?: 'editor' | 'mobile' | 'tv' | 'pc'; jsEngine?: 'browser' | 'hippy'; + designWidth?: number; curPage?: Id; transformStyle?: (style: Record) => Record; } @@ -55,6 +56,7 @@ class App extends EventEmitter { public platform = 'mobile'; public jsEngine = 'browser'; + public designWidth = 375; public components = new Map(); @@ -66,13 +68,14 @@ class App extends EventEmitter { this.env = new Env(options.ua); options.platform && (this.platform = options.platform); options.jsEngine && (this.jsEngine = options.jsEngine); + options.designWidth && (this.designWidth = options.designWidth); // 根据屏幕大小计算出跟节点的font-size,用于rem样式的适配 if (this.platform === 'mobile' || this.platform === 'editor') { const calcFontsize = () => { let { width } = document.documentElement.getBoundingClientRect(); width = Math.min(800, width); - const fontSize = width / 3.75; + const fontSize = width / (this.designWidth / 100); document.documentElement.style.fontSize = `${fontSize}px`; };