fix: 统一使用事件总线,修复模态框不自动消失的问题

This commit is contained in:
Baobhan Sith
2025-05-10 13:15:54 +08:00
parent 87375c6e85
commit 9ec75c0fdd
3 changed files with 24 additions and 5 deletions
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { defineProps, defineEmits, watch } from 'vue';
import { defineProps, defineEmits, watch, onMounted, onBeforeUnmount } from 'vue';
import QuickCommandsView from '../views/QuickCommandsView.vue'; // 导入视图
import { useWorkspaceEventSubscriber } from '../composables/workspaceEvents'; // 导入事件订阅器
const props = defineProps<{
isVisible: boolean;
@@ -36,12 +37,22 @@ watch(() => props.isVisible, (newValue) => {
}
});
const onWorkspaceEvent = useWorkspaceEventSubscriber(); // 获取事件订阅器
// Clean up listener on unmount (though v-if usually handles this)
import { onUnmounted } from 'vue';
onUnmounted(() => {
document.removeEventListener('keydown', handleKeydown);
});
onMounted(() => {
// 监听 terminal:sendCommand 事件以关闭模态框
onWorkspaceEvent('terminal:sendCommand', () => {
console.log('[QuickCommandsModal] Received terminal:sendCommand event, closing modal.');
closeModal();
});
});
</script>
<template>