From 0bcd7d075518523809b639e8128583c87b90aa89 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Thu, 10 Apr 2025 19:57:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E6=94=AF=E6=8C=81=E4=BC=A0?= =?UTF-8?q?=E5=85=A5env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/App.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/core/src/App.ts b/packages/core/src/App.ts index 8b76ad37..52da9717 100644 --- a/packages/core/src/App.ts +++ b/packages/core/src/App.ts @@ -33,6 +33,7 @@ import { transformStyle as defaultTransformStyle } from './utils'; export interface AppOptionsConfig { ua?: string; + env?: Env; config?: MApp; platform?: 'editor' | 'mobile' | 'tv' | 'pc'; jsEngine?: JsEngine; @@ -55,7 +56,7 @@ class App extends EventEmitter { App.nodeClassMap.set(type, NodeClass); } - public env: Env = new Env(); + public env!: Env; public dsl?: MApp; public codeDsl?: CodeBlockDSL; public dataSourceManager?: DataSourceManager; @@ -75,7 +76,12 @@ class App extends EventEmitter { constructor(options: AppOptionsConfig) { super(); - this.setEnv(options.ua); + if (options.env) { + this.setEnv(options.env); + } else { + this.setEnv(options.ua); + } + // 代码块描述内容在dsl codeBlocks字段 this.codeDsl = options.config?.codeBlocks; options.platform && (this.platform = options.platform); @@ -123,8 +129,12 @@ class App extends EventEmitter { } } - public setEnv(ua?: string) { - this.env = new Env(ua); + public setEnv(ua?: string | T) { + if (!ua || typeof ua === 'string') { + this.env = new Env(ua); + } else { + this.env = ua; + } } public setDesignWidth(width: number) {