先切换一下页标签,再点击面板的关闭。
结果两个面板都关闭了,还留下个框线(Tabpage未移除)
This commit is contained in:
@@ -262,40 +262,34 @@ const onPanelClose = (event) => {
|
||||
const areaId = event.areaId;
|
||||
const panelId = event.panelId;
|
||||
|
||||
// 始终只关闭面板,不关闭整个Area,除非没有剩余面板
|
||||
panelActions.close(panelId, areaId);
|
||||
// 1. 先找到要移除的面板
|
||||
const area = floatingAreas.value.find(a => a.id === areaId);
|
||||
if (area && area.children) {
|
||||
const areaChildrenArray = Array.isArray(area.children) ? area.children : [area.children];
|
||||
for (const child of areaChildrenArray) {
|
||||
if (child.type === 'TabPage' && child.children) {
|
||||
// 处理TabPage的children,可能是单个Panel或Panel数组
|
||||
const isArray = Array.isArray(child.children);
|
||||
const childrenArray = isArray ? child.children : [child.children];
|
||||
// 确保TabPage的children是数组,方便统一处理
|
||||
let isArray = Array.isArray(child.children);
|
||||
if (!isArray) {
|
||||
// 如果不是数组,将其转换为数组
|
||||
child.children = [child.children];
|
||||
isArray = true;
|
||||
}
|
||||
|
||||
// 检查每个子项是否为Panel组件
|
||||
for (let i = 0; i < childrenArray.length; i++) {
|
||||
const item = childrenArray[i];
|
||||
for (let i = 0; i < child.children.length; i++) {
|
||||
const item = child.children[i];
|
||||
if (item.type === 'Panel' && item.id === panelId) {
|
||||
// 从数组中移除Panel
|
||||
if (isArray) {
|
||||
child.children.splice(i, 1);
|
||||
} else {
|
||||
// 如果是单个Panel,移除整个TabPage
|
||||
const tabPageIndex = areaChildrenArray.indexOf(child);
|
||||
if (tabPageIndex !== -1) {
|
||||
if (Array.isArray(area.children)) {
|
||||
area.children.splice(tabPageIndex, 1);
|
||||
} else {
|
||||
// 如果area.children是单个对象,直接设为null
|
||||
area.children = null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// 2. 调用PanelActions关闭面板资源
|
||||
panelActions.close(panelId, areaId);
|
||||
|
||||
// 如果Panel数组为空,移除TabPage
|
||||
if (Array.isArray(child.children) && child.children.length === 0) {
|
||||
// 3. 只移除指定的面板,不影响其他面板
|
||||
child.children.splice(i, 1);
|
||||
|
||||
// 4. 检查TabPage是否还有子元素
|
||||
// 当child.children为空数组时,认为TabPage没有子元素
|
||||
if (child.children.length === 0) {
|
||||
// 如果TabPage没有任何子元素,移除TabPage
|
||||
const tabPageIndex = areaChildrenArray.indexOf(child);
|
||||
if (tabPageIndex !== -1) {
|
||||
if (Array.isArray(area.children)) {
|
||||
@@ -312,28 +306,36 @@ const onPanelClose = (event) => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 如果找不到Area或TabPage,仍需关闭面板资源
|
||||
panelActions.close(panelId, areaId);
|
||||
}
|
||||
|
||||
// 检查Area是否还有子元素,如果没有,关闭整个Area
|
||||
if (area && area.children) {
|
||||
let hasChildren = false;
|
||||
const areaChildrenArray = Array.isArray(area.children) ? area.children : [area.children];
|
||||
for (const child of areaChildrenArray) {
|
||||
if (child.type === 'TabPage' && child.children) {
|
||||
const tabChildrenArray = Array.isArray(child.children) ? child.children : [child.children];
|
||||
if (tabChildrenArray.length > 0) {
|
||||
hasChildren = true;
|
||||
break;
|
||||
// 5. 检查Area是否还有子元素,如果没有,关闭整个Area
|
||||
const updatedArea = floatingAreas.value.find(a => a.id === areaId);
|
||||
if (updatedArea) {
|
||||
if (!updatedArea.children) {
|
||||
// Area没有children,直接关闭
|
||||
onCloseFloatingArea({ areaId });
|
||||
} else {
|
||||
// 检查Area的children是否还有有效的TabPage
|
||||
let hasValidTabPage = false;
|
||||
const areaChildrenArray = Array.isArray(updatedArea.children) ? updatedArea.children : [updatedArea.children];
|
||||
for (const child of areaChildrenArray) {
|
||||
if (child.type === 'TabPage' && child.children) {
|
||||
// 检查TabPage是否还有子元素,无论是数组还是单个对象
|
||||
const hasChildren = Array.isArray(child.children) ? child.children.length > 0 : true;
|
||||
if (hasChildren) {
|
||||
hasValidTabPage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasValidTabPage) {
|
||||
onCloseFloatingArea({ areaId });
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasChildren) {
|
||||
onCloseFloatingArea({ areaId });
|
||||
}
|
||||
} else {
|
||||
// Area没有children,直接关闭
|
||||
onCloseFloatingArea({ areaId });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -542,12 +544,12 @@ const onTabClose = async (data) => {
|
||||
}
|
||||
|
||||
// 5. 检查TabPage是否还有子元素
|
||||
// 当targetTabPage.children为null时,TabPage仍然存在,只是不显示标签栏
|
||||
// 只有当children为undefined或空数组时,才认为TabPage没有子元素
|
||||
// 当targetTabPage.children为null或undefined时,认为TabPage没有子元素
|
||||
// 当targetTabPage.children为空数组时,也认为没有子元素
|
||||
let hasTabPageChildren = true;
|
||||
if (Array.isArray(targetTabPage.children)) {
|
||||
hasTabPageChildren = targetTabPage.children.length > 0;
|
||||
} else if (targetTabPage.children === undefined) {
|
||||
} else if (targetTabPage.children === null || targetTabPage.children === undefined) {
|
||||
hasTabPageChildren = false;
|
||||
}
|
||||
|
||||
@@ -710,7 +712,8 @@ const setupEventListeners = () => {
|
||||
unsubscribeFunctions.push(eventBus.on(EVENT_TYPES.PANEL_TOGGLE_COLLAPSE, () => emit('toggleCollapse'), { componentId: 'dock-layout' }));
|
||||
unsubscribeFunctions.push(eventBus.on(EVENT_TYPES.PANEL_MAXIMIZE, onMaximize, { componentId: 'dock-layout' }));
|
||||
unsubscribeFunctions.push(eventBus.on(EVENT_TYPES.PANEL_CLOSE_REQUEST, onPanelClose, { componentId: 'dock-layout' }));
|
||||
unsubscribeFunctions.push(eventBus.on(EVENT_TYPES.PANEL_CLOSE, onPanelClose, { componentId: 'dock-layout' }));
|
||||
// 移除对PANEL_CLOSE事件的监听,避免重复执行关闭逻辑
|
||||
// unsubscribeFunctions.push(eventBus.on(EVENT_TYPES.PANEL_CLOSE, onPanelClose, { componentId: 'dock-layout' }));
|
||||
unsubscribeFunctions.push(eventBus.on(EVENT_TYPES.PANEL_TOGGLE_TOOLBAR, () => emit('toggleToolbar'), { componentId: 'dock-layout' }));
|
||||
unsubscribeFunctions.push(eventBus.on(EVENT_TYPES.PANEL_MAXIMIZE_SYNC, onPanelMaximizeSync, { componentId: 'dock-layout' }));
|
||||
// 单面板检测事件
|
||||
|
||||
Reference in New Issue
Block a user