From 896f92b5a88729f3178c3556932e761a9fcd37c0 Mon Sep 17 00:00:00 2001 From: parisma Date: Wed, 14 Sep 2022 20:27:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E4=BB=A3=E7=A0=81=E5=9D=97?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=94=AF=E6=8C=81=E4=BC=A0=E5=8F=82=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=A4=B1=E8=B4=A5=E9=80=BB=E8=BE=91,ts=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/App.ts | 3 ++- packages/core/src/Node.ts | 4 ++-- .../layouts/sidebar/code-block/CodeBlockList.vue | 15 ++++++++++++++- packages/schema/src/index.ts | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/core/src/App.ts b/packages/core/src/App.ts index 55298321..2f0fa1df 100644 --- a/packages/core/src/App.ts +++ b/packages/core/src/App.ts @@ -44,7 +44,7 @@ interface EventCache { class App extends EventEmitter { public env; - public codeDsl: CodeBlockDSL | undefined; + public codeDsl: CodeBlockDSL; public pages = new Map(); public page: Page | undefined; @@ -61,6 +61,7 @@ class App extends EventEmitter { super(); this.env = new Env(options.ua); + this.codeDsl = options.config?.methods; options.platform && (this.platform = options.platform); options.jsEngine && (this.jsEngine = options.jsEngine); options.designWidth && (this.designWidth = options.designWidth); diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index d3a4e5a1..d73112de 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -66,10 +66,10 @@ class Node extends EventEmitter { private listenLifeSafe() { this.once('created', async (instance: any) => { this.instance = instance; - if (Array.isArray(this.data.created)) { + if (Array.isArray(this.data.created) && this.app?.codeDsl) { await Promise.all( this.data.created.map(async (codeId) => { - if (this.app?.codeDsl[codeId] && typeof this.app?.codeDsl[codeId]?.content === 'function') { + if (this.app.codeDsl[codeId] && typeof this.app?.codeDsl[codeId]?.content === 'function') { await this.app.codeDsl[codeId].content(this); } }), diff --git a/packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue b/packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue index 8b19d35e..48a542ac 100644 --- a/packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue +++ b/packages/editor/src/layouts/sidebar/code-block/CodeBlockList.vue @@ -46,6 +46,15 @@ import { CodeBlockDSL, EditorMode } from '../../../type'; import codeBlockEditor from './CodeBlockEditor.vue'; +enum ErrorType { + UNDELETEABLE = 'undeleteable', + BIND = 'bind', +} + +const props = defineProps<{ + customError: (id: string, errorType: ErrorType) => any; +}>(); + const services = inject('services'); // 代码块列表 const codeList = ref(null); @@ -88,7 +97,11 @@ const deleteCode = (key: string) => { // 无绑定关系,且不在不可删除列表中 services?.codeBlockService.deleteCodeDslByIds([key]); } else { - ElMessage.error('代码块删除失败'); + if (typeof props.customError === 'function') { + props.customError(key, codeIds.includes(key) ? ErrorType.BIND : ErrorType.UNDELETEABLE); + } else { + ElMessage.error('代码块删除失败'); + } } }; diff --git a/packages/schema/src/index.ts b/packages/schema/src/index.ts index ad582e92..8f6e0085 100644 --- a/packages/schema/src/index.ts +++ b/packages/schema/src/index.ts @@ -80,7 +80,7 @@ export interface CodeBlockContent { /** 代码块名称 */ name: string; /** 代码块内容 */ - content: string; + content: any; } export interface PastePosition { left?: number;