2026-01-22 15:23:57 +08:00
|
|
|
/**
|
|
|
|
|
* 对话框管理器
|
|
|
|
|
* 负责创建和管理所有对话框实例
|
|
|
|
|
*/
|
2025-12-04 15:24:44 +08:00
|
|
|
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';
|
2026-01-22 15:23:57 +08:00
|
|
|
import { BaseManager } from '../core/base-manager';
|
2025-12-04 15:24:44 +08:00
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
* 对话框管理器
|
|
|
|
|
* 统一管理对话框的创建、主题更新和销毁
|
2025-12-04 15:24:44 +08:00
|
|
|
*/
|
2026-01-22 15:23:57 +08:00
|
|
|
export class DialogManager extends BaseManager {
|
|
|
|
|
/** 容器元素 */
|
2025-12-04 15:24:44 +08:00
|
|
|
private container: HTMLElement;
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 活跃的对话框列表 */
|
2025-12-04 15:24:44 +08:00
|
|
|
private activeDialogs: BimDialog[] = [];
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
constructor(container: HTMLElement) {
|
|
|
|
|
super();
|
2025-12-04 15:24:44 +08:00
|
|
|
this.container = container;
|
2025-12-08 10:02:24 +08:00
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
this.subscribe('ui:open-dialog', (payload) => {
|
2025-12-08 10:02:24 +08:00
|
|
|
console.log('[DialogManager] Received open-dialog event:', payload);
|
|
|
|
|
if (payload.id === 'info') {
|
|
|
|
|
this.showInfoDialog();
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-12-04 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
* 创建对话框
|
|
|
|
|
* @param options 对话框配置选项
|
|
|
|
|
* @returns 对话框实例
|
2025-12-04 15:24:44 +08:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 显示信息对话框 */
|
2025-12-04 15:24:44 +08:00
|
|
|
public showInfoDialog() {
|
|
|
|
|
new BimInfoDialog(this.container);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
* 更新所有对话框的主题
|
|
|
|
|
* @param theme 主题配置
|
2025-12-04 15:24:44 +08:00
|
|
|
*/
|
|
|
|
|
public updateTheme(theme: ThemeConfig) {
|
|
|
|
|
this.activeDialogs.forEach(dialog => {
|
|
|
|
|
if (dialog.setTheme) {
|
|
|
|
|
dialog.setTheme(theme);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-08 10:02:24 +08:00
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 销毁管理器和所有对话框 */
|
2025-12-08 10:02:24 +08:00
|
|
|
public destroy() {
|
|
|
|
|
this.activeDialogs.forEach(d => d.destroy());
|
|
|
|
|
this.activeDialogs = [];
|
2026-01-22 15:23:57 +08:00
|
|
|
super.destroy();
|
2025-12-08 10:02:24 +08:00
|
|
|
}
|
2025-12-22 18:48:38 +08:00
|
|
|
}
|