From 1d8440c9b1eccb9d822c430e3aa295c4ef486583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=B7=E5=B0=8F=E5=89=8D?= Date: Fri, 23 Jan 2026 17:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0ios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 5 +- src/components/Auth/AuthFormContent.js | 129 +++++++++++++++++++------ 2 files changed, 101 insertions(+), 33 deletions(-) diff --git a/app.py b/app.py index fd062bdd..563357ad 100755 --- a/app.py +++ b/app.py @@ -3887,11 +3887,12 @@ def create_wechat_jsapi_order(): order.payment_source = 'h5' order_no = order.order_no # 使用自动生成的订单号 - # 关联优惠码 - if promo_code and price_result.get('promo_applied'): + # 关联优惠码(注意:price_result 返回的是 'promo_code' 字段,不是 'promo_applied') + if promo_code and price_result.get('promo_code'): promo = PromoCode.query.filter_by(code=promo_code.upper()).first() if promo: order.promo_code_id = promo.id + print(f"📦 JSAPI订单关联优惠码: {promo.code} (ID: {promo.id})") db.session.add(order) db.session.commit() diff --git a/src/components/Auth/AuthFormContent.js b/src/components/Auth/AuthFormContent.js index 4ace44f3..1bc06275 100644 --- a/src/components/Auth/AuthFormContent.js +++ b/src/components/Auth/AuthFormContent.js @@ -15,6 +15,7 @@ import WechatRegister from './WechatRegister'; import { logger } from '../../utils/logger'; import { getApiBase } from '../../utils/apiConfig'; import { useAuthEvents } from '../../hooks/useAuthEvents'; +import { isWeChatBrowser } from '../MiniProgramLauncher/hooks/useWechatEnvironment'; const { Link } = Typography; @@ -189,8 +190,12 @@ export default function AuthFormContent() { const isMountedRef = useRef(true); const wechatRef = useRef(null); + // 检测是否在微信浏览器中 + const isInWeChatBrowser = isWeChatBrowser(); + // Tab 状态: 'wechat' | 'phone' | 'password' - const [activeTab, setActiveTab] = useState('wechat'); + // 如果在微信浏览器中,默认显示 phone tab(因为微信 tab 会显示 H5 登录按钮) + const [activeTab, setActiveTab] = useState(isInWeChatBrowser ? 'phone' : 'wechat'); // 表单状态 const [isLoading, setIsLoading] = useState(false); @@ -216,8 +221,8 @@ export default function AuthFormContent() { if (tab !== 'wechat' && wechatRef.current) { wechatRef.current.stopPolling(); } - // 切换到微信登录时,自动获取二维码 - if (tab === 'wechat' && wechatRef.current) { + // 切换到微信登录时,自动获取二维码(仅在非微信浏览器中) + if (tab === 'wechat' && wechatRef.current && !isInWeChatBrowser) { wechatRef.current.fetchQRCode(); } setActiveTab(tab); @@ -446,9 +451,10 @@ export default function AuthFormContent() { authEvents.trackLoginPageViewed(); // 组件挂载时,如果默认 Tab 是微信登录,自动获取二维码 + // 仅在非微信浏览器中才需要获取二维码 // 使用 setTimeout 确保 ref 已经绑定 const timer = setTimeout(() => { - if (activeTab === 'wechat' && wechatRef.current) { + if (activeTab === 'wechat' && wechatRef.current && !isInWeChatBrowser) { wechatRef.current.fetchQRCode(); } }, 100); @@ -532,31 +538,91 @@ export default function AuthFormContent() { ); // 渲染微信登录区域 - const renderWechatLogin = () => ( -
- -
- 扫码即表示同意{" "} - - 《用户协议》 - - {" "}和{" "} - - 《隐私政策》 - + const renderWechatLogin = () => { + // 在微信浏览器中,显示直接的微信H5登录按钮 + if (isInWeChatBrowser) { + return ( +
+ {/* 内容区小标题 */} +
+ {config.wechat.title} +
+
{config.wechat.subtitle}
+ + {/* 微信一键登录按钮 */} +
+ +
+ +
+ 点击登录即表示同意{" "} + + 《用户协议》 + + {" "}和{" "} + + 《隐私政策》 + +
+
+ ); + } + + // 非微信浏览器,显示扫码登录二维码 + return ( +
+ +
+ 扫码即表示同意{" "} + + 《用户协议》 + + {" "}和{" "} + + 《隐私政策》 + +
-
- ); + ); + }; // 渲染密码登录表单 const renderPasswordForm = () => ( @@ -661,11 +727,12 @@ export default function AuthFormContent() { if (activeTab !== 'wechat') { otherMethods.push({ key: 'wechat', - label: '微信', + label: isInWeChatBrowser ? '微信一键' : '微信', icon: , color: THEME.wechat, hoverBg: 'rgba(7, 193, 96, 0.1)', - onClick: isMobile ? handleWechatH5Login : () => handleTabChange('wechat'), + // 微信浏览器内直接调用H5登录,否则切换到微信Tab + onClick: isInWeChatBrowser ? handleWechatH5Login : (isMobile ? handleWechatH5Login : () => handleTabChange('wechat')), }); } @@ -741,7 +808,7 @@ export default function AuthFormContent() { // 获取右上角提示文字 const getCornerTooltip = () => { if (activeTab === 'wechat') return '切换到验证码登录'; - return '切换到微信登录'; + return isInWeChatBrowser ? '切换到微信一键登录' : '切换到微信登录'; }; // 渲染内容区域