fix(editor): 代码块code-block-panel-tool slot data丢失

This commit is contained in:
roymondchen 2023-03-30 16:13:23 +08:00
parent 6340bcc04b
commit aa12779598
2 changed files with 8 additions and 10 deletions

View File

@ -85,6 +85,7 @@ const codeList = computed(() =>
id: target.id, id: target.id,
name: target.name, name: target.name,
type: 'code', type: 'code',
codeBlockContent: codeBlockService?.getCodeContentById(target.id),
children: Object.entries(target.deps).map(([id, dep]) => ({ children: Object.entries(target.deps).map(([id, dep]) => ({
name: dep.name, name: dep.name,
type: 'node', type: 'node',

View File

@ -39,9 +39,6 @@ class CodeBlock extends BaseService {
constructor() { constructor() {
super([ super([
'getCodeContentById',
'getCodeDslByIds',
'getCurrentDsl',
'setCodeDslById', 'setCodeDslById',
'setCodeEditorShowStatus', 'setCodeEditorShowStatus',
'setEditStatus', 'setEditStatus',
@ -77,9 +74,9 @@ class CodeBlock extends BaseService {
* @param {Id} id id * @param {Id} id id
* @returns {CodeBlockContent | null} * @returns {CodeBlockContent | null}
*/ */
public async getCodeContentById(id: Id): Promise<CodeBlockContent | null> { public getCodeContentById(id: Id): CodeBlockContent | null {
if (!id) return null; if (!id) return null;
const totalCodeDsl = await this.getCodeDsl(); const totalCodeDsl = this.getCodeDsl();
if (!totalCodeDsl) return null; if (!totalCodeDsl) return null;
return totalCodeDsl[id] ?? null; return totalCodeDsl[id] ?? null;
} }
@ -91,7 +88,7 @@ class CodeBlock extends BaseService {
* @returns {void} * @returns {void}
*/ */
public async setCodeDslById(id: Id, codeConfig: CodeBlockContent): Promise<void> { public async setCodeDslById(id: Id, codeConfig: CodeBlockContent): Promise<void> {
const codeDsl = await this.getCodeDsl(); const codeDsl = this.getCodeDsl();
if (!codeDsl) { if (!codeDsl) {
throw new Error('dsl中没有codeBlocks'); throw new Error('dsl中没有codeBlocks');
@ -119,8 +116,8 @@ class CodeBlock extends BaseService {
* @param {string[]} ids id数组 * @param {string[]} ids id数组
* @returns {CodeBlockDSL} * @returns {CodeBlockDSL}
*/ */
public async getCodeDslByIds(ids: string[]): Promise<CodeBlockDSL> { public getCodeDslByIds(ids: string[]): CodeBlockDSL {
const codeDsl = await this.getCodeDsl(); const codeDsl = this.getCodeDsl();
return pick(codeDsl, ids) as CodeBlockDSL; return pick(codeDsl, ids) as CodeBlockDSL;
} }
@ -157,8 +154,8 @@ class CodeBlock extends BaseService {
* *
* @returns {CodeBlockContent | null} * @returns {CodeBlockContent | null}
*/ */
public async getCurrentDsl(): Promise<CodeBlockContent | null> { public getCurrentDsl(): CodeBlockContent | null {
return await this.getCodeContentById(this.state.id); return this.getCodeContentById(this.state.id);
} }
/** /**