mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
fix(data-source): 编辑器的runtime不能对数据源的mock配置有影响
This commit is contained in:
parent
69f3cb2f12
commit
fa2d00ba36
@ -111,28 +111,21 @@ class DataSourceManager extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const beforeInit: ((...args: any[]) => any)[] = [];
|
for (const method of ds.methods) {
|
||||||
const afterInit: ((...args: any[]) => any)[] = [];
|
|
||||||
|
|
||||||
ds.methods.forEach((method) => {
|
|
||||||
if (typeof method.content !== 'function') return;
|
if (typeof method.content !== 'function') return;
|
||||||
if (method.timing === 'beforeInit') {
|
if (method.timing === 'beforeInit') {
|
||||||
beforeInit.push(method.content);
|
method.content({ params: {}, dataSource: ds, app: this.app });
|
||||||
}
|
}
|
||||||
if (method.timing === 'afterInit') {
|
|
||||||
afterInit.push(method.content);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const method of beforeInit) {
|
|
||||||
await method({ params: {}, dataSource: ds, app: this.app });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await ds.init();
|
await ds.init();
|
||||||
|
|
||||||
for (const method of afterInit) {
|
ds.methods.forEach((method) => {
|
||||||
await method({ params: {}, dataSource: ds, app: this.app });
|
if (typeof method.content !== 'function') return;
|
||||||
}
|
if (method.timing === 'afterInit') {
|
||||||
|
method.content({ params: {}, dataSource: ds, app: this.app });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public get(id: string) {
|
public get(id: string) {
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
|
|
||||||
|
import { cloneDeep } from 'lodash-es';
|
||||||
|
|
||||||
import type { AppCore, CodeBlockContent, DataSchema, DataSourceSchema } from '@tmagic/schema';
|
import type { AppCore, CodeBlockContent, DataSchema, DataSourceSchema } from '@tmagic/schema';
|
||||||
import { getDefaultValueFromFields } from '@tmagic/utils';
|
import { getDefaultValueFromFields } from '@tmagic/utils';
|
||||||
|
|
||||||
@ -62,7 +64,7 @@ export default class DataSource<T extends DataSourceSchema = DataSourceSchema> e
|
|||||||
if (this.app.platform === 'editor') {
|
if (this.app.platform === 'editor') {
|
||||||
// 编辑器中有mock使用mock,没有使用默认值
|
// 编辑器中有mock使用mock,没有使用默认值
|
||||||
this.mockData = options.schema.mocks?.find((mock) => mock.useInEditor)?.data || this.getDefaultData();
|
this.mockData = options.schema.mocks?.find((mock) => mock.useInEditor)?.data || this.getDefaultData();
|
||||||
data = this.mockData;
|
data = cloneDeep(this.mockData);
|
||||||
} else if (typeof options.useMock === 'boolean' && options.useMock) {
|
} else if (typeof options.useMock === 'boolean' && options.useMock) {
|
||||||
// 设置了使用mock就使用mock数据
|
// 设置了使用mock就使用mock数据
|
||||||
this.mockData = options.schema.mocks?.find((mock) => mock.enable)?.data || this.getDefaultData();
|
this.mockData = options.schema.mocks?.find((mock) => mock.enable)?.data || this.getDefaultData();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user