92 lines
2.5 KiB
TypeScript
92 lines
2.5 KiB
TypeScript
import type { IDestroyable } from '@/common/types/IDestroyable'
|
|
import type { WindowState } from '@/services/WindowService'
|
|
import type { ResourceType } from '@/services/ResourceService'
|
|
|
|
/**
|
|
* 窗体数据更新参数
|
|
*/
|
|
export interface WindowFormDataUpdateParams {
|
|
/** 窗口id */
|
|
id: string
|
|
/** 窗口状态 */
|
|
state: WindowState
|
|
/** 窗口宽度 */
|
|
width: number
|
|
/** 窗口高度 */
|
|
height: number
|
|
/** 窗口x坐标(左上角) */
|
|
x: number
|
|
/** 窗口y坐标(左上角) */
|
|
y: number
|
|
}
|
|
|
|
/**
|
|
* 事件定义
|
|
* @interface IEventMap 事件定义 键是事件名称,值是事件处理函数
|
|
*/
|
|
export interface IEventMap {
|
|
// 系统就绪事件
|
|
onSystemReady: (data: { timestamp: Date; services: string[] }) => void
|
|
|
|
// 窗体相关事件
|
|
onWindowStateChanged: (windowId: string, newState: string, oldState: string) => void
|
|
onWindowFormDataUpdate: (data: WindowFormDataUpdateParams) => void
|
|
onWindowFormResizeStart: (windowId: string) => void
|
|
onWindowFormResizing: (windowId: string, width: number, height: number) => void
|
|
onWindowFormResizeEnd: (windowId: string) => void
|
|
onWindowClose: (windowId: string) => void
|
|
|
|
// 应用生命周期事件
|
|
onAppLifecycle: (data: { appId: string; event: string; timestamp: Date }) => void
|
|
|
|
// 资源相关事件
|
|
onResourceQuotaExceeded: (appId: string, resourceType: ResourceType) => void
|
|
onPerformanceAlert: (data: { type: 'memory' | 'cpu'; usage: number; limit: number }) => void
|
|
|
|
/**
|
|
* 事件处理函数映射
|
|
*/
|
|
[key: string]: (...args: any[]) => void
|
|
}
|
|
|
|
/**
|
|
* 事件管理器接口定义
|
|
*/
|
|
export interface IEventBuilder<Events extends IEventMap> extends IDestroyable {
|
|
/**
|
|
* 添加事件监听
|
|
* @param eventName 事件名称
|
|
* @param handler 事件处理函数
|
|
* @param options 配置项 { immediate: 立即执行一次 immediateArgs: 立即执行的参数 once: 只监听一次 }
|
|
* @returns void
|
|
*/
|
|
addEventListener<E extends keyof Events, F extends Events[E]>(
|
|
eventName: E,
|
|
handler: F,
|
|
options?: {
|
|
immediate?: boolean
|
|
immediateArgs?: Parameters<F>
|
|
once?: boolean
|
|
}
|
|
): void
|
|
|
|
/**
|
|
* 移除事件监听
|
|
* @param eventName 事件名称
|
|
* @param handler 事件处理函数
|
|
* @returns void
|
|
*/
|
|
removeEventListener<E extends keyof Events, F extends Events[E]>(eventName: E, handler: F): void
|
|
|
|
/**
|
|
* 触发事件
|
|
* @param eventName 事件名称
|
|
* @param args 参数
|
|
* @returns void
|
|
*/
|
|
notifyEvent<E extends keyof Events, F extends Events[E]>(
|
|
eventName: E,
|
|
...args: Parameters<F>
|
|
): void
|
|
}
|