feat: 页面有变更时,关闭或刷新页面弹出浏览器的保存提示

This commit is contained in:
teukkk 2024-08-01 18:24:37 +08:00 committed by 刘瑞斌
parent 1c6c8fcb7a
commit 17090ffa3a
2 changed files with 14 additions and 0 deletions

View File

@ -34,4 +34,11 @@ export default function useLeaveTabUnSaveCheck(tabs: TabItem[], permissions?: st
next(); next();
} }
}); });
// 页面有变更时,关闭或刷新页面弹出浏览器的保存提示
window.onbeforeunload = () => {
if (!isLeaving && tabs.some((tab) => tab.unSaved) && hasAnyPermission(permissions || [])) {
return '';
}
};
} }

View File

@ -58,6 +58,13 @@ export default function useLeaveUnSaveTip(leaveProp = leaveProps) {
next(); next();
} }
}); });
// 页面有变更时,关闭或刷新页面弹出浏览器的保存提示
window.onbeforeunload = () => {
if (!isSave.value) {
return '';
}
};
return { return {
setIsSave, setIsSave,
openUnsavedTip, openUnsavedTip,