- 新增 ManagerRegistry 单例注册表,统一管理所有 Manager 实例 - 新增 BaseManager 基类,自动管理事件订阅清理 - 新增 BaseDialogManager 基类,统一对话框生命周期管理 - 重构 15 个 Manager 使用新基类 - 重构 Toolbar 按钮和 Menu 按钮移除 engine 参数依赖 - 删除 BimComponent 基类(已不再使用) - 为所有 Manager 和核心模块添加中文 JSDoc 注释
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
/**
|
|
* 对话框管理器
|
|
* 负责创建和管理所有对话框实例
|
|
*/
|
|
import { BimDialog } from '../components/dialog';
|
|
import { BimInfoDialog } from '../components/dialog/bimInfoDialog';
|
|
import type { DialogOptions } from '../components/dialog/index.type';
|
|
import type { ThemeConfig } from '../themes/types';
|
|
import { themeManager } from '../services/theme';
|
|
import { BaseManager } from '../core/base-manager';
|
|
|
|
/**
|
|
* 对话框管理器
|
|
* 统一管理对话框的创建、主题更新和销毁
|
|
*/
|
|
export class DialogManager extends BaseManager {
|
|
/** 容器元素 */
|
|
private container: HTMLElement;
|
|
/** 活跃的对话框列表 */
|
|
private activeDialogs: BimDialog[] = [];
|
|
|
|
constructor(container: HTMLElement) {
|
|
super();
|
|
this.container = container;
|
|
|
|
this.subscribe('ui:open-dialog', (payload) => {
|
|
console.log('[DialogManager] Received open-dialog event:', payload);
|
|
if (payload.id === 'info') {
|
|
this.showInfoDialog();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 创建对话框
|
|
* @param options 对话框配置选项
|
|
* @returns 对话框实例
|
|
*/
|
|
public create(options: Omit<DialogOptions, 'container'>): BimDialog {
|
|
const dialog = new BimDialog({
|
|
container: this.container,
|
|
...options,
|
|
onClose: () => {
|
|
this.activeDialogs = this.activeDialogs.filter(d => d !== dialog);
|
|
if (options.onClose) options.onClose();
|
|
}
|
|
});
|
|
|
|
dialog.setTheme(themeManager.getTheme());
|
|
this.activeDialogs.push(dialog);
|
|
return dialog;
|
|
}
|
|
|
|
/** 显示信息对话框 */
|
|
public showInfoDialog() {
|
|
new BimInfoDialog(this.container);
|
|
}
|
|
|
|
/**
|
|
* 更新所有对话框的主题
|
|
* @param theme 主题配置
|
|
*/
|
|
public updateTheme(theme: ThemeConfig) {
|
|
this.activeDialogs.forEach(dialog => {
|
|
if (dialog.setTheme) {
|
|
dialog.setTheme(theme);
|
|
}
|
|
});
|
|
}
|
|
|
|
/** 销毁管理器和所有对话框 */
|
|
public destroy() {
|
|
this.activeDialogs.forEach(d => d.destroy());
|
|
this.activeDialogs = [];
|
|
super.destroy();
|
|
}
|
|
}
|