fix(editor): 修复初始dsl无codeBlocks字段时无法新增的问题

This commit is contained in:
parisma 2022-09-22 20:37:58 +08:00 committed by jia000
parent caa47823be
commit 3bb8ecc975
3 changed files with 23 additions and 17 deletions

View File

@ -61,8 +61,8 @@ class App extends EventEmitter {
super();
this.env = new Env(options.ua);
// 代码块描述内容在dsl codeBlock字段
this.codeDsl = options.config?.codeBlock;
// 代码块描述内容在dsl codeBlocks字段
this.codeDsl = options.config?.codeBlocks;
options.platform && (this.platform = options.platform);
options.jsEngine && (this.jsEngine = options.jsEngine);
options.designWidth && (this.designWidth = options.designWidth);
@ -141,7 +141,7 @@ class App extends EventEmitter {
* @param curPage id
*/
public setConfig(config: MApp, curPage?: Id) {
this.codeDsl = config.codeBlock;
this.codeDsl = config.codeBlocks;
this.pages = new Map();
config.items?.forEach((page) => {
this.pages.set(

View File

@ -69,7 +69,7 @@ class CodeBlock extends BaseService {
}
/**
* dsl数据源dsl中的codeBlock字段读取
* dsl数据源dsl中的codeBlocks字段读取
* @param {boolean} forceRefresh dsl拉取刷新
* @returns {CodeBlockDSL | null}
*/
@ -100,15 +100,21 @@ class CodeBlock extends BaseService {
*/
public async setCodeDslById(id: string, codeConfig: CodeBlockContent): Promise<void> {
let codeDsl = await this.getCodeDsl();
if (!codeDsl) return;
const existContent = codeDsl[id] || {};
codeDsl = {
...codeDsl,
[id]: {
...existContent,
...codeConfig,
},
};
if (!codeDsl) {
// dsl中无代码块字段
codeDsl = {
[id]: codeConfig,
};
} else {
const existContent = codeDsl[id] || {};
codeDsl = {
...codeDsl,
[id]: {
...existContent,
...codeConfig,
},
};
}
await this.setCodeDsl(codeDsl);
}

View File

@ -767,23 +767,23 @@ class Editor extends BaseService {
}
/**
* dsl中的codeBlock字段读取活动的代码块
* dsl中的codeBlocks字段读取活动的代码块
* @returns {CodeBlockDSL | null}
*/
public async getCodeDsl(): Promise<CodeBlockDSL | null> {
const root = this.get<MApp | null>('root');
if (!root) return null;
return root.codeBlock || null;
return root.codeBlocks || null;
}
/**
* dsl的codeBlock字段
* dsl的codeBlocks字段
* @param {CodeBlockDSL} codeDsl DSL
* @returns {void}
*/
public async setCodeDsl(codeDsl: CodeBlockDSL): Promise<void> {
if (!this.state.root) return;
this.state.root.codeBlock = codeDsl;
this.state.root.codeBlocks = codeDsl;
}
private addModifiedNodeId(id: Id) {