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