2026-01-22 15:23:57 +08:00
|
|
|
/**
|
|
|
|
|
* 工具栏管理器
|
|
|
|
|
* 负责管理底部工具栏的创建、按钮配置和显示控制
|
|
|
|
|
*/
|
2025-12-04 15:24:44 +08:00
|
|
|
import type { ButtonGroupColors, ButtonConfig } from '../components/button-group/index.type';
|
|
|
|
|
import { Toolbar } from '../components/button-group/toolbar';
|
|
|
|
|
import type { ThemeConfig } from '../themes/types';
|
2026-01-22 15:23:57 +08:00
|
|
|
import { BaseManager } from '../core/base-manager';
|
2025-12-04 15:24:44 +08:00
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
* 工具栏管理器
|
|
|
|
|
* 提供工具栏按钮的添加、显示/隐藏、主题更新等功能
|
2025-12-04 15:24:44 +08:00
|
|
|
*/
|
2026-01-22 15:23:57 +08:00
|
|
|
export class ToolbarManager extends BaseManager {
|
|
|
|
|
/** 工具栏实例 */
|
2025-12-04 15:24:44 +08:00
|
|
|
private toolbar: Toolbar | null = null;
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 工具栏容器元素 */
|
2025-12-04 15:24:44 +08:00
|
|
|
private toolbarContainer: HTMLElement | null = null;
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 主容器元素 */
|
2025-12-04 15:24:44 +08:00
|
|
|
private container: HTMLElement;
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
constructor(container: HTMLElement) {
|
|
|
|
|
super();
|
2025-12-04 15:24:44 +08:00
|
|
|
this.container = container;
|
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 初始化工具栏 */
|
2025-12-04 15:24:44 +08:00
|
|
|
private init() {
|
|
|
|
|
this.toolbarContainer = document.createElement('div');
|
|
|
|
|
this.toolbarContainer.id = 'opt-btn-groups';
|
|
|
|
|
this.toolbarContainer.className = 'bim-engine-opt-btn-container is-bottom-toolbar';
|
|
|
|
|
this.container.appendChild(this.toolbarContainer);
|
|
|
|
|
|
|
|
|
|
this.toolbar = new Toolbar({
|
|
|
|
|
container: this.toolbarContainer,
|
2026-01-21 15:50:07 +08:00
|
|
|
type: 'glass-pill',
|
2025-12-04 15:24:44 +08:00
|
|
|
showLabel: true,
|
|
|
|
|
direction: 'row',
|
2026-01-21 15:50:07 +08:00
|
|
|
position: 'bottom-right',
|
|
|
|
|
align: 'vertical',
|
|
|
|
|
expand: 'up'
|
2025-12-04 15:24:44 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.toolbar.init();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
/**
|
|
|
|
|
* 更新工具栏主题
|
|
|
|
|
* @param theme 主题配置
|
|
|
|
|
*/
|
2025-12-04 15:24:44 +08:00
|
|
|
public updateTheme(theme: ThemeConfig) {
|
|
|
|
|
this.toolbar?.setTheme(theme);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 刷新工具栏渲染 */
|
2025-12-04 15:24:44 +08:00
|
|
|
public refresh() {
|
|
|
|
|
this.toolbar?.render();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 销毁工具栏 */
|
2025-12-04 15:24:44 +08:00
|
|
|
public destroy() {
|
|
|
|
|
this.toolbar?.destroy();
|
|
|
|
|
this.toolbar = null;
|
2026-01-22 15:23:57 +08:00
|
|
|
super.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加按钮组
|
|
|
|
|
* @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);
|
2025-12-04 15:24:44 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
/**
|
|
|
|
|
* 设置是否显示标签
|
|
|
|
|
* @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 是否可见
|
|
|
|
|
*/
|
2025-12-04 15:24:44 +08:00
|
|
|
public setVisible(visible: boolean) {
|
|
|
|
|
if (this.toolbarContainer) {
|
|
|
|
|
this.toolbarContainer.style.visibility = visible ? 'visible' : 'hidden';
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-25 15:47:57 +08:00
|
|
|
|
|
|
|
|
/**
|
2026-01-22 15:23:57 +08:00
|
|
|
* 设置背景颜色
|
|
|
|
|
* @param color 颜色值
|
|
|
|
|
*/
|
|
|
|
|
public setBackgroundColor(color: string) {
|
|
|
|
|
this.toolbar?.setBackgroundColor(color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置按钮组颜色
|
|
|
|
|
* @param colors 颜色配置
|
2025-12-25 15:47:57 +08:00
|
|
|
*/
|
2026-01-22 15:23:57 +08:00
|
|
|
public setColors(colors: ButtonGroupColors) {
|
|
|
|
|
this.toolbar?.setColors(colors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 隐藏工具栏 */
|
2025-12-25 15:47:57 +08:00
|
|
|
public hide(): void {
|
|
|
|
|
if (this.toolbarContainer) {
|
|
|
|
|
this.toolbarContainer.style.display = 'none';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
/** 显示工具栏 */
|
2025-12-25 15:47:57 +08:00
|
|
|
public show(): void {
|
|
|
|
|
if (this.toolbarContainer) {
|
|
|
|
|
this.toolbarContainer.style.display = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取工具栏容器
|
2026-01-22 15:23:57 +08:00
|
|
|
* @returns 容器元素
|
2025-12-25 15:47:57 +08:00
|
|
|
*/
|
|
|
|
|
public getContainer(): HTMLElement | null {
|
|
|
|
|
return this.toolbarContainer;
|
|
|
|
|
}
|
2025-12-04 15:24:44 +08:00
|
|
|
}
|