refactor: 重构 Manager 架构,引入 ManagerRegistry 和 BaseManager 基类

- 新增 ManagerRegistry 单例注册表,统一管理所有 Manager 实例
- 新增 BaseManager 基类,自动管理事件订阅清理
- 新增 BaseDialogManager 基类,统一对话框生命周期管理
- 重构 15 个 Manager 使用新基类
- 重构 Toolbar 按钮和 Menu 按钮移除 engine 参数依赖
- 删除 BimComponent 基类(已不再使用)
- 为所有 Manager 和核心模块添加中文 JSDoc 注释
This commit is contained in:
yuding
2026-01-22 15:23:57 +08:00
parent f2460fb981
commit 31b60e84ce
47 changed files with 5580 additions and 5341 deletions

View File

@@ -1,26 +1,32 @@
/**
* 工具栏管理器
* 负责管理底部工具栏的创建、按钮配置和显示控制
*/
import type { ButtonGroupColors, ButtonConfig } from '../components/button-group/index.type';
import { Toolbar } from '../components/button-group/toolbar';
import type { ThemeConfig } from '../themes/types';
import { BimComponent } from '../core/component';
import type { BimEngine } from '../bim-engine';
import { BaseManager } from '../core/base-manager';
/**
* 底部工具栏管理器 (ToolbarManager)
* 仅负责管理底部工具栏实例。
* 工具栏管理器
* 提供工具栏按钮的添加、显示/隐藏、主题更新等功能
*/
export class ToolbarManager extends BimComponent {
export class ToolbarManager extends BaseManager {
/** 工具栏实例 */
private toolbar: Toolbar | null = null;
/** 工具栏容器元素 */
private toolbarContainer: HTMLElement | null = null;
/** 主容器元素 */
private container: HTMLElement;
constructor(engine: BimEngine, container: HTMLElement) {
super(engine);
constructor(container: HTMLElement) {
super();
this.container = container;
this.init();
}
/** 初始化工具栏 */
private init() {
// 创建底部工具栏专用容器
this.toolbarContainer = document.createElement('div');
this.toolbarContainer.id = 'opt-btn-groups';
this.toolbarContainer.className = 'bim-engine-opt-btn-container is-bottom-toolbar';
@@ -36,52 +42,108 @@ export class ToolbarManager extends BimComponent {
expand: 'up'
});
// 注入 engine 到 Toolbar
// @ts-ignore - Toolbar 还没更新类型,暂时忽略
this.toolbar.setEngine(this.engine);
this.toolbar.init();
}
/**
* 更新工具栏主题
* @param theme 主题配置
*/
public updateTheme(theme: ThemeConfig) {
this.toolbar?.setTheme(theme);
}
/** 刷新工具栏渲染 */
public refresh() {
this.toolbar?.render();
}
/** 销毁工具栏 */
public destroy() {
this.toolbar?.destroy();
this.toolbar = null;
super.destroy();
}
// --- 转发 API ---
public addGroup(groupId: string, beforeGroupId?: string) { this.toolbar?.addGroup(groupId, beforeGroupId); this.toolbar?.render(); }
public addButton(config: ButtonConfig) { this.toolbar?.addButton(config); this.toolbar?.render(); }
public setButtonVisibility(id: string, v: boolean) { this.toolbar?.updateButtonVisibility(id, v); }
public setShowLabel(show: boolean) { this.toolbar?.setShowLabel(show); }
public setBtnActive(id: string, active?: boolean) { this.toolbar?.setBtnActive(id, active); }
/**
* 添加按钮组
* @param groupId 组 ID
* @param beforeGroupId 插入到指定组之前
*/
public addGroup(groupId: string, beforeGroupId?: string) {
this.toolbar?.addGroup(groupId, beforeGroupId);
this.toolbar?.render();
}
/**
* 添加按钮
* @param config 按钮配置
*/
public addButton(config: ButtonConfig) {
this.toolbar?.addButton(config);
this.toolbar?.render();
}
/**
* 设置按钮可见性
* @param id 按钮 ID
* @param v 是否可见
*/
public setButtonVisibility(id: string, v: boolean) {
this.toolbar?.updateButtonVisibility(id, v);
}
/**
* 设置是否显示标签
* @param show 是否显示
*/
public setShowLabel(show: boolean) {
this.toolbar?.setShowLabel(show);
}
/**
* 设置按钮激活状态
* @param id 按钮 ID
* @param active 是否激活
*/
public setBtnActive(id: string, active?: boolean) {
this.toolbar?.setBtnActive(id, active);
}
/**
* 设置工具栏可见性
* @param visible 是否可见
*/
public setVisible(visible: boolean) {
if (this.toolbarContainer) {
this.toolbarContainer.style.visibility = visible ? 'visible' : 'hidden';
}
}
public setBackgroundColor(color: string) { this.toolbar?.setBackgroundColor(color); }
public setColors(colors: ButtonGroupColors) { this.toolbar?.setColors(colors); }
/**
* 隐藏工具栏
* 设置背景颜色
* @param color 颜色值
*/
public setBackgroundColor(color: string) {
this.toolbar?.setBackgroundColor(color);
}
/**
* 设置按钮组颜色
* @param colors 颜色配置
*/
public setColors(colors: ButtonGroupColors) {
this.toolbar?.setColors(colors);
}
/** 隐藏工具栏 */
public hide(): void {
if (this.toolbarContainer) {
this.toolbarContainer.style.display = 'none';
}
}
/**
* 显示工具栏
*/
/** 显示工具栏 */
public show(): void {
if (this.toolbarContainer) {
this.toolbarContainer.style.display = '';
@@ -90,6 +152,7 @@ export class ToolbarManager extends BimComponent {
/**
* 获取工具栏容器
* @returns 容器元素
*/
public getContainer(): HTMLElement | null {
return this.toolbarContainer;