fix(h5-partner): make WeChat login click feedback and OAuth start reliably

This commit is contained in:
2026-08-02 12:42:55 +08:00
parent 3fc2f23e10
commit bdc9dbde8d
+23 -14
View File
@@ -14,11 +14,10 @@ import { usePartnerSession } from '../contexts/PartnerSessionContext';
import { partnerHomePath } from '../lib/partnerAccess'; import { partnerHomePath } from '../lib/partnerAccess';
import { import {
bindPartnerWechatAfterSmsLogin, bindPartnerWechatAfterSmsLogin,
canPartnerUseWechatLogin,
fetchClientConfig, fetchClientConfig,
loginPartnerWithWechat, loginPartnerWithWechat,
PARTNER_WECHAT_LOGIN_HINT,
} from '../lib/wechat-auth'; } from '../lib/wechat-auth';
import { toastError } from '../lib/toast';
import { isWechatEnv } from '../lib/weixin'; import { isWechatEnv } from '../lib/weixin';
const REMEMBER_PHONE_KEY = 'partner_remember_phone'; const REMEMBER_PHONE_KEY = 'partner_remember_phone';
@@ -114,7 +113,9 @@ export default function LoginPage() {
function ensureAgreed() { function ensureAgreed() {
if (!agreed) { if (!agreed) {
setMsg('请先勾选并同意用户协议'); const tip = '请先勾选并同意用户协议';
setMsg(tip);
toastError(tip);
agreementRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' }); agreementRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' });
return false; return false;
} }
@@ -196,25 +197,28 @@ export default function LoginPage() {
setMsg(''); setMsg('');
if (!isWechatEnv()) { if (!isWechatEnv()) {
setMsg(WECHAT_INAPP_REQUIRED_MSG); setMsg(WECHAT_INAPP_REQUIRED_MSG);
return; toastError(WECHAT_INAPP_REQUIRED_MSG);
}
const canUseWechat = await canPartnerUseWechatLogin({
profile: savedProfile,
phone,
});
if (!canUseWechat) {
setMsg(PARTNER_WECHAT_LOGIN_HINT);
return; return;
} }
setWxLoading(true); setWxLoading(true);
try { try {
// 直接发起 OAuth;未绑定账号由后端返回「请先短信登录」提示
const session = await loginPartnerWithWechat(); const session = await loginPartnerWithWechat();
if (session) { if (session) {
applySession(session); applySession(session);
await finishLoginNavigate(); await finishLoginNavigate();
return;
} }
if (session === null) {
const tip = '微信授权暂未开启,请使用验证码登录';
setMsg(tip);
toastError(tip);
}
// session === undefined:已跳转微信授权页
} catch (e) { } catch (e) {
setMsg(formatWechatError(e)); const tip = formatWechatError(e);
setMsg(tip);
toastError(tip);
} finally { } finally {
setWxLoading(false); setWxLoading(false);
} }
@@ -375,13 +379,18 @@ export default function LoginPage() {
<svg viewBox="0 0 24 24" fill="#07C160" aria-hidden> <svg viewBox="0 0 24 24" fill="#07C160" aria-hidden>
<path d="M8.25 4.5C4.52 4.5 1.5 7.04 1.5 10.17c0 1.78.98 3.37 2.5 4.48l-.63 1.88 2.19-1.09c.84.24 1.74.38 2.69.38.25 0 .5 0 .75-.03-.16-.53-.25-1.09-.25-1.66 0-3.13 3.02-5.67 6.75-5.67.57 0 1.13.06 1.66.17C15.17 6.13 12 4.5 8.25 4.5zm10.5 6.33c-3.11 0-5.62 2.12-5.62 4.73 0 2.61 2.51 4.73 5.62 4.73.79 0 1.54-.14 2.24-.38l1.83.91-.53-1.57c1.27-.92 2.08-2.25 2.08-3.73 0-2.61-2.51-4.73-5.62-4.73z" /> <path d="M8.25 4.5C4.52 4.5 1.5 7.04 1.5 10.17c0 1.78.98 3.37 2.5 4.48l-.63 1.88 2.19-1.09c.84.24 1.74.38 2.69.38.25 0 .5 0 .75-.03-.16-.53-.25-1.09-.25-1.66 0-3.13 3.02-5.67 6.75-5.67.57 0 1.13.06 1.66.17C15.17 6.13 12 4.5 8.25 4.5zm10.5 6.33c-3.11 0-5.62 2.12-5.62 4.73 0 2.61 2.51 4.73 5.62 4.73.79 0 1.54-.14 2.24-.38l1.83.91-.53-1.57c1.27-.92 2.08-2.25 2.08-3.73 0-2.61-2.51-4.73-5.62-4.73z" />
</svg> </svg>
<span>{wxLoading ? '登录中...' : '微信一键登录'}</span> <span>{wxLoading ? '跳转授权中...' : '微信一键登录'}</span>
</button> </button>
{msg && (
<p className="partner-auth-msg" style={{ color: 'var(--color-error, #d33)', fontSize: 13, textAlign: 'center' }}>
{msg}
</p>
)}
</> </>
)} )}
<p className="partner-auth-msg" style={{ textAlign: 'center' }}> <p className="partner-auth-msg" style={{ textAlign: 'center' }}>
7
</p> </p>
</div> </div>
</main> </main>