refactor: 重构 Manager 架构,引入 ManagerRegistry 和 BaseManager 基类
- 新增 ManagerRegistry 单例注册表,统一管理所有 Manager 实例 - 新增 BaseManager 基类,自动管理事件订阅清理 - 新增 BaseDialogManager 基类,统一对话框生命周期管理 - 重构 15 个 Manager 使用新基类 - 重构 Toolbar 按钮和 Menu 按钮移除 engine 参数依赖 - 删除 BimComponent 基类(已不再使用) - 为所有 Manager 和核心模块添加中文 JSDoc 注释
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import type {ButtonGroupColors, ButtonConfig} from '../components/button-group/index.type';
|
||||
import {Toolbar} from '../components/button-group/toolbar';
|
||||
import {BimComponent} from '../core/component';
|
||||
import type {BimEngine} from '../bim-engine';
|
||||
import {BimButtonGroup} from "../components/button-group";
|
||||
import {BimTree} from "../components/tree";
|
||||
import {TreeNodeConfig} from "../components/tree/types.ts";
|
||||
import {BimDialog} from "../components/dialog";
|
||||
import {BimTab} from "../components/tab";
|
||||
import {getIcon} from "../utils/icon-manager";
|
||||
/**
|
||||
* 构件树管理器
|
||||
* 负责管理构件树按钮和构件树对话框
|
||||
*/
|
||||
import type { ButtonGroupColors, ButtonConfig } from '../components/button-group/index.type';
|
||||
import { BaseManager } from '../core/base-manager';
|
||||
import { BimButtonGroup } from '../components/button-group';
|
||||
import { BimTree } from '../components/tree';
|
||||
import { TreeNodeConfig } from '../components/tree/types';
|
||||
import { BimDialog } from '../components/dialog';
|
||||
import { BimTab } from '../components/tab';
|
||||
import { getIcon } from '../utils/icon-manager';
|
||||
|
||||
const MOCK_STRUCT_DATA: TreeNodeConfig[] =[
|
||||
/** 模拟的构件树数据 */
|
||||
const MOCK_STRUCT_DATA: TreeNodeConfig[] = [
|
||||
{
|
||||
id: 'root',
|
||||
label: '全部构件',
|
||||
@@ -20,10 +23,10 @@ const MOCK_STRUCT_DATA: TreeNodeConfig[] =[
|
||||
id: 'level-1',
|
||||
label: '一层',
|
||||
expanded: false,
|
||||
icon:'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M20.73 16.52V7.59a.7.7 0 0 0-.08-.33a.74.74 0 0 0-.36-.36l-8-3.58a.75.75 0 0 0-.62 0l-8 3.58a.8.8 0 0 0-.44.69v8.82a.83.83 0 0 0 .44.69l8 3.58a.72.72 0 0 0 .62 0l8-3.58a.77.77 0 0 0 .44-.58m-16-7.78l6.5 2.92v7.18l-6.5-2.91Zm8 2.92l6.5-2.92v7.19l-6.5 2.91ZM12 4.82l6.17 2.77L12 10.35L5.83 7.59Z"/></svg>',
|
||||
icon: '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M20.73 16.52V7.59a.7.7 0 0 0-.08-.33a.74.74 0 0 0-.36-.36l-8-3.58a.75.75 0 0 0-.62 0l-8 3.58a.8.8 0 0 0-.44.69v8.82a.83.83 0 0 0 .44.69l8 3.58a.72.72 0 0 0 .62 0l8-3.58a.77.77 0 0 0 .44-.58m-16-7.78l6.5 2.92v7.18l-6.5-2.91Zm8 2.92l6.5-2.92v7.19l-6.5 2.91ZM12 4.82l6.17 2.77L12 10.35L5.83 7.59Z"/></svg>',
|
||||
clickAction: 'expand',
|
||||
children: [
|
||||
{ id: 'l1-wall', label: '墙体(128)'},
|
||||
{ id: 'l1-wall', label: '墙体(128)' },
|
||||
{ id: 'l1-column', label: '柱(46)' },
|
||||
{ id: 'l1-beam', label: '梁(82)' },
|
||||
{ id: 'l1-slab', label: '楼板(12)' },
|
||||
@@ -75,23 +78,27 @@ const MOCK_STRUCT_DATA: TreeNodeConfig[] =[
|
||||
];
|
||||
|
||||
/**
|
||||
* 底部工具栏管理器 (ToolbarManager)
|
||||
* 仅负责管理底部工具栏实例。
|
||||
* 构件树管理器
|
||||
* 管理左上角的构件树按钮和对话框
|
||||
*/
|
||||
export class ConstructTreeManagerBtn extends BimComponent {
|
||||
private toolbar: Toolbar | null = null;
|
||||
export class ConstructTreeManagerBtn extends BaseManager {
|
||||
/** 按钮组实例 */
|
||||
private toolbar: BimButtonGroup | null = null;
|
||||
/** 按钮容器元素 */
|
||||
private toolbarContainer: HTMLElement | null = null;
|
||||
/** 主容器元素 */
|
||||
private container: HTMLElement;
|
||||
/** 构件树对话框实例 */
|
||||
private dialog: BimDialog | null = null;
|
||||
|
||||
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 = 'bim-construct-tree';
|
||||
this.container.appendChild(this.toolbarContainer);
|
||||
@@ -99,12 +106,11 @@ export class ConstructTreeManagerBtn extends BimComponent {
|
||||
container: this.toolbarContainer,
|
||||
showLabel: false,
|
||||
direction: 'column',
|
||||
position: 'top-left', // 底部居中
|
||||
align: 'vertical', // 图标在上
|
||||
expand: 'up' // 向上展开
|
||||
position: 'top-left',
|
||||
align: 'vertical',
|
||||
expand: 'up'
|
||||
});
|
||||
this.toolbar.init();
|
||||
this.toolbar.setEngine(this.engine);
|
||||
this.toolbar.addGroup('construct-tree');
|
||||
this.toolbar.addButton({
|
||||
id: 'construct-tree-btn',
|
||||
@@ -113,16 +119,16 @@ export class ConstructTreeManagerBtn extends BimComponent {
|
||||
label: 'construct-tree',
|
||||
icon: getIcon('目录树'),
|
||||
onClick: () => {
|
||||
this.openConstructTreeDialog()
|
||||
this.openConstructTreeDialog();
|
||||
}
|
||||
});
|
||||
this.toolbar.render();
|
||||
}
|
||||
|
||||
/** 打开构件树对话框 */
|
||||
public openConstructTreeDialog() {
|
||||
this.setVisible(false);
|
||||
|
||||
// 构件树实例(放在“构件”标签内)
|
||||
const tree = new BimTree({
|
||||
data: MOCK_STRUCT_DATA,
|
||||
checkable: true,
|
||||
@@ -146,18 +152,15 @@ export class ConstructTreeManagerBtn extends BimComponent {
|
||||
});
|
||||
tree.init();
|
||||
|
||||
// 系统/空间暂留空占位,可后续填充业务内容
|
||||
const systemPlaceholder = document.createElement('div');
|
||||
systemPlaceholder.className = 'construct-tab__panel-content';
|
||||
const spacePlaceholder = document.createElement('div');
|
||||
spacePlaceholder.className = 'construct-tab__panel-content';
|
||||
|
||||
// 构件面板容器,确保内部树区域可滚动
|
||||
const componentPanel = document.createElement('div');
|
||||
componentPanel.className = 'construct-tab__panel-content';
|
||||
componentPanel.appendChild(tree.element);
|
||||
|
||||
// 创建 Tab 容器(仅在本弹窗内使用,不额外挂 Manager)
|
||||
const tabMount = document.createElement('div');
|
||||
tabMount.className = 'construct-tab__container';
|
||||
tabMount.style.height = '100%';
|
||||
@@ -165,24 +168,23 @@ export class ConstructTreeManagerBtn extends BimComponent {
|
||||
const tab = new BimTab({
|
||||
container: tabMount,
|
||||
tabs: [
|
||||
{id: 'component', title: 'tab.component', content: componentPanel},
|
||||
{id: 'system', title: 'tab.system', content: systemPlaceholder},
|
||||
{id: 'space', title: 'tab.space', content: spacePlaceholder},
|
||||
{ id: 'component', title: 'tab.component', content: componentPanel },
|
||||
{ id: 'system', title: 'tab.system', content: systemPlaceholder },
|
||||
{ id: 'space', title: 'tab.space', content: spacePlaceholder },
|
||||
],
|
||||
activeId: 'component',
|
||||
onChange: () => {
|
||||
// 切换后根据内容宽度刷新弹窗
|
||||
this.dialog?.fitWidth();
|
||||
}
|
||||
});
|
||||
tab.init();
|
||||
|
||||
this.dialog = this.engine.dialog!.create({
|
||||
this.dialog = this.registry.dialog!.create({
|
||||
title: 'constructTree.title',
|
||||
minWidth: 320,
|
||||
height: 420,
|
||||
content: tabMount,
|
||||
position: {x: 20, y: 20},
|
||||
position: { x: 20, y: 20 },
|
||||
resizable: false,
|
||||
onClose: () => {
|
||||
tab.destroy();
|
||||
@@ -193,44 +195,76 @@ export class ConstructTreeManagerBtn extends BimComponent {
|
||||
this.dialog?.fitWidth();
|
||||
}
|
||||
|
||||
/** 刷新渲染 */
|
||||
public refresh() {
|
||||
this.toolbar?.render();
|
||||
}
|
||||
|
||||
/** 销毁管理器 */
|
||||
public destroy() {
|
||||
this.toolbar?.destroy();
|
||||
this.toolbar = null;
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
// --- 转发 API ---
|
||||
/**
|
||||
* 添加按钮组
|
||||
* @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 visible 是否可见
|
||||
*/
|
||||
public setVisible(visible: boolean) {
|
||||
if (this.toolbarContainer) {
|
||||
this.toolbarContainer.style.visibility = visible ? 'visible' : 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景颜色
|
||||
* @param color 颜色值
|
||||
*/
|
||||
public setBackgroundColor(color: string) {
|
||||
this.toolbar?.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置按钮组颜色
|
||||
* @param colors 颜色配置
|
||||
*/
|
||||
public setColors(colors: ButtonGroupColors) {
|
||||
this.toolbar?.setColors(colors);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user