From 17090ffa3a9ab585779a8bec6b91b058e44ad130 Mon Sep 17 00:00:00 2001 From: teukkk Date: Thu, 1 Aug 2024 18:24:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A1=B5=E9=9D=A2=E6=9C=89=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E6=97=B6=EF=BC=8C=E5=85=B3=E9=97=AD=E6=88=96=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E9=A1=B5=E9=9D=A2=E5=BC=B9=E5=87=BA=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E4=BF=9D=E5=AD=98=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/hooks/useLeaveTabUnSaveCheck.ts | 7 +++++++ frontend/src/hooks/useLeaveUnSaveTip.ts | 7 +++++++ 2 files changed, 14 insertions(+) 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,