删除文件上传离开页面的提示信息

This commit is contained in:
2025-06-06 11:32:19 +08:00
parent 358e9ab745
commit 7009227806
4 changed files with 36 additions and 119 deletions
+32 -32
View File
@@ -1560,44 +1560,44 @@ export default function FilesUpload() {
];
// 添加路由阻止器
const shouldBlock = uploadStage === "uploading" || uploadStage === "processing";
// const shouldBlock = uploadStage === "uploading" || uploadStage === "processing";
// 使用useBlocker来阻止页面导航
const blocker = useBlocker(
({ nextLocation }) => {
return shouldBlock && window.location.pathname !== nextLocation.pathname;
}
);
// const blocker = useBlocker(
// ({ nextLocation }) => {
// return shouldBlock && window.location.pathname !== nextLocation.pathname;
// }
// );
// 处理阻止导航的逻辑
useEffect(() => {
if (blocker.state === "blocked") {
const confirmed = window.confirm(
"文件正在上传或处理中,离开页面将中断操作。确定要离开吗?"
);
if (confirmed) {
blocker.proceed();
} else {
blocker.reset();
}
}
}, [blocker]);
// // 处理阻止导航的逻辑
// useEffect(() => {
// if (blocker.state === "blocked") {
// const confirmed = window.confirm(
// "文件正在上传或处理中,离开页面将中断操作。确定要离开吗?"
// );
// if (confirmed) {
// blocker.proceed();
// } else {
// blocker.reset();
// }
// }
// }, [blocker]);
// 添加页面刷新/关闭提示
useEffect(() => {
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
if (shouldBlock) {
e.preventDefault();
e.returnValue = "文件正在上传或处理中,离开页面将中断操作。确定要离开吗?";
return e.returnValue;
}
};
// useEffect(() => {
// const handleBeforeUnload = (e: BeforeUnloadEvent) => {
// if (shouldBlock) {
// e.preventDefault();
// e.returnValue = "文件正在上传或处理中,离开页面将中断操作。确定要离开吗?";
// return e.returnValue;
// }
// };
window.addEventListener("beforeunload", handleBeforeUnload);
return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
};
}, [shouldBlock]);
// window.addEventListener("beforeunload", handleBeforeUnload);
// return () => {
// window.removeEventListener("beforeunload", handleBeforeUnload);
// };
// }, [shouldBlock]);
return (
<div className="file-upload-page">
+1 -1
View File
@@ -527,7 +527,7 @@ export default function ReviewDetails() {
) : reviewData && (
<>
{/* 自定义面包屑 */}
<div className="flex justify-between items-center mb-2">
<div className="flex justify-between items-center mb-4">
<Breadcrumb
items={getBreadcrumbItems()}
className="items-center flex !mb-0"