fix(mp): 小程序真机 TextEncoder 不可用 + DevTools getPhoneNumber 绕过
- secure-storage-aes.ts 用纯 JS 实现 UTF-8 编解码替代 TextEncoder/TextDecoder - 登录页绑定手机号步骤:DevTools/模拟器中跳过微信 SDK 直接调后端 mock
This commit is contained in:
@@ -99,6 +99,24 @@ export default function Login() {
|
||||
}
|
||||
};
|
||||
|
||||
// DevTools 中 getPhoneNumber 不可用,直接传 mock 数据绕过微信 SDK
|
||||
const handleDevBindPhone = async () => {
|
||||
try {
|
||||
const success = await bindPhone('dev_mock', 'dev_mock');
|
||||
if (success) {
|
||||
navigateAfterLogin();
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
Taro.showModal({
|
||||
title: '绑定失败',
|
||||
content: err instanceof Error ? err.message : '绑定失败',
|
||||
confirmText: '重新登录',
|
||||
cancelText: '取消',
|
||||
success: (res) => { if (res.confirm) setNeedBind(false); },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<View className="login-page">
|
||||
{/* 品牌区 */}
|
||||
@@ -120,15 +138,29 @@ export default function Login() {
|
||||
</>
|
||||
) : (
|
||||
<View className="login-bind-section">
|
||||
<Button
|
||||
className="login-btn-bind"
|
||||
openType="getPhoneNumber"
|
||||
onGetPhoneNumber={handleGetPhone}
|
||||
loading={loading}
|
||||
disabled={loading}
|
||||
>
|
||||
授权手机号完成绑定
|
||||
</Button>
|
||||
{/* 真机:微信手机号授权 */}
|
||||
{!(IS_DEV || IS_SIMULATOR) && (
|
||||
<Button
|
||||
className="login-btn-bind"
|
||||
openType="getPhoneNumber"
|
||||
onGetPhoneNumber={handleGetPhone}
|
||||
loading={loading}
|
||||
disabled={loading}
|
||||
>
|
||||
授权手机号完成绑定
|
||||
</Button>
|
||||
)}
|
||||
{/* DevTools:跳过微信 SDK 直接调后端(后端 wechat_dev_mode 会用 mock 手机号) */}
|
||||
{(IS_DEV || IS_SIMULATOR) && (
|
||||
<Button
|
||||
className="login-btn-bind"
|
||||
onClick={handleDevBindPhone}
|
||||
loading={loading}
|
||||
disabled={loading}
|
||||
>
|
||||
授权手机号完成绑定(开发模式)
|
||||
</Button>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user