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,135 +1,122 @@
import { BimComponent } from '../core/component';
import { BimEngine } from '../bim-engine';
import { BimDialog } from '../components/dialog';
/**
* 轴向剖切对话框管理器
* 负责管理轴向剖切工具对话框的显示、隐藏和剖切面板的交互
*/
import { BaseDialogManager } from '../core/base-dialog-manager';
import { SectionAxisPanel } from '../components/section-axis-panel';
import type { SectionAxis } from '../components/section-axis-panel/types';
/**
* 轴向剖切弹窗管理器
* 轴向剖切对话框管理器
* 继承自 BaseDialogManager提供 X/Y/Z 轴向剖切的对话框管理功能
*/
export class SectionAxisDialogManager extends BimComponent {
private dialogId = 'section-axis-dialog';
private dialog: BimDialog | null = null;
export class SectionAxisDialogManager extends BaseDialogManager {
/** 轴向剖切面板实例 */
private panel: SectionAxisPanel | null = null;
constructor(engine: BimEngine) {
super(engine);
/** 对话框唯一标识 */
protected get dialogId(): string {
return 'section-axis-dialog';
}
public init(): void {
// 可以在这里监听事件
/** 对话框标题(国际化 key */
protected get dialogTitle(): string {
return 'sectionAxis.dialogTitle';
}
/** 对话框宽度 */
protected get dialogWidth(): number {
return 240;
}
/**
* 显示弹窗
* 获取对话框位置
* 定位在容器右下角
*/
public show(): void {
if (!this.engine.dialog || !this.engine.container) {
console.warn('Dialog manager or container is not initialized');
return;
}
protected getDialogPosition(): { x: number; y: number } {
const container = this.registry.container;
if (!container) return { x: 100, y: 100 };
// 如果已打开,先销毁
this.destroy();
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const paddingRight = 20;
const paddingBottom = 50;
// 创建面板
return {
x: containerWidth - this.dialogWidth - paddingRight,
y: containerHeight - paddingBottom - 200
};
}
/**
* 创建对话框内容
* 初始化轴向剖切面板并设置回调
*/
protected createContent(): HTMLElement {
this.panel = new SectionAxisPanel({
defaultAxis: 'x',
defaultHidden: false,
onHideToggle: (isHidden) => {
console.log('[SectionAxisDialogManager] 隐藏切换:', isHidden);
// TODO: 实现隐藏/显示剖切面的逻辑
},
onReverse: () => {
console.log('[SectionAxisDialogManager] 反向剖切');
// TODO: 实现反向剖切的逻辑
},
onAxisChange: (axis) => {
console.log('[SectionAxisDialogManager] 切换轴向:', axis);
// TODO: 实现轴向切换的逻辑
}
});
this.panel.init();
return this.panel.element;
}
// 创建弹窗
const dialogWidth = 240;
const paddingRight = 20;
const paddingBottom = 50;
const container = this.engine.container;
const containerWidth = container.clientWidth;
const containerHeight = container.clientHeight;
const x = containerWidth - dialogWidth - paddingRight;
const y = containerHeight - paddingBottom - 200; // 临时y值会被fitHeight调整
/** 对话框创建后的回调,自适应高度 */
protected onDialogCreated(): void {
this.dialog?.fitHeight(false);
}
this.dialog = this.engine.dialog.create({
id: this.dialogId,
title: 'sectionAxis.dialogTitle',
width: dialogWidth,
height: 'auto', // 自动高度
position: { x, y },
draggable: true,
resizable: false,
content: this.panel.element,
onClose: () => {
this.engine.toolbar?.setBtnActive('section-axis', false);
this.hide();
}
});
this.dialog.init();
/** 对话框关闭时的回调,取消工具栏按钮激活状态 */
protected onDialogClose(): void {
this.registry.toolbar?.setBtnActive('section-axis', false);
}
// 自适应高度
this.dialog.fitHeight(false);
/** 销毁前的清理,销毁面板实例 */
protected onBeforeDestroy(): void {
if (this.panel) {
this.panel.destroy();
this.panel = null;
}
}
/**
* 隐藏弹窗
*/
public hide(): void {
this.destroy();
}
/**
* 获取隐藏状态
* 获取剖切面隐藏状态
* @returns 是否隐藏
*/
public getHiddenState(): boolean {
return this.panel?.getHiddenState() ?? false;
}
/**
* 设置隐藏状态
* 设置剖切面隐藏状态
* @param isHidden 是否隐藏
*/
public setHiddenState(isHidden: boolean): void {
this.panel?.setHiddenState(isHidden);
}
/**
* 获取当前激活的轴向
* 获取当前激活的剖切轴向
* @returns 当前轴向 'x' | 'y' | 'z'
*/
public getActiveAxis(): SectionAxis {
return this.panel?.getActiveAxis() ?? 'x';
}
/**
* 设置激活的轴向
* 设置剖切轴向
* @param axis 目标轴向
*/
public setActiveAxis(axis: SectionAxis): void {
this.panel?.setActiveAxis(axis);
}
/**
* 销毁弹窗和面板
*/
public destroy(): void {
// 关闭弹窗
if (this.dialog) {
this.dialog.destroy();
this.dialog = null;
}
// 销毁面板
if (this.panel) {
this.panel.destroy();
this.panel = null;
}
}
}