diff --git a/source/Component/HeaderBar/HeaderBar.tsx b/source/Component/HeaderBar/HeaderBar.tsx index 8009871..b69b679 100644 --- a/source/Component/HeaderBar/HeaderBar.tsx +++ b/source/Component/HeaderBar/HeaderBar.tsx @@ -126,6 +126,30 @@ class HeaderWindowsAction extends Component { @useStatusWithEvent("fileSave", "fileChange", "fileLoad") class HeaderBar extends Component { + private showCloseMessage = (e: BeforeUnloadEvent) => { + if (!this.props.status?.archive.isSaved) { + const message = I18N(this.props, "ZH_CH"); + (e || window.event).returnValue = message; // 兼容 Gecko + IE + return message; // 兼容 Gecko + Webkit, Safari, Chrome + } + } + + public componentDidMount() { + + if (this.props.setting?.platform === Platform.web) { + // 阻止页面关闭 + window.addEventListener("beforeunload", this.showCloseMessage); + } + } + + public componentWillUnmount() { + + if (this.props.setting?.platform === Platform.web) { + // 阻止页面关闭 + window.removeEventListener("beforeunload", this.showCloseMessage); + } + } + public render(): ReactNode { const { status, setting } = this.props; diff --git a/source/Context/Status.tsx b/source/Context/Status.tsx index ac88446..0d702ca 100644 --- a/source/Context/Status.tsx +++ b/source/Context/Status.tsx @@ -172,6 +172,8 @@ class Status extends Emitter { this.emit("fileChange"); } } + + // 设置文件修改状态 this.on("objectChange", handelFileChange); this.on("behaviorChange", handelFileChange); this.on("labelChange", handelFileChange);