mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-24 00:40:05 +08:00
fix(editor): 代码块删除支持传参处理失败逻辑,ts类型修复
This commit is contained in:
parent
310ee32d75
commit
896f92b5a8
@ -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);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@ -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>
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user