用户端不要强制用户输入手机号

This commit is contained in:
2026-07-15 19:57:06 +08:00
parent f15d2057f2
commit 0f5f0f4c2b
14 changed files with 167 additions and 71 deletions
@@ -68,13 +68,6 @@ export default function WechatShareBootstrap() {
handleWechatAuthCallback()
.then((result) => {
if (!result) return;
if (result.needBindPhone && result.wxSessionKey) {
goLogin(returnFromLogin, {
bindMode: '1',
wxSessionKey: result.wxSessionKey,
});
return;
}
if (saveWechatLoginResult(result)) {
toast('微信授权成功', 'success');
if (
@@ -83,6 +76,14 @@ export default function WechatShareBootstrap() {
) {
finishLoginNavigate(returnFromLogin || params.get('return') || undefined);
}
return;
}
// 兼容旧接口:仅 needBindPhone 时引导可选绑定,不阻塞浏览
if (result.needBindPhone && result.wxSessionKey) {
goLogin(returnFromLogin, {
bindMode: '1',
wxSessionKey: result.wxSessionKey,
});
}
})
.catch((e) => {
+3 -6
View File
@@ -5,7 +5,7 @@ import { fetchClientConfig, fetchUserProfile, needsWechatAuthForPay } from './pa
/**
* 支付前门禁:
* - 未登录 / 未验手机 → 跳转登录页
* - 未登录 → 跳转登录页(微信授权即可,不强制手机号)
* - H5 微信内缺 openId → 尝试 OAuth(可能跳转微信授权页)
* - 小程序缺绑定 → 跳转登录页 needWechat
*/
@@ -17,10 +17,6 @@ export async function ensurePayReady(returnPath: string): Promise<boolean> {
try {
const [config, profile] = await Promise.all([fetchClientConfig(), fetchUserProfile()]);
if (!profile.phoneVerified) {
goLogin(returnPath, { needPhone: '1' });
return false;
}
if (!needsWechatAuthForPay(config, profile)) {
return true;
}
@@ -28,8 +24,9 @@ export async function ensurePayReady(returnPath: string): Promise<boolean> {
if (process.env.TARO_ENV === 'h5') {
const auth = await ensureWechatAuthForPay();
if (auth.ok) return true;
// 旧版 needBindPhone 已不再返回;缺 openId 时走登录补微信绑定
if ('needBindPhone' in auth && auth.needBindPhone) {
goLogin(returnPath, { bindMode: '1', wxSessionKey: auth.wxSessionKey });
goLogin(returnPath, { needWechat: '1' });
return false;
}
// redirecting:正在跳转微信 OAuth
+23 -7
View File
@@ -121,17 +121,18 @@ export default function LoginPage() {
}
function handleWechatLoginResult(result: WechatLoginResult, wxInfo?: MiniWechatProfile | null) {
// 微信授权成功即登录;手机号改为下单页可选绑定
if (result.accessToken) {
applySessionAndLeave(result, undefined, wxInfo);
return;
}
if (result.needBindPhone && result.wxSessionKey) {
setBindMode(true);
setWxSessionKey(result.wxSessionKey);
setMsg('微信授权成功,绑定手机号完成登录');
setMsg('微信授权成功,绑定手机号(也可跳过,稍后在下单时再绑定)');
setSentHint('');
return;
}
if (result.accessToken) {
applySessionAndLeave(result, undefined, wxInfo);
return;
}
setMsg('微信登录未完成,请重试或使用手机号登录');
}
@@ -286,13 +287,17 @@ export default function LoginPage() {
<View className="login-welcome">
<Text className="login-welcome-title">
{completeMode === 'phone'
? '完成手机验证'
? '建议绑定手机号'
: completeMode === 'wechat'
? '完成微信授权'
: '欢迎来到杜康好客'}
</Text>
<Text className="login-welcome-sub">
{completeMode ? '完成后将返回继续支付' : '买美酒,享好礼'}
{completeMode === 'phone'
? '便于订单通知与售后,也可稍后绑定'
: completeMode === 'wechat'
? '完成后将返回继续支付'
: '买美酒,享好礼'}
</Text>
</View>
</View>
@@ -365,6 +370,17 @@ export default function LoginPage() {
: '登录'}
</Text>
</View>
{completeMode === 'phone' ? (
<View
className="login-skip-bind"
onClick={() => finishLoginNavigate(returnTo)}
style={{ marginTop: 12, textAlign: 'center' }}
>
<Text className="u-muted" style={{ fontSize: 14 }}>
</Text>
</View>
) : null}
</View>
)}
@@ -1,12 +1,14 @@
import { useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useRef, useState } from 'react';
import { View, Text, Image } from '@tarojs/components';
import Taro, { useRouter } from '@tarojs/taro';
import PageShell from '../../components/PageShell';
import SubPageHeader from '../../components/SubPageHeader';
import { goLogin } from '../../lib/auth-nav';
import { buildAddressListUrl, buildPayUrl, readCheckoutContext } from '../../lib/checkout-nav';
import { tryGetClientGpsLocation } from '../../lib/client-location';
import { maskPhone } from '../../lib/phone';
import { ensurePayReady } from '../../lib/pay-ready';
import { fetchUserProfile } from '../../lib/pay-wechat';
import { request } from '../../lib/api';
import { getProductMainImage } from '../../lib/product-images';
@@ -58,6 +60,7 @@ export default function OrderConfirmPage() {
const [previewLoading, setPreviewLoading] = useState(false);
const [loading, setLoading] = useState(false);
const [msg, setMsg] = useState('');
const phonePromptSkipped = useRef(false);
useEffect(() => {
request<Address[]>('/user/addresses')
@@ -161,6 +164,30 @@ export default function OrderConfirmPage() {
}
const returnPath = `/pages/order-confirm/index?productId=${productId}&qty=${quantity}&addressId=${addressId}${forceCross ? '&cross=1' : ''}`;
if (!phonePromptSkipped.current) {
try {
const profile = await fetchUserProfile();
if (!profile.phoneVerified) {
const { confirm, cancel } = await Taro.showModal({
title: '建议绑定手机号',
content: '绑定后便于订单通知与售后联系;也可跳过,不绑定也能继续下单。',
confirmText: '去绑定',
cancelText: '暂不绑定',
});
if (confirm) {
goLogin(returnPath, { needPhone: '1' });
return;
}
if (cancel) {
phonePromptSkipped.current = true;
}
}
} catch {
/* 拉取档案失败不阻塞下单 */
}
}
const ready = await ensurePayReady(returnPath);
if (!ready) return;