修复切换页标签后关闭面板会关闭所有面板的异常
This commit is contained in:
@@ -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移除事件监听`);
|
||||
});
|
||||
})
|
||||
|
||||
// 关闭标签页
|
||||
|
||||
Reference in New Issue
Block a user