增加redirect_url
This commit is contained in:
parent
623999d9d9
commit
c72bee42fd
|
@ -1,11 +1,27 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useState, Suspense } from "react";
|
||||
import { FiArrowLeft, FiCheckCircle } from "react-icons/fi";
|
||||
import toast from "react-hot-toast";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
export default function SuccessPage() {
|
||||
// 创建一个客户端组件来处理搜索参数
|
||||
function SuccessContent() {
|
||||
const [closeAttempted, setCloseAttempted] = useState(false);
|
||||
const searchParams = useSearchParams();
|
||||
const redirectUrl = searchParams.get("redirect_url");
|
||||
|
||||
// 处理重定向
|
||||
useEffect(() => {
|
||||
if (redirectUrl) {
|
||||
// 添加一个小延迟,让成功动画有时间显示
|
||||
const redirectTimer = setTimeout(() => {
|
||||
window.location.href = redirectUrl;
|
||||
}, 1500);
|
||||
|
||||
return () => clearTimeout(redirectTimer);
|
||||
}
|
||||
}, [redirectUrl]);
|
||||
|
||||
// 页面加载时的动画效果
|
||||
useEffect(() => {
|
||||
|
@ -22,6 +38,12 @@ export default function SuccessPage() {
|
|||
|
||||
// 尝试关闭页面
|
||||
const handleClose = () => {
|
||||
// 如果有重定向URL,直接跳转
|
||||
if (redirectUrl) {
|
||||
window.location.href = redirectUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
window.close();
|
||||
|
||||
|
@ -49,36 +71,47 @@ export default function SuccessPage() {
|
|||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center">
|
||||
<div
|
||||
id="success-icon"
|
||||
className="p-3 bg-green-900/30 rounded-full transition-transform duration-500 ease-in-out transform scale-0"
|
||||
>
|
||||
<FiCheckCircle className="w-16 h-16 text-green-400" />
|
||||
</div>
|
||||
|
||||
<h2 className="mt-6 text-2xl font-bold text-center text-white">
|
||||
支付成功
|
||||
</h2>
|
||||
|
||||
<p className="mt-4 text-lg text-center text-gray-300">
|
||||
{redirectUrl ? "即将返回应用..." : "请关闭当前页面返回应用"}
|
||||
</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 ? "立即返回" : "关闭页面"}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 主页面组件,包含Suspense边界
|
||||
export default function SuccessPage() {
|
||||
return (
|
||||
<div
|
||||
className="flex flex-col items-center justify-center min-h-screen px-4 py-12"
|
||||
style={{ backgroundColor: "#07050A" }}
|
||||
>
|
||||
<div className="w-full max-w-md p-8 mx-auto bg-[#17161A] rounded-xl shadow-lg border border-gray-800">
|
||||
<div className="flex flex-col items-center">
|
||||
<div
|
||||
id="success-icon"
|
||||
className="p-3 bg-green-900/30 rounded-full transition-transform duration-500 ease-in-out transform scale-0"
|
||||
>
|
||||
<FiCheckCircle className="w-16 h-16 text-green-400" />
|
||||
</div>
|
||||
|
||||
<h2 className="mt-6 text-2xl font-bold text-center text-white">
|
||||
支付成功
|
||||
</h2>
|
||||
|
||||
<p className="mt-4 text-lg text-center text-gray-300">
|
||||
请关闭当前页面返回应用
|
||||
</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" />
|
||||
关闭页面
|
||||
</button>
|
||||
</div>
|
||||
<Suspense
|
||||
fallback={<div className="text-white text-center">加载中...</div>}
|
||||
>
|
||||
<SuccessContent />
|
||||
</Suspense>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue