From 137a780269bd53dab91b7f5a6940e6855e64df9f Mon Sep 17 00:00:00 2001 From: erio Date: Fri, 6 Mar 2026 19:13:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=AE=80=E5=8C=96=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=B1=95=E7=A4=BA=E9=80=BB=E8=BE=91=20-=20=E6=9C=89?= =?UTF-8?q?=20payUrl=20=E7=9B=B4=E6=8E=A5=E8=B7=B3=E8=BD=AC=EF=BC=8C?= =?UTF-8?q?=E6=9C=89=20qrCode=20=E6=98=BE=E7=A4=BA=E4=BA=8C=E7=BB=B4?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除 isRedirectPayment / mobileRedirectUrl 等支付类型判断, 前端只根据后端返回的字段决定行为: - payUrl → 自动跳转,无需确认 - qrCode → 展示二维码 + 中心图标 - clientSecret → Stripe 嵌入式表单 Co-Authored-By: Claude Opus 4.6 --- src/components/PaymentQRCode.tsx | 40 +++++++------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/src/components/PaymentQRCode.tsx b/src/components/PaymentQRCode.tsx index 13f6c53..ccc50d0 100644 --- a/src/components/PaymentQRCode.tsx +++ b/src/components/PaymentQRCode.tsx @@ -4,7 +4,6 @@ import { useEffect, useMemo, useState, useCallback, useRef } from 'react'; import QRCode from 'qrcode'; import { isStripeType, - isRedirectPayment, getPaymentMeta, getPaymentIconSrc, getPaymentChannelLabel, @@ -78,32 +77,22 @@ export default function PaymentQRCode({ const [popupBlocked, setPopupBlocked] = useState(false); const paymentMethodListenerAdded = useRef(false); - // alipay_direct 使用电脑网站支付,payUrl 是跳转链接不是二维码内容 - const isRedirect = isRedirectPayment(paymentType); - - // 移动端可用的跳转链接:优先 payUrl,其次尝试 qrCode(微信 weixin:// 协议可直接唤起) - const mobileRedirectUrl = payUrl || (qrCode && /^(https?:|weixin:)/i.test(qrCode) ? qrCode : null); - - // 自动跳转:redirect 支付方式 或 移动端 H5 - const shouldAutoRedirect = !expired && !isStripeType(paymentType) && ((isRedirect && payUrl) || (isMobile && mobileRedirectUrl)); + // 有 payUrl 就直接跳转,不需要确认 + const shouldAutoRedirect = !expired && !isStripeType(paymentType) && !!payUrl; useEffect(() => { if (!shouldAutoRedirect || redirected) return; - const url = isRedirect ? payUrl! : mobileRedirectUrl!; setRedirected(true); - // embedded iframe 不能 location.href 跳转,用 window.open if (isEmbedded) { - window.open(url, '_blank'); + window.open(payUrl!, '_blank'); } else { - window.location.href = url; + window.location.href = payUrl!; } - }, [shouldAutoRedirect, redirected, isRedirect, payUrl, mobileRedirectUrl, isEmbedded]); + }, [shouldAutoRedirect, redirected, payUrl, isEmbedded]); const qrPayload = useMemo(() => { - if (isRedirect && !qrCode) return ''; - const value = (qrCode || payUrl || '').trim(); - return value; - }, [qrCode, payUrl, isRedirect]); + return (qrCode || '').trim(); + }, [qrCode]); useEffect(() => { let cancelled = false; @@ -476,7 +465,7 @@ export default function PaymentQRCode({ )} - {!qrDataUrl && payUrl && ( - - {TEXT_GO_PAY} - - )} - - {!qrDataUrl && !payUrl && ( + {!qrDataUrl && (