修复切换页标签后关闭面板会关闭所有面板的异常

This commit is contained in:
zqm
2026-01-13 16:56:27 +08:00
parent d0e45bd479
commit 4a14dc9158
4 changed files with 64 additions and 1 deletions

View File

@@ -133,7 +133,7 @@
<script setup>
import { defineProps, ref, onMounted, onUnmounted, computed } from 'vue'
import { emitEvent, EVENT_TYPES } from './eventBus'
import { emitEvent, eventBus, EVENT_TYPES } from './eventBus'
import Render from './Render.vue'
const props = defineProps({
@@ -215,6 +215,37 @@ onMounted(() => {
setActiveTab(0)
}
}
// 监听面板移除事件调整activeTabIndex
const unsubscribe = eventBus.on(EVENT_TYPES.TABPAGE_PANEL_REMOVED, (data) => {
if (data.tabPageId === props.id) {
console.log(`[TabPage:${props.id}] 收到Panel移除事件:`, data);
if (data.remainingPanelCount === 0) {
// 如果移除后没有Panel了重置activeTabIndex
activeTabIndex.value = -1;
console.log(` → 没有Panel了重置activeTabIndex为-1`);
} else if (activeTabIndex.value >= data.remainingPanelCount) {
// 如果当前激活的索引超出范围,调整为最后一个
const oldIndex = activeTabIndex.value;
activeTabIndex.value = data.remainingPanelCount - 1;
console.log(` → 激活索引${oldIndex}超出范围,调整为${activeTabIndex.value}`);
} else if (activeTabIndex.value > data.removedIndex) {
// 如果当前激活的索引在移除的索引之后需要减1
const oldIndex = activeTabIndex.value;
activeTabIndex.value -= 1;
console.log(` → 激活索引在移除索引之后,从${oldIndex}调整为${activeTabIndex.value}`);
}
// 如果当前激活的索引在移除的索引之前,不需要调整
console.log(` → 调整后的activeTabIndex: ${activeTabIndex.value}`);
}
}, { componentId: 'tabpage' });
// 保存取消订阅函数,在组件卸载时清理
onUnmounted(() => {
unsubscribe();
console.log(`[TabPage:${props.id}] 已清理Panel移除事件监听`);
});
})
// 关闭标签页