解决状态未初始化Bug
This commit is contained in:
@@ -942,6 +942,17 @@ const addFloatingPanel = (panel) => {
|
||||
// 同时注册到AreaHandler的状态管理中,确保事件处理能正常进行
|
||||
areaActions.createFloating(newArea)
|
||||
|
||||
// 初始化面板状态
|
||||
const tabPage = newArea.children
|
||||
if (tabPage.children) {
|
||||
const childrenArray = Array.isArray(tabPage.children) ? tabPage.children : [tabPage.children]
|
||||
for (const panel of childrenArray) {
|
||||
if (panel.type === 'Panel' && panel.id) {
|
||||
panelActions.initializePanelState(panel.id, areaId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newArea.id
|
||||
}
|
||||
|
||||
@@ -1400,11 +1411,34 @@ const onAreaResizeEnd = (event) => {
|
||||
// 只需要更新本地floatingAreas中的状态
|
||||
};
|
||||
|
||||
/**
|
||||
* 初始化主区域的所有面板状态
|
||||
*/
|
||||
const initializeMainAreaPanels = () => {
|
||||
const mainTabPage = mainAreaConfig.value.children;
|
||||
if (mainTabPage && mainTabPage.type === 'TabPage' && mainTabPage.children) {
|
||||
const childrenArray = Array.isArray(mainTabPage.children)
|
||||
? mainTabPage.children
|
||||
: [mainTabPage.children];
|
||||
|
||||
console.log(`[DockLayout] 初始化主区域面板,共 ${childrenArray.length} 个`);
|
||||
|
||||
for (const panel of childrenArray) {
|
||||
if (panel.type === 'Panel' && panel.id) {
|
||||
panelActions.initializePanelState(panel.id, mainAreaConfig.value.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 轻量级生命周期处理
|
||||
onMounted(() => {
|
||||
// 初始化轻量级状态
|
||||
console.log('DockLayout component mounted');
|
||||
unsubscribeFunctions.value = setupEventListeners();
|
||||
|
||||
// 初始化主区域的面板状态
|
||||
initializeMainAreaPanels();
|
||||
})
|
||||
|
||||
// 组件卸载时清理资源
|
||||
|
||||
@@ -157,6 +157,7 @@ import {
|
||||
onEvent
|
||||
} from './eventBus';
|
||||
import { areaActions, getAreaHandler } from './handlers/AreaHandler';
|
||||
import { panelActions } from './handlers/PanelHandler';
|
||||
|
||||
// 获取AreaHandler实例
|
||||
const areaHandler = getAreaHandler();
|
||||
@@ -850,6 +851,10 @@ onMounted(() => {
|
||||
}, {
|
||||
source: { component: 'Panel', panelId: props.id }
|
||||
});
|
||||
|
||||
// 初始化面板状态
|
||||
console.log(`[Panel:${props.id}] 初始化面板状态,areaId: ${areaId}`);
|
||||
panelActions.initializePanelState(props.id, areaId);
|
||||
}
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
|
||||
@@ -824,6 +824,50 @@ class PanelEventHandler {
|
||||
memoryProtected: !!this.memoryProtection
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化面板状态
|
||||
* @param {string} panelId - 面板ID
|
||||
* @param {string} areaId - 所属区域ID
|
||||
* @param {Object} initialState - 初始状态(可选)
|
||||
* @returns {Object} 初始化后的面板状态
|
||||
*/
|
||||
initializePanelState(panelId, areaId, initialState = {}) {
|
||||
try {
|
||||
// 参数验证
|
||||
if (!panelId || !areaId) {
|
||||
console.error(`[PanelHandler] initializePanelState: 参数错误 - panelId: ${panelId}, areaId: ${areaId}`)
|
||||
return null
|
||||
}
|
||||
|
||||
// 检查是否已存在状态
|
||||
if (this.panelStates.has(panelId)) {
|
||||
console.debug(`[PanelHandler] 面板 ${panelId} 状态已存在,跳过初始化`)
|
||||
return this.panelStates.get(panelId)
|
||||
}
|
||||
|
||||
// 创建初始状态
|
||||
const panelState = {
|
||||
id: panelId,
|
||||
areaId: areaId,
|
||||
closed: false,
|
||||
maximized: false,
|
||||
collapsed: false,
|
||||
toolbarExpanded: true,
|
||||
createdAt: Date.now(),
|
||||
lastModified: Date.now(),
|
||||
...initialState
|
||||
}
|
||||
|
||||
// 存储状态
|
||||
this.panelStates.set(panelId, panelState)
|
||||
console.debug(`[PanelHandler] 面板 ${panelId} 状态初始化完成`)
|
||||
return panelState
|
||||
} catch (error) {
|
||||
console.error(`[PanelHandler] initializePanelState 失败: ${error.message}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 单例实例变量
|
||||
@@ -858,6 +902,7 @@ export const panelActions = {
|
||||
close: (panelId, areaId, options) => panelHandler.close(panelId, areaId, options),
|
||||
requestClose: (panelId, options) => panelHandler.requestClose(panelId, options),
|
||||
toggleToolbar: (panelId, options) => panelHandler.toggleToolbar(panelId, options),
|
||||
initializePanelState: (panelId, areaId, initialState) => panelHandler.initializePanelState(panelId, areaId, initialState),
|
||||
|
||||
// 拖拽操作
|
||||
startDrag: (panelId, event, options) => panelHandler.startDrag(panelId, event, options),
|
||||
|
||||
Reference in New Issue
Block a user