全部用静态导入
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* 专门处理Area相关的所有事件,包括浮动区域管理、拖拽、停靠、合并等
|
||||
*/
|
||||
|
||||
import { eventBus } from '../eventBus.js';
|
||||
import { eventBus } from '../eventBus';
|
||||
|
||||
// Area事件类型常量
|
||||
export const AREA_EVENT_TYPES = {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* 统一管理所有组件的拖拽状态,提供拖拽历史、性能监控、冲突检测等功能
|
||||
*/
|
||||
|
||||
import { eventBus } from '../eventBus.js';
|
||||
import { GLOBAL_EVENT_TYPES, globalEventActions } from './GlobalEventManager.js';
|
||||
import { eventBus } from '../eventBus';
|
||||
import { GLOBAL_EVENT_TYPES, globalEventActions } from './GlobalEventManager';
|
||||
|
||||
// 拖拽状态类型
|
||||
export const DRAG_STATE_TYPES = {
|
||||
@@ -520,6 +520,11 @@ class DragStateManager {
|
||||
* 注册事件监听器
|
||||
*/
|
||||
_registerEventListeners() {
|
||||
// 防止重复注册监听器
|
||||
if (this.eventListenersRegistered) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dragEvents = [
|
||||
// Panel拖拽事件
|
||||
'panel.drag.start', 'panel.drag.move', 'panel.drag.end', 'panel.drag.cancel',
|
||||
@@ -535,6 +540,36 @@ class DragStateManager {
|
||||
deduplication: { type: 'EVENT_BASED', key: 'dragState' }
|
||||
});
|
||||
});
|
||||
|
||||
this.eventListenersRegistered = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁管理器
|
||||
*/
|
||||
destroy() {
|
||||
// 清理事件监听器
|
||||
const dragEvents = [
|
||||
// Panel拖拽事件
|
||||
'panel.drag.start', 'panel.drag.move', 'panel.drag.end', 'panel.drag.cancel',
|
||||
// TabPage拖拽事件
|
||||
'tabpage.drag.start', 'tabpage.drag.move', 'tabpage.drag.end', 'tabpage.drag.cancel',
|
||||
// Area拖拽事件
|
||||
'area.drag.start', 'area.drag.move', 'area.drag.end', 'area.drag.cancel'
|
||||
];
|
||||
|
||||
dragEvents.forEach(eventType => {
|
||||
eventBus.off(eventType, this._onDragEvent);
|
||||
});
|
||||
|
||||
// 清理清理调度器
|
||||
this._stopCleanupScheduler();
|
||||
|
||||
// 清理拖拽状态
|
||||
this.dragStates.clear();
|
||||
this.dragHistory = [];
|
||||
|
||||
console.log('🗑️ 拖拽状态管理器已销毁');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
* 统一管理所有事件处理器和功能模块
|
||||
*/
|
||||
|
||||
import { eventBus, eventBusActions, EVENT_TYPES } from '../eventBus.js';
|
||||
import { panelHandler, PANEL_EVENT_TYPES, panelActions } from './PanelHandler.js';
|
||||
import tabPageHandler, { TABPAGE_EVENT_TYPES, tabPageActions } from './TabPageHandler.js';
|
||||
import areaHandler, { AREA_EVENT_TYPES, areaActions } from './AreaHandler.js';
|
||||
import globalEventManager, { GLOBAL_EVENT_TYPES, globalEventActions } from './GlobalEventManager.js';
|
||||
import dragStateManager, { DRAG_STATE_TYPES, dragStateActions } from './DragStateManager.js';
|
||||
import integrationTester, { testActions, TEST_CONFIG } from './IntegrationTester.js';
|
||||
import { eventBus, eventBusActions, EVENT_TYPES } from '../eventBus';
|
||||
import { panelHandler, PANEL_EVENT_TYPES, panelActions } from './PanelHandler';
|
||||
import tabPageHandler, { TABPAGE_EVENT_TYPES, tabPageActions } from './TabPageHandler';
|
||||
import areaHandler, { AREA_EVENT_TYPES, areaActions } from './AreaHandler';
|
||||
import globalEventManager, { GLOBAL_EVENT_TYPES, globalEventActions } from './GlobalEventManager';
|
||||
import dragStateManager, { DRAG_STATE_TYPES, dragStateActions } from './DragStateManager';
|
||||
import integrationTester, { testActions, TEST_CONFIG } from './IntegrationTester';
|
||||
|
||||
// 事件总线配置
|
||||
export const EVENT_BUS_CONFIG = {
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
* 统一管理所有事件处理器,提供事件路由、分发、监控和调试功能
|
||||
*/
|
||||
|
||||
import { eventBus } from '../eventBus.js';
|
||||
import { panelHandler, PANEL_EVENT_TYPES, panelActions } from './PanelHandler.js';
|
||||
import tabPageHandler, { TABPAGE_EVENT_TYPES, tabPageActions } from './TabPageHandler.js';
|
||||
import areaHandler, { AREA_EVENT_TYPES, areaActions } from './AreaHandler.js';
|
||||
import { eventBus } from '../eventBus';
|
||||
import { PANEL_EVENT_TYPES, panelActions, panelHandler } from './PanelHandler';
|
||||
import tabPageHandlerModule, { TABPAGE_EVENT_TYPES, tabPageActions } from './TabPageHandler';
|
||||
import areaHandlerModule, { AREA_EVENT_TYPES, areaActions } from './AreaHandler';
|
||||
|
||||
// 获取处理器实例
|
||||
const tabPageHandler = tabPageHandlerModule.getInstance ? tabPageHandlerModule.getInstance() : tabPageHandlerModule;
|
||||
const areaHandler = areaHandlerModule;
|
||||
|
||||
// 全局事件类型常量
|
||||
export const GLOBAL_EVENT_TYPES = {
|
||||
@@ -305,21 +309,17 @@ class GlobalEventManager {
|
||||
this.crossComponentChannels = new Map();
|
||||
this.isInitialized = false;
|
||||
this.eventListenersRegistered = false;
|
||||
this.componentListenersRegistered = false;
|
||||
this.debugMode = false;
|
||||
|
||||
// 处理器映射
|
||||
this.handlerMap = {
|
||||
panelHandler,
|
||||
tabPageHandler,
|
||||
areaHandler
|
||||
};
|
||||
this.handlerMap = {};
|
||||
this.eventListenerUnsubscribers = [];
|
||||
|
||||
// 绑定方法
|
||||
this._onGlobalEvent = this._onGlobalEvent.bind(this);
|
||||
this._onSystemError = this._handleSystemError.bind(this);
|
||||
this._cleanupExpiredData = this._cleanupExpiredData.bind(this);
|
||||
|
||||
this._initialize();
|
||||
// 延迟初始化,先不调用_initialize()
|
||||
|
||||
// 保存实例到静态属性
|
||||
GlobalEventManager.instance = this;
|
||||
@@ -328,13 +328,20 @@ class GlobalEventManager {
|
||||
/**
|
||||
* 初始化事件管理器
|
||||
*/
|
||||
_initialize() {
|
||||
async _initialize() {
|
||||
// 防止重复初始化
|
||||
if (this.isInitialized) {
|
||||
console.warn('⚠️ 全局事件管理器已初始化,跳过重复初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
// 初始化处理器映射
|
||||
this.handlerMap = {
|
||||
panelHandler,
|
||||
tabPageHandler,
|
||||
areaHandler
|
||||
};
|
||||
|
||||
// 注册全局事件监听器
|
||||
this._registerGlobalEventListeners();
|
||||
|
||||
@@ -367,10 +374,11 @@ class GlobalEventManager {
|
||||
|
||||
const globalEvents = Object.values(GLOBAL_EVENT_TYPES);
|
||||
globalEvents.forEach(eventType => {
|
||||
eventBus.on(eventType, this._onGlobalEvent, {
|
||||
const unsubscribe = eventBus.on(eventType, this._onGlobalEvent, {
|
||||
priority: 0, // 最高优先级
|
||||
deduplication: { type: 'TTL_BASED', ttl: 50 }
|
||||
});
|
||||
this.eventListenerUnsubscribers.push(unsubscribe);
|
||||
});
|
||||
|
||||
// 注册所有组件事件监听器
|
||||
@@ -384,26 +392,30 @@ class GlobalEventManager {
|
||||
* 注册组件事件监听器
|
||||
*/
|
||||
_registerComponentEventListeners() {
|
||||
// 防止重复注册组件事件监听器
|
||||
if (this.componentListenersRegistered) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Panel事件监听
|
||||
Object.values(PANEL_EVENT_TYPES).forEach(eventType => {
|
||||
eventBus.on(eventType, (data) => {
|
||||
this._routeEvent(eventType, data, 'panel');
|
||||
}, { priority: 1 });
|
||||
const unsubscribe = eventBus.on(eventType, this._routeEvent.bind(this, eventType, null, 'panel'), { priority: 1 });
|
||||
this.eventListenerUnsubscribers.push(unsubscribe);
|
||||
});
|
||||
|
||||
// TabPage事件监听
|
||||
Object.values(TABPAGE_EVENT_TYPES).forEach(eventType => {
|
||||
eventBus.on(eventType, (data) => {
|
||||
this._routeEvent(eventType, data, 'tabPage');
|
||||
}, { priority: 1 });
|
||||
const unsubscribe = eventBus.on(eventType, this._routeEvent.bind(this, eventType, null, 'tabPage'), { priority: 1 });
|
||||
this.eventListenerUnsubscribers.push(unsubscribe);
|
||||
});
|
||||
|
||||
// Area事件监听
|
||||
Object.values(AREA_EVENT_TYPES).forEach(eventType => {
|
||||
eventBus.on(eventType, (data) => {
|
||||
this._routeEvent(eventType, data, 'area');
|
||||
}, { priority: 1 });
|
||||
const unsubscribe = eventBus.on(eventType, this._routeEvent.bind(this, eventType, null, 'area'), { priority: 1 });
|
||||
this.eventListenerUnsubscribers.push(unsubscribe);
|
||||
});
|
||||
|
||||
this.componentListenersRegistered = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1022,8 +1034,15 @@ class GlobalEventManager {
|
||||
* 销毁事件管理器
|
||||
*/
|
||||
destroy() {
|
||||
// 清理所有事件监听器,包括全局事件和组件事件
|
||||
eventBus.clear();
|
||||
// 清理自己注册的所有事件监听器
|
||||
this.eventListenerUnsubscribers.forEach(unsubscribe => {
|
||||
try {
|
||||
unsubscribe();
|
||||
} catch (error) {
|
||||
console.warn('清理监听器时出错:', error);
|
||||
}
|
||||
});
|
||||
this.eventListenerUnsubscribers = [];
|
||||
|
||||
// 销毁各个处理器
|
||||
Object.values(this.handlerMap).forEach(handler => {
|
||||
@@ -1041,6 +1060,7 @@ class GlobalEventManager {
|
||||
|
||||
this.isInitialized = false;
|
||||
this.eventListenersRegistered = false;
|
||||
this.componentListenersRegistered = false;
|
||||
console.log('🗑️ 全局事件管理器已销毁,所有监听器已清理');
|
||||
}
|
||||
}
|
||||
@@ -1150,17 +1170,20 @@ export const globalEventActions = {
|
||||
/**
|
||||
* 确保单例实例存在
|
||||
*/
|
||||
function ensureInstance() {
|
||||
async function ensureInstance() {
|
||||
if (!globalEventManager) {
|
||||
globalEventManager = new GlobalEventManager();
|
||||
// 异步初始化
|
||||
await globalEventManager._initialize();
|
||||
} else if (!globalEventManager.isInitialized) {
|
||||
// 如果实例存在但未初始化,完成初始化
|
||||
await globalEventManager._initialize();
|
||||
}
|
||||
return globalEventManager;
|
||||
}
|
||||
|
||||
// 导出单例实例访问方法
|
||||
export const getGlobalEventManager = () => {
|
||||
return ensureInstance();
|
||||
};
|
||||
export const getGlobalEventManager = ensureInstance;
|
||||
|
||||
// 导出事件管理器和相关API
|
||||
export default {
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
* 对所有事件处理器进行集成测试、性能监控和优化建议
|
||||
*/
|
||||
|
||||
import { eventBus } from '../eventBus.js';
|
||||
import { panelHandler, PANEL_EVENT_TYPES } from './PanelHandler.js';
|
||||
import tabPageHandler, { TABPAGE_EVENT_TYPES } from './TabPageHandler.js';
|
||||
import areaHandler, { AREA_EVENT_TYPES } from './AreaHandler.js';
|
||||
import globalEventManager, { GLOBAL_EVENT_TYPES, globalEventActions } from './GlobalEventManager.js';
|
||||
import dragStateManager, { DRAG_STATE_TYPES, dragStateActions } from './DragStateManager.js';
|
||||
import { eventBus } from '../eventBus';
|
||||
import { panelHandler, PANEL_EVENT_TYPES } from './PanelHandler';
|
||||
import tabPageHandler, { TABPAGE_EVENT_TYPES } from './TabPageHandler';
|
||||
import areaHandler, { AREA_EVENT_TYPES } from './AreaHandler';
|
||||
import globalEventManager, { GLOBAL_EVENT_TYPES, globalEventActions } from './GlobalEventManager';
|
||||
import dragStateManager, { DRAG_STATE_TYPES, dragStateActions } from './DragStateManager';
|
||||
|
||||
// 测试配置
|
||||
export const TEST_CONFIG = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { emitEvent, onEvent, onceEvent, registerHandler, unregisterHandler, getHandlerSnapshot } from '../eventBus.js'
|
||||
import { emitEvent, onEvent, onceEvent, registerHandler, unregisterHandler, getHandlerSnapshot } from '../eventBus'
|
||||
import { nanoid } from 'nanoid'
|
||||
|
||||
// Panel事件类型常量
|
||||
@@ -788,8 +788,28 @@ class PanelEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// 单例实例变量
|
||||
let panelHandler = null;
|
||||
|
||||
/**
|
||||
* 确保单例实例存在
|
||||
* @returns {PanelEventHandler} PanelEventHandler实例
|
||||
*/
|
||||
function ensureInstance() {
|
||||
if (!panelHandler) {
|
||||
panelHandler = new PanelEventHandler();
|
||||
}
|
||||
return panelHandler;
|
||||
}
|
||||
|
||||
// 导出单例实例访问方法
|
||||
export const getPanelHandler = ensureInstance;
|
||||
|
||||
// 创建全局Panel事件处理器实例
|
||||
export const panelHandler = new PanelEventHandler()
|
||||
const panelHandlerInstance = ensureInstance();
|
||||
|
||||
// 导出事件处理器实例
|
||||
export { panelHandlerInstance as panelHandler };
|
||||
|
||||
// 便捷的操作函数
|
||||
export const panelActions = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 专门处理TabPage相关的所有事件,包括标签页拖拽、切换、关闭、激活等
|
||||
*/
|
||||
|
||||
import { eventBus } from '../eventBus.js';
|
||||
import { eventBus } from '../eventBus';
|
||||
|
||||
// TabPage事件类型常量
|
||||
export const TABPAGE_EVENT_TYPES = {
|
||||
@@ -577,8 +577,19 @@ class TabPageEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建单例实例
|
||||
const tabPageHandler = new TabPageEventHandler();
|
||||
// 单例实例变量
|
||||
let tabPageHandler = null;
|
||||
|
||||
/**
|
||||
* 确保单例实例存在
|
||||
* @returns {TabPageEventHandler} TabPageEventHandler实例
|
||||
*/
|
||||
function ensureInstance() {
|
||||
if (!tabPageHandler) {
|
||||
tabPageHandler = new TabPageEventHandler();
|
||||
}
|
||||
return tabPageHandler;
|
||||
}
|
||||
|
||||
// TabPage便捷操作函数
|
||||
export const tabPageActions = {
|
||||
@@ -678,7 +689,8 @@ export const tabPageActions = {
|
||||
* @param {Object} updates - 状态更新
|
||||
*/
|
||||
updateState: (tabPageId, updates) => {
|
||||
tabPageHandler.tabPageStateManager.updateState(tabPageId, updates);
|
||||
const instance = ensureInstance();
|
||||
instance.tabPageStateManager.updateState(tabPageId, updates);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -700,7 +712,10 @@ export const tabPageActions = {
|
||||
};
|
||||
|
||||
// 导出事件处理器和相关API
|
||||
export default tabPageHandler;
|
||||
export default {
|
||||
getInstance: ensureInstance,
|
||||
actions: tabPageActions
|
||||
};
|
||||
|
||||
// 便利的TabPage拖拽处理函数
|
||||
export const triggerTabPageDrag = {
|
||||
|
||||
Reference in New Issue
Block a user