mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-11 05:31:56 +08:00
fix(editor): 组件销毁时移除service的时间监听
This commit is contained in:
parent
841b75eef1
commit
cfc57f17af
@ -227,7 +227,7 @@ export default defineComponent({
|
|||||||
emits: ['props-panel-mounted', 'update:modelValue'],
|
emits: ['props-panel-mounted', 'update:modelValue'],
|
||||||
|
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
editorService.on('root-change', (value, preValue) => {
|
const rootChangeHandler = (value: MApp, preValue?: MApp | null) => {
|
||||||
const nodeId = editorService.get<MNode | null>('node')?.id || props.defaultSelected;
|
const nodeId = editorService.get<MNode | null>('node')?.id || props.defaultSelected;
|
||||||
let node;
|
let node;
|
||||||
if (nodeId) {
|
if (nodeId) {
|
||||||
@ -247,7 +247,9 @@ export default defineComponent({
|
|||||||
if (toRaw(value) !== toRaw(preValue)) {
|
if (toRaw(value) !== toRaw(preValue)) {
|
||||||
emit('update:modelValue', value);
|
emit('update:modelValue', value);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
editorService.on('root-change', rootChangeHandler);
|
||||||
|
|
||||||
// 初始值变化,重新设置节点信息
|
// 初始值变化,重新设置节点信息
|
||||||
watch(
|
watch(
|
||||||
@ -326,6 +328,8 @@ export default defineComponent({
|
|||||||
uiService.resetState();
|
uiService.resetState();
|
||||||
componentListService.resetState();
|
componentListService.resetState();
|
||||||
codeBlockService.resetState();
|
codeBlockService.resetState();
|
||||||
|
|
||||||
|
editorService.off('root-change', rootChangeHandler);
|
||||||
});
|
});
|
||||||
|
|
||||||
const services: Services = {
|
const services: Services = {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup name="MEditorPropsPanel">
|
<script lang="ts" setup name="MEditorPropsPanel">
|
||||||
import { computed, getCurrentInstance, inject, onMounted, ref, watchEffect } from 'vue';
|
import { computed, getCurrentInstance, inject, onMounted, onUnmounted, ref, watchEffect } from 'vue';
|
||||||
|
|
||||||
import { tMagicMessage } from '@tmagic/design';
|
import { tMagicMessage } from '@tmagic/design';
|
||||||
import type { FormValue } from '@tmagic/form';
|
import type { FormValue } from '@tmagic/form';
|
||||||
@ -56,6 +56,10 @@ onMounted(() => {
|
|||||||
emit('mounted', internalInstance);
|
emit('mounted', internalInstance);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
services?.propsService.off('props-configs-change', init);
|
||||||
|
});
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (configForm.value && stage.value) {
|
if (configForm.value && stage.value) {
|
||||||
configForm.value.formState.stage = stage.value;
|
configForm.value.formState.stage = stage.value;
|
||||||
|
@ -104,12 +104,6 @@ const filterText = ref('');
|
|||||||
// 默认展开节点
|
// 默认展开节点
|
||||||
const defaultExpandedKeys = computed(() => (selectedIds.value.length > 0 ? selectedIds.value : []));
|
const defaultExpandedKeys = computed(() => (selectedIds.value.length > 0 ? selectedIds.value : []));
|
||||||
|
|
||||||
editorService?.on('remove', () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
tree.value?.getNode(editorService.get('node').id)?.updateChildren();
|
|
||||||
}, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 触发画布单选
|
// 触发画布单选
|
||||||
const select = async (data: MNode) => {
|
const select = async (data: MNode) => {
|
||||||
if (!data.id) {
|
if (!data.id) {
|
||||||
@ -273,9 +267,17 @@ const mouseleaveHandler = () => {
|
|||||||
isMultiSelectStatus.value = false;
|
isMultiSelectStatus.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const editorServiceRemoveHandler = () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
tree.value?.getNode(editorService?.get('node').id)?.updateChildren();
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
let keycon: KeyController;
|
let keycon: KeyController;
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
editorService?.on('remove', editorServiceRemoveHandler);
|
||||||
|
|
||||||
keycon = new KeyController(tree.value?.$el);
|
keycon = new KeyController(tree.value?.$el);
|
||||||
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
||||||
const ctrl = isMac ? 'meta' : 'ctrl';
|
const ctrl = isMac ? 'meta' : 'ctrl';
|
||||||
@ -293,6 +295,8 @@ onMounted(() => {
|
|||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
keycon.destroy();
|
keycon.destroy();
|
||||||
|
|
||||||
|
editorService?.off('remove', editorServiceRemoveHandler);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 鼠标是否按下标志,用于高亮状态互斥
|
// 鼠标是否按下标志,用于高亮状态互斥
|
||||||
|
@ -170,8 +170,12 @@ export default class extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public removeAllPlugins() {
|
public removeAllPlugins() {
|
||||||
this.pluginOptionsList = {};
|
Object.keys(this.pluginOptionsList).forEach((key) => {
|
||||||
this.middleware = {};
|
this.pluginOptionsList[key] = [];
|
||||||
|
});
|
||||||
|
Object.keys(this.middleware).forEach((key) => {
|
||||||
|
this.middleware[key] = [];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async doTask() {
|
private async doTask() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user