refactor: 重构 Manager 架构,引入 ManagerRegistry 和 BaseManager 基类
- 新增 ManagerRegistry 单例注册表,统一管理所有 Manager 实例 - 新增 BaseManager 基类,自动管理事件订阅清理 - 新增 BaseDialogManager 基类,统一对话框生命周期管理 - 重构 15 个 Manager 使用新基类 - 重构 Toolbar 按钮和 Menu 按钮移除 engine 参数依赖 - 删除 BimComponent 基类(已不再使用) - 为所有 Manager 和核心模块添加中文 JSDoc 注释
This commit is contained in:
@@ -1,94 +1,64 @@
|
||||
import { BimComponent } from '../core/component';
|
||||
import { BimEngine } from '../bim-engine';
|
||||
import { BimDialog } from '../components/dialog';
|
||||
/**
|
||||
* 漫游路径对话框管理器
|
||||
* 负责管理漫游路径设置对话框的显示和交互
|
||||
*/
|
||||
import { BaseDialogManager } from '../core/base-dialog-manager';
|
||||
import { WalkPathPanel } from '../components/walk-path-panel';
|
||||
|
||||
/**
|
||||
* 路径漫游弹窗管理器
|
||||
* 漫游路径对话框管理器
|
||||
* 继承自 BaseDialogManager,提供漫游路径配置的对话框管理功能
|
||||
*/
|
||||
export class WalkPathDialogManager extends BimComponent {
|
||||
private dialogId = 'walk-path-dialog';
|
||||
private dialog: BimDialog | null = null;
|
||||
export class WalkPathDialogManager extends BaseDialogManager {
|
||||
/** 漫游路径面板实例 */
|
||||
private panel: WalkPathPanel | null = null;
|
||||
|
||||
constructor(engine: BimEngine) {
|
||||
super(engine);
|
||||
}
|
||||
/** 对话框唯一标识 */
|
||||
protected get dialogId() { return 'walk-path-dialog'; }
|
||||
/** 对话框标题(国际化 key) */
|
||||
protected get dialogTitle() { return 'walkControl.path.dialogTitle'; }
|
||||
/** 对话框宽度 */
|
||||
protected get dialogWidth() { return 300; }
|
||||
/** 对话框高度 */
|
||||
protected get dialogHeight(): number { return 400; }
|
||||
|
||||
public init(): void {
|
||||
// 可以在这里监听事件
|
||||
}
|
||||
/** 初始化 */
|
||||
public init(): void {}
|
||||
|
||||
/**
|
||||
* 显示弹窗
|
||||
* 获取对话框位置
|
||||
* 定位在容器右侧居中
|
||||
*/
|
||||
public show(): void {
|
||||
if (!this.engine.dialog || !this.engine.container) {
|
||||
console.warn('Dialog manager or container is not initialized');
|
||||
return;
|
||||
}
|
||||
protected getDialogPosition() {
|
||||
const container = this.registry.container;
|
||||
if (!container) return { x: 100, y: 100 };
|
||||
|
||||
// 如果已打开,先销毁
|
||||
this.destroy();
|
||||
const paddingRight = 20;
|
||||
const containerWidth = container.clientWidth;
|
||||
const containerHeight = container.clientHeight;
|
||||
|
||||
// 创建面板(暂时空内容)
|
||||
return {
|
||||
x: containerWidth - this.dialogWidth - paddingRight,
|
||||
y: (containerHeight - this.dialogHeight) / 2
|
||||
};
|
||||
}
|
||||
|
||||
/** 创建对话框内容 */
|
||||
protected createContent(): HTMLElement {
|
||||
this.panel = new WalkPathPanel();
|
||||
this.panel.init();
|
||||
|
||||
const dialogWidth = 300;
|
||||
const dialogHeight = 400;
|
||||
const paddingRight = 20;
|
||||
const container = this.engine.container;
|
||||
const containerHeight = container.clientHeight;
|
||||
const containerWidth = container.clientWidth;
|
||||
|
||||
// 右边中间:right: 20px, 垂直居中
|
||||
const x = containerWidth - dialogWidth - paddingRight;
|
||||
const y = (containerHeight - dialogHeight) / 2;
|
||||
|
||||
this.dialog = this.engine.dialog.create({
|
||||
id: this.dialogId,
|
||||
title: 'walkControl.path.dialogTitle',
|
||||
width: dialogWidth,
|
||||
height: dialogHeight,
|
||||
position: { x, y },
|
||||
draggable: true,
|
||||
resizable: false,
|
||||
content: this.panel.element,
|
||||
onClose: () => {
|
||||
// 通知主控制面板更新状态
|
||||
if (this.engine.walkControl && this.engine.walkControl.panel) {
|
||||
this.engine.walkControl.panel.setPathModeActive(false);
|
||||
}
|
||||
this.hide();
|
||||
}
|
||||
});
|
||||
this.dialog.init();
|
||||
return this.panel.element;
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏弹窗
|
||||
*/
|
||||
public hide(): void {
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁弹窗和面板
|
||||
*/
|
||||
public destroy(): void {
|
||||
// 先保存 dialog 引用,避免在回调中重复调用
|
||||
const dialog = this.dialog;
|
||||
|
||||
// 立即清空引用,防止递归
|
||||
this.dialog = null;
|
||||
|
||||
// 关闭弹窗
|
||||
if (dialog) {
|
||||
dialog.destroy();
|
||||
/** 对话框关闭时的回调 */
|
||||
protected onDialogClose(): void {
|
||||
if (this.registry.walkControl && this.registry.walkControl.panel) {
|
||||
this.registry.walkControl.panel.setPathModeActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
// 销毁面板
|
||||
/** 销毁前的清理 */
|
||||
protected onBeforeDestroy(): void {
|
||||
if (this.panel) {
|
||||
this.panel.destroy();
|
||||
this.panel = null;
|
||||
|
||||
Reference in New Issue
Block a user