fix(editor): 代码块删除支持传参处理失败逻辑,ts类型修复

This commit is contained in:
parisma 2022-09-14 20:27:17 +08:00 committed by jia000
parent 310ee32d75
commit 896f92b5a8
4 changed files with 19 additions and 5 deletions

View File

@ -44,7 +44,7 @@ interface EventCache {
class App extends EventEmitter { class App extends EventEmitter {
public env; public env;
public codeDsl: CodeBlockDSL | undefined; public codeDsl: CodeBlockDSL;
public pages = new Map<Id, Page>(); public pages = new Map<Id, Page>();
public page: Page | undefined; public page: Page | undefined;
@ -61,6 +61,7 @@ class App extends EventEmitter {
super(); super();
this.env = new Env(options.ua); this.env = new Env(options.ua);
this.codeDsl = options.config?.methods;
options.platform && (this.platform = options.platform); options.platform && (this.platform = options.platform);
options.jsEngine && (this.jsEngine = options.jsEngine); options.jsEngine && (this.jsEngine = options.jsEngine);
options.designWidth && (this.designWidth = options.designWidth); options.designWidth && (this.designWidth = options.designWidth);

View File

@ -66,10 +66,10 @@ class Node extends EventEmitter {
private listenLifeSafe() { private listenLifeSafe() {
this.once('created', async (instance: any) => { this.once('created', async (instance: any) => {
this.instance = instance; this.instance = instance;
if (Array.isArray(this.data.created)) { if (Array.isArray(this.data.created) && this.app?.codeDsl) {
await Promise.all( await Promise.all(
this.data.created.map(async (codeId) => { 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); await this.app.codeDsl[codeId].content(this);
} }
}), }),

View File

@ -46,6 +46,15 @@ import { CodeBlockDSL, EditorMode } from '../../../type';
import codeBlockEditor from './CodeBlockEditor.vue'; import codeBlockEditor from './CodeBlockEditor.vue';
enum ErrorType {
UNDELETEABLE = 'undeleteable',
BIND = 'bind',
}
const props = defineProps<{
customError: (id: string, errorType: ErrorType) => any;
}>();
const services = inject<Services>('services'); const services = inject<Services>('services');
// //
const codeList = ref<CodeBlockDSL | null>(null); const codeList = ref<CodeBlockDSL | null>(null);
@ -88,7 +97,11 @@ const deleteCode = (key: string) => {
// //
services?.codeBlockService.deleteCodeDslByIds([key]); services?.codeBlockService.deleteCodeDslByIds([key]);
} else { } else {
ElMessage.error('代码块删除失败'); if (typeof props.customError === 'function') {
props.customError(key, codeIds.includes(key) ? ErrorType.BIND : ErrorType.UNDELETEABLE);
} else {
ElMessage.error('代码块删除失败');
}
} }
}; };
</script> </script>

View File

@ -80,7 +80,7 @@ export interface CodeBlockContent {
/** 代码块名称 */ /** 代码块名称 */
name: string; name: string;
/** 代码块内容 */ /** 代码块内容 */
content: string; content: any;
} }
export interface PastePosition { export interface PastePosition {
left?: number; left?: number;