diff --git a/frontend/src/hooks/useLeaveTabUnSaveCheck.ts b/frontend/src/hooks/useLeaveTabUnSaveCheck.ts index ce261d119a..69a8aab87f 100644 --- a/frontend/src/hooks/useLeaveTabUnSaveCheck.ts +++ b/frontend/src/hooks/useLeaveTabUnSaveCheck.ts @@ -34,4 +34,11 @@ export default function useLeaveTabUnSaveCheck(tabs: TabItem[], permissions?: st next(); } }); + + // 页面有变更时,关闭或刷新页面弹出浏览器的保存提示 + window.onbeforeunload = () => { + if (!isLeaving && tabs.some((tab) => tab.unSaved) && hasAnyPermission(permissions || [])) { + return ''; + } + }; } diff --git a/frontend/src/hooks/useLeaveUnSaveTip.ts b/frontend/src/hooks/useLeaveUnSaveTip.ts index 0e515eab6e..4763242eb2 100644 --- a/frontend/src/hooks/useLeaveUnSaveTip.ts +++ b/frontend/src/hooks/useLeaveUnSaveTip.ts @@ -58,6 +58,13 @@ export default function useLeaveUnSaveTip(leaveProp = leaveProps) { next(); } }); + + // 页面有变更时,关闭或刷新页面弹出浏览器的保存提示 + window.onbeforeunload = () => { + if (!isSave.value) { + return ''; + } + }; return { setIsSave, openUnsavedTip,