feat(core): 支持传入env

This commit is contained in:
roymondchen 2025-04-10 19:57:33 +08:00
parent 54e00f2852
commit 0bcd7d0755

View File

@ -33,6 +33,7 @@ import { transformStyle as defaultTransformStyle } from './utils';
export interface AppOptionsConfig { export interface AppOptionsConfig {
ua?: string; ua?: string;
env?: Env;
config?: MApp; config?: MApp;
platform?: 'editor' | 'mobile' | 'tv' | 'pc'; platform?: 'editor' | 'mobile' | 'tv' | 'pc';
jsEngine?: JsEngine; jsEngine?: JsEngine;
@ -55,7 +56,7 @@ class App extends EventEmitter {
App.nodeClassMap.set(type, NodeClass); App.nodeClassMap.set(type, NodeClass);
} }
public env: Env = new Env(); public env!: Env;
public dsl?: MApp; public dsl?: MApp;
public codeDsl?: CodeBlockDSL; public codeDsl?: CodeBlockDSL;
public dataSourceManager?: DataSourceManager; public dataSourceManager?: DataSourceManager;
@ -75,7 +76,12 @@ class App extends EventEmitter {
constructor(options: AppOptionsConfig) { constructor(options: AppOptionsConfig) {
super(); super();
this.setEnv(options.ua); if (options.env) {
this.setEnv(options.env);
} else {
this.setEnv(options.ua);
}
// 代码块描述内容在dsl codeBlocks字段 // 代码块描述内容在dsl codeBlocks字段
this.codeDsl = options.config?.codeBlocks; this.codeDsl = options.config?.codeBlocks;
options.platform && (this.platform = options.platform); options.platform && (this.platform = options.platform);
@ -123,8 +129,12 @@ class App extends EventEmitter {
} }
} }
public setEnv(ua?: string) { public setEnv<T extends Env>(ua?: string | T) {
this.env = new Env(ua); if (!ua || typeof ua === 'string') {
this.env = new Env(ua);
} else {
this.env = ua;
}
} }
public setDesignWidth(width: number) { public setDesignWidth(width: number) {