mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-26 10:59:58 +08:00
feat(data-source): 支持在指定js环境下不执行init的配置
This commit is contained in:
parent
2a5b9ec6bd
commit
86bdb9f099
@ -31,6 +31,7 @@ import {
|
|||||||
type DeprecatedEventConfig,
|
type DeprecatedEventConfig,
|
||||||
type EventConfig,
|
type EventConfig,
|
||||||
type Id,
|
type Id,
|
||||||
|
type JsEngine,
|
||||||
type MApp,
|
type MApp,
|
||||||
type RequestFunction,
|
type RequestFunction,
|
||||||
} from '@tmagic/schema';
|
} from '@tmagic/schema';
|
||||||
@ -45,7 +46,7 @@ interface AppOptionsConfig {
|
|||||||
ua?: string;
|
ua?: string;
|
||||||
config?: MApp;
|
config?: MApp;
|
||||||
platform?: 'editor' | 'mobile' | 'tv' | 'pc';
|
platform?: 'editor' | 'mobile' | 'tv' | 'pc';
|
||||||
jsEngine?: 'browser' | 'hippy' | 'nodejs';
|
jsEngine?: JsEngine;
|
||||||
designWidth?: number;
|
designWidth?: number;
|
||||||
curPage?: Id;
|
curPage?: Id;
|
||||||
useMock?: boolean;
|
useMock?: boolean;
|
||||||
|
@ -29,10 +29,17 @@ import type { DataSourceManagerData, DataSourceManagerOptions } from './types';
|
|||||||
class DataSourceManager extends EventEmitter {
|
class DataSourceManager extends EventEmitter {
|
||||||
private static dataSourceClassMap = new Map<string, typeof DataSource>();
|
private static dataSourceClassMap = new Map<string, typeof DataSource>();
|
||||||
|
|
||||||
public static registe<T extends typeof DataSource = typeof DataSource>(type: string, dataSource: T) {
|
public static register<T extends typeof DataSource = typeof DataSource>(type: string, dataSource: T) {
|
||||||
DataSourceManager.dataSourceClassMap.set(type, dataSource);
|
DataSourceManager.dataSourceClassMap.set(type, dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public static registe<T extends typeof DataSource = typeof DataSource>(type: string, dataSource: T) {
|
||||||
|
DataSourceManager.register(type, dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
public static getDataSourceClass(type: string) {
|
public static getDataSourceClass(type: string) {
|
||||||
return DataSourceManager.dataSourceClassMap.get(type);
|
return DataSourceManager.dataSourceClassMap.get(type);
|
||||||
}
|
}
|
||||||
@ -66,6 +73,10 @@ class DataSourceManager extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.app.jsEngine && ds.schema.disabledInitInJsEngine?.includes(this.app.jsEngine)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const beforeInit: ((...args: any[]) => any)[] = [];
|
const beforeInit: ((...args: any[]) => any)[] = [];
|
||||||
const afterInit: ((...args: any[]) => any)[] = [];
|
const afterInit: ((...args: any[]) => any)[] = [];
|
||||||
|
|
||||||
@ -239,6 +250,6 @@ class DataSourceManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataSourceManager.registe('http', HttpDataSource as any);
|
DataSourceManager.register('http', HttpDataSource as any);
|
||||||
|
|
||||||
export default DataSourceManager;
|
export default DataSourceManager;
|
||||||
|
@ -33,13 +33,15 @@ export interface HttpOptions {
|
|||||||
|
|
||||||
export type RequestFunction = <T = any>(options: HttpOptions) => Promise<T>;
|
export type RequestFunction = <T = any>(options: HttpOptions) => Promise<T>;
|
||||||
|
|
||||||
|
export type JsEngine = 'browser' | 'hippy' | 'nodejs';
|
||||||
|
|
||||||
export interface AppCore {
|
export interface AppCore {
|
||||||
/** 页面配置描述 */
|
/** 页面配置描述 */
|
||||||
dsl?: MApp;
|
dsl?: MApp;
|
||||||
/** 允许平台,editor: 编辑器中,mobile: 手机端,tv: 电视端, pc: 电脑端 */
|
/** 允许平台,editor: 编辑器中,mobile: 手机端,tv: 电视端, pc: 电脑端 */
|
||||||
platform?: 'editor' | 'mobile' | 'tv' | 'pc' | string;
|
platform?: 'editor' | 'mobile' | 'tv' | 'pc' | string;
|
||||||
/** 代码运行环境 */
|
/** 代码运行环境 */
|
||||||
jsEngine?: 'browser' | 'hippy' | 'nodejs' | string;
|
jsEngine?: JsEngine | string;
|
||||||
/** 网络请求函数 */
|
/** 网络请求函数 */
|
||||||
request?: RequestFunction;
|
request?: RequestFunction;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
@ -237,6 +239,8 @@ export interface DataSourceSchema {
|
|||||||
methods: CodeBlockContent[];
|
methods: CodeBlockContent[];
|
||||||
/** mock数据 */
|
/** mock数据 */
|
||||||
mocks?: MockSchema[];
|
mocks?: MockSchema[];
|
||||||
|
/** 不执行init的环境 */
|
||||||
|
disabledInitInJsEngine?: (JsEngine | string)[];
|
||||||
/** 扩展字段 */
|
/** 扩展字段 */
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user