This commit is contained in:
yezian 2025-03-17 19:12:14 +08:00
parent c72bee42fd
commit 083c3569e2
1 changed files with 70 additions and 2 deletions

View File

@ -45,7 +45,47 @@ function SuccessContent() {
}
try {
window.close();
//
const historyLength = window.history.length;
console.log(`历史记录长度: ${historyLength}`);
if (historyLength > 1) {
console.log("检测到历史记录,尝试返回上一页");
//
window.history.go(-2);
//
setTimeout(() => {
//
if (document.visibilityState !== "hidden") {
console.log("返回上一页可能失败,尝试返回一级");
window.history.back();
}
}, 200);
return;
}
console.log("无历史记录,尝试关闭窗口");
//
//
const isOpener = window.opener && !window.opener.closed;
if (isOpener) {
//
try {
// 访 opener
window.opener.focus();
console.log("尝试聚焦父窗口");
} catch (e) {
console.log("无法访问opener可能是跨域限制", e);
}
}
//
console.log("尝试关闭窗口");
const closingAttempt = window.close();
console.log("关闭窗口结果:", closingAttempt);
//
setTimeout(() => {
@ -71,6 +111,20 @@ function SuccessContent() {
}
};
//
const getCloseInstructions = () => {
const hasHistory = window.history.length > 1;
if (hasHistory) {
return "将返回之前的页面";
} else {
return "请点击浏览器右上角的 × 关闭此页面";
}
};
//
const historyInfo = `历史记录长度: ${window.history.length}`;
return (
<div className="flex flex-col items-center">
<div
@ -88,12 +142,26 @@ function SuccessContent() {
{redirectUrl ? "即将返回应用..." : "请关闭当前页面返回应用"}
</p>
{closeAttempted && !redirectUrl && (
<p className="mt-2 text-sm text-center text-gray-400">
{getCloseInstructions()}
</p>
)}
{process.env.NODE_ENV === "development" && (
<p className="mt-2 text-xs text-center text-gray-500">{historyInfo}</p>
)}
<button
onClick={handleClose}
className="flex items-center justify-center w-full mt-8 px-4 py-3 text-white bg-[#FF669E] rounded-md hover:bg-[#FF4A8E] transition-colors"
>
<FiArrowLeft className="w-5 h-5 mr-2" />
{redirectUrl ? "立即返回" : "关闭页面"}
{redirectUrl
? "立即返回"
: window.history.length > 1
? "返回上一页"
: "关闭页面"}
</button>
</div>
);