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

69 lines
2.1 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';
import { themeManager } from '../services/theme'; // 修正路径
/**
*
*
*/
export class DialogManager {
/** 弹窗挂载的父容器 */
private container: HTMLElement;
/** 活跃的弹窗实例列表 */
private activeDialogs: BimDialog[] = [];
/**
*
* @param container
*/
constructor(container: HTMLElement) {
this.container = container;
}
/**
*
* @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);
}
});
}
}