diff --git a/src/Add-on/ToggleUI.ts b/src/Add-on/ToggleUI.ts index 40a2e8b67..d1b46a252 100644 --- a/src/Add-on/ToggleUI.ts +++ b/src/Add-on/ToggleUI.ts @@ -1,11 +1,11 @@ +import { DownPanelStore } from "../UI/Store/DownPanelStore"; export class Command_ToggleUI { async exec() { - let els = ["#TopPanel", "#TopToolBar"].map(e => document.querySelector(e) as HTMLElement); - - for (let el of els) - el.style.display = el.style.display === "none" ? "block" : "none"; + let store = DownPanelStore.GetInstance() as DownPanelStore; + store.isTopToolBarShow = !store.isTopToolBarShow; + store.Upload(); } } diff --git a/src/UI/Components/TopToolBar/ToolsBlock.tsx b/src/UI/Components/TopToolBar/ToolsBlock.tsx index a1110f05f..6b12b8655 100644 --- a/src/UI/Components/TopToolBar/ToolsBlock.tsx +++ b/src/UI/Components/TopToolBar/ToolsBlock.tsx @@ -30,13 +30,15 @@ export class ToolsBlock extends React.Component @observable listSmall: ICommandIconInfo[] = this.props.list.slice(35); //顶端工具栏每部分最多显示个数 @observable windowWidth = window.innerWidth; private blocksData = ToolsBlockStore.GetInstance().blocksData as TopToolBarBlockData; + + private _DisposeAOP: Function; componentDidMount() { window.addEventListener('resize', this.calSmallIconList, false); this.calSmallIconList(); if (this.isExtendShow) this.divEl.focus(); - end(app.Editor.MouseCtrl, app.Editor.MouseCtrl.onMouseDown, (e: MouseEvent) => + this._DisposeAOP = end(app.Editor.MouseCtrl, app.Editor.MouseCtrl.onMouseDown, (e: MouseEvent) => { if (this.isExtendShow) this.isExtendShow = false; }); @@ -44,6 +46,11 @@ export class ToolsBlock extends React.Component componentWillUnmount() { window.removeEventListener("resize", this.calSmallIconList, false); + if (this._DisposeAOP) + { + this._DisposeAOP(); + this._DisposeAOP = undefined; + } } componentDidUpdate() { diff --git a/src/UI/Store/DownPanelStore.ts b/src/UI/Store/DownPanelStore.ts index ce0e8d171..bbd211298 100644 --- a/src/UI/Store/DownPanelStore.ts +++ b/src/UI/Store/DownPanelStore.ts @@ -1,6 +1,7 @@ import { action, autorun, observable, reaction } from 'mobx'; import { Vector3 } from 'three'; import * as xaop from 'xaop'; +import { Command_ToggleUI } from '../../Add-on/ToggleUI'; import { app } from '../../ApplicationServices/Application'; import { appCache } from '../../Common/AppCache'; import { ConfigUrls } from '../../Common/HostUrl'; @@ -285,8 +286,7 @@ export class DownPanelStore } toggleTopToolBarShow() { - this.isTopToolBarShow = !this.isTopToolBarShow; - this.Upload(); + new Command_ToggleUI().exec(); } toggleBottomToolBarShow() {