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 {
public env;
public codeDsl: CodeBlockDSL | undefined;
public codeDsl: CodeBlockDSL;
public pages = new Map<Id, Page>();
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);

View File

@ -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);
}
}),

View File

@ -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>('services');
//
const codeList = ref<CodeBlockDSL | null>(null);
@ -87,8 +96,12 @@ const deleteCode = (key: string) => {
if (!codeIds.includes(key) && !undeleteableList.includes(key)) {
//
services?.codeBlockService.deleteCodeDslByIds([key]);
} else {
if (typeof props.customError === 'function') {
props.customError(key, codeIds.includes(key) ? ErrorType.BIND : ErrorType.UNDELETEABLE);
} else {
ElMessage.error('代码块删除失败');
}
}
};
</script>

View File

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