From 8a465ae625c4a50f72090676057437821bbece0f Mon Sep 17 00:00:00 2001
From: erio
Date: Sat, 7 Mar 2026 16:55:49 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E4=BB=98=E7=BB=93=E6=9E=9C?=
=?UTF-8?q?=E9=A1=B5=E5=A2=9E=E5=8A=A0=205=20=E7=A7=92=E5=80=92=E8=AE=A1?=
=?UTF-8?q?=E6=97=B6=E8=87=AA=E5=8A=A8=E8=BF=94=E5=9B=9E=E5=92=8C=E6=89=8B?=
=?UTF-8?q?=E5=8A=A8=E8=BF=94=E5=9B=9E=E6=8C=89=E9=92=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-Authored-By: Claude Opus 4.6
---
src/app/pay/result/page.tsx | 92 +++++++++++++++++++++----------------
1 file changed, 53 insertions(+), 39 deletions(-)
diff --git a/src/app/pay/result/page.tsx b/src/app/pay/result/page.tsx
index daf0c96..a7c2d14 100644
--- a/src/app/pay/result/page.tsx
+++ b/src/app/pay/result/page.tsx
@@ -15,6 +15,7 @@ function ResultContent() {
const [status, setStatus] = useState(null);
const [loading, setLoading] = useState(true);
const [isInPopup, setIsInPopup] = useState(false);
+ const [countdown, setCountdown] = useState(5);
// Detect if opened as a popup window (from stripe-popup or via popup=1 param)
useEffect(() => {
@@ -53,16 +54,35 @@ function ResultContent() {
};
}, [outTradeNo]);
- // Auto-close popup window on success
const isSuccess = status === 'COMPLETED' || status === 'PAID' || status === 'RECHARGING';
- useEffect(() => {
- if (!isInPopup || !isSuccess) return;
- const timer = setTimeout(() => {
+ const goBack = () => {
+ if (isInPopup) {
window.close();
- }, 3000);
- return () => clearTimeout(timer);
- }, [isInPopup, isSuccess]);
+ } else if (window.history.length > 1) {
+ window.history.back();
+ } else {
+ window.close();
+ }
+ };
+
+ // Countdown auto-return on success
+ useEffect(() => {
+ if (!isSuccess) return;
+ setCountdown(5);
+ const timer = setInterval(() => {
+ setCountdown((prev) => {
+ if (prev <= 1) {
+ clearInterval(timer);
+ goBack();
+ return 0;
+ }
+ return prev - 1;
+ });
+ }, 1000);
+ return () => clearInterval(timer);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [isSuccess, isInPopup]);
if (loading) {
return (
@@ -91,35 +111,31 @@ function ResultContent() {
{status === 'COMPLETED' ? '余额已成功到账!' : '支付成功,余额正在充值中...'}
- {isInPopup && (
-
-
- 此窗口将在 3 秒后自动关闭
-
-
-
- )}
+
+
+ {countdown > 0 ? `${countdown} 秒后自动返回` : '正在返回...'}
+
+
+
>
) : isPending ? (
<>
⏳
等待支付
订单尚未完成支付
- {isInPopup && (
-
- )}
+
>
) : (
<>
@@ -134,15 +150,13 @@ function ResultContent() {
? '订单已被取消'
: '请联系管理员处理'}
- {isInPopup && (
-
- )}
+
>
)}