更新ios

This commit is contained in:
2026-01-23 17:35:24 +08:00
parent 5c9155a93d
commit 1d8440c9b1
2 changed files with 101 additions and 33 deletions

5
app.py
View File

@@ -3887,11 +3887,12 @@ def create_wechat_jsapi_order():
order.payment_source = 'h5' order.payment_source = 'h5'
order_no = order.order_no # 使用自动生成的订单号 order_no = order.order_no # 使用自动生成的订单号
# 关联优惠码 # 关联优惠码注意price_result 返回的是 'promo_code' 字段,不是 'promo_applied'
if promo_code and price_result.get('promo_applied'): if promo_code and price_result.get('promo_code'):
promo = PromoCode.query.filter_by(code=promo_code.upper()).first() promo = PromoCode.query.filter_by(code=promo_code.upper()).first()
if promo: if promo:
order.promo_code_id = promo.id order.promo_code_id = promo.id
print(f"📦 JSAPI订单关联优惠码: {promo.code} (ID: {promo.id})")
db.session.add(order) db.session.add(order)
db.session.commit() db.session.commit()

View File

@@ -15,6 +15,7 @@ import WechatRegister from './WechatRegister';
import { logger } from '../../utils/logger'; import { logger } from '../../utils/logger';
import { getApiBase } from '../../utils/apiConfig'; import { getApiBase } from '../../utils/apiConfig';
import { useAuthEvents } from '../../hooks/useAuthEvents'; import { useAuthEvents } from '../../hooks/useAuthEvents';
import { isWeChatBrowser } from '../MiniProgramLauncher/hooks/useWechatEnvironment';
const { Link } = Typography; const { Link } = Typography;
@@ -189,8 +190,12 @@ export default function AuthFormContent() {
const isMountedRef = useRef(true); const isMountedRef = useRef(true);
const wechatRef = useRef(null); const wechatRef = useRef(null);
// 检测是否在微信浏览器中
const isInWeChatBrowser = isWeChatBrowser();
// Tab 状态: 'wechat' | 'phone' | 'password' // 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); const [isLoading, setIsLoading] = useState(false);
@@ -216,8 +221,8 @@ export default function AuthFormContent() {
if (tab !== 'wechat' && wechatRef.current) { if (tab !== 'wechat' && wechatRef.current) {
wechatRef.current.stopPolling(); wechatRef.current.stopPolling();
} }
// 切换到微信登录时,自动获取二维码 // 切换到微信登录时,自动获取二维码(仅在非微信浏览器中)
if (tab === 'wechat' && wechatRef.current) { if (tab === 'wechat' && wechatRef.current && !isInWeChatBrowser) {
wechatRef.current.fetchQRCode(); wechatRef.current.fetchQRCode();
} }
setActiveTab(tab); setActiveTab(tab);
@@ -446,9 +451,10 @@ export default function AuthFormContent() {
authEvents.trackLoginPageViewed(); authEvents.trackLoginPageViewed();
// 组件挂载时,如果默认 Tab 是微信登录,自动获取二维码 // 组件挂载时,如果默认 Tab 是微信登录,自动获取二维码
// 仅在非微信浏览器中才需要获取二维码
// 使用 setTimeout 确保 ref 已经绑定 // 使用 setTimeout 确保 ref 已经绑定
const timer = setTimeout(() => { const timer = setTimeout(() => {
if (activeTab === 'wechat' && wechatRef.current) { if (activeTab === 'wechat' && wechatRef.current && !isInWeChatBrowser) {
wechatRef.current.fetchQRCode(); wechatRef.current.fetchQRCode();
} }
}, 100); }, 100);
@@ -532,7 +538,66 @@ export default function AuthFormContent() {
); );
// 渲染微信登录区域 // 渲染微信登录区域
const renderWechatLogin = () => ( const renderWechatLogin = () => {
// 在微信浏览器中显示直接的微信H5登录按钮
if (isInWeChatBrowser) {
return (
<div>
{/* 内容区小标题 */}
<div style={styles.contentTitle}>
<span style={styles.contentTitleText}>{config.wechat.title}</span>
</div>
<div style={styles.contentSubtitle}>{config.wechat.subtitle}</div>
{/* 微信一键登录按钮 */}
<div style={{ marginTop: '32px', marginBottom: '48px' }}>
<Button
type="primary"
size="large"
block
icon={<WechatOutlined />}
onClick={handleWechatH5Login}
style={{
height: '56px',
fontSize: '18px',
fontWeight: 'bold',
borderRadius: '12px',
background: THEME.wechat,
border: 'none',
color: '#fff',
boxShadow: '0 4px 15px rgba(7, 193, 96, 0.3)',
}}
>
微信一键登录
</Button>
</div>
<div style={styles.privacyText}>
点击登录即表示同意{" "}
<Link
href="/home/user-agreement"
target="_blank"
onClick={authEvents.trackUserAgreementClicked}
style={styles.privacyLink}
>
用户协议
</Link>
{" "}{" "}
<Link
href="/home/privacy-policy"
target="_blank"
onClick={authEvents.trackPrivacyPolicyClicked}
style={styles.privacyLink}
>
隐私政策
</Link>
</div>
</div>
);
}
// 非微信浏览器,显示扫码登录二维码
return (
<div> <div>
<WechatRegister ref={wechatRef} /> <WechatRegister ref={wechatRef} />
<div style={{ ...styles.privacyText, marginTop: '16px' }}> <div style={{ ...styles.privacyText, marginTop: '16px' }}>
@@ -557,6 +622,7 @@ export default function AuthFormContent() {
</div> </div>
</div> </div>
); );
};
// 渲染密码登录表单 // 渲染密码登录表单
const renderPasswordForm = () => ( const renderPasswordForm = () => (
@@ -661,11 +727,12 @@ export default function AuthFormContent() {
if (activeTab !== 'wechat') { if (activeTab !== 'wechat') {
otherMethods.push({ otherMethods.push({
key: 'wechat', key: 'wechat',
label: '微信', label: isInWeChatBrowser ? '微信一键' : '微信',
icon: <WechatOutlined />, icon: <WechatOutlined />,
color: THEME.wechat, color: THEME.wechat,
hoverBg: 'rgba(7, 193, 96, 0.1)', 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 = () => { const getCornerTooltip = () => {
if (activeTab === 'wechat') return '切换到验证码登录'; if (activeTab === 'wechat') return '切换到验证码登录';
return '切换到微信登录'; return isInWeChatBrowser ? '切换到微信一键登录' : '切换到微信登录';
}; };
// 渲染内容区域 // 渲染内容区域