Files
bim_engine/src/managers/dialog-manager.ts

88 lines
2.8 KiB
TypeScript
Raw Normal View History

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';
2025-12-08 10:02:24 +08:00
import { themeManager } from '../services/theme';
import { BimComponent } from '../core/component';
import type { BimEngine } from '../bim-engine';
/**
*
*
*/
2025-12-08 10:02:24 +08:00
export class DialogManager extends BimComponent {
/** 弹窗挂载的父容器 */
private container: HTMLElement;
/** 活跃的弹窗实例列表 */
private activeDialogs: BimDialog[] = [];
/**
*
2025-12-08 10:02:24 +08:00
* @param engine
* @param container
*/
2025-12-08 10:02:24 +08:00
constructor(engine: BimEngine, container: HTMLElement) {
super(engine);
this.container = container;
2025-12-08 10:02:24 +08:00
// 监听打开弹窗事件
this.on('ui:open-dialog', (payload) => {
// 这里可以根据 payload.id 做更复杂的逻辑,目前简单演示
console.log('[DialogManager] Received open-dialog event:', payload);
// 示例:如果 payload.id 是 'info',则打开 info dialog
if (payload.id === 'info') {
this.showInfoDialog();
}
});
}
/**
*
* @param options container使
* @returns BimDialog
*/
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() {
// 最佳实践:所有弹窗应通过 create 统一管理,或者手动加入管理。
new BimInfoDialog(this.container);
// 暂时不做主题追踪,作为遗留逻辑保留
}
/**
*
* @param theme
*/
public updateTheme(theme: ThemeConfig) {
this.activeDialogs.forEach(dialog => {
if (dialog.setTheme) {
dialog.setTheme(theme);
}
});
}
2025-12-08 10:02:24 +08:00
public destroy() {
this.activeDialogs.forEach(d => d.destroy());
this.activeDialogs = [];
}
}