fix: 修复扫一扫登录
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 47s

This commit is contained in:
sexygoat
2026-04-17 10:51:10 +08:00
parent 715e4f6f7d
commit 16a47c1229
2 changed files with 11 additions and 9 deletions

View File

@@ -124,12 +124,12 @@
doLogin(); doLogin();
}; };
const handleScanLogin = async () => { const handleScanLogin = async () => {
// #ifdef H5 // #ifdef H5
const ready = await initWxSdk(); const result = await initWxSdk();
console.log(ready); console.log('微信SDK初始化结果:', result);
if (!ready) { if (!result.success) {
uni.showToast({ title: '扫一扫功能暂不可用', icon: 'none' }); uni.showToast({ title: result.error || '扫一扫功能暂不可用', icon: 'none' });
return; return;
} }
wx.scanQRCode({ wx.scanQRCode({

View File

@@ -1,7 +1,9 @@
import { wechatApi } from '@/api/index.js'; import { wechatApi } from '@/api/index.js';
export const initWxSdk = async () => { export const initWxSdk = async () => {
if (typeof wx === 'undefined') return false; if (typeof wx === 'undefined') {
return { success: false, error: '请在微信中打开' };
}
try { try {
const currentUrl = window.location.href.split('#')[0]; const currentUrl = window.location.href.split('#')[0];
@@ -19,14 +21,14 @@ export const initWxSdk = async () => {
}); });
return new Promise((resolve) => { return new Promise((resolve) => {
wx.ready(() => resolve(true)); wx.ready(() => resolve({ success: true }));
wx.error((err) => { wx.error((err) => {
console.error('wx.config error:', err); console.error('wx.config error:', err);
resolve(false); resolve({ success: false, error: err.errMsg || '微信配置失败' });
}); });
}); });
} catch (e) { } catch (e) {
console.error('WX SDK init failed', e); console.error('WX SDK init failed', e);
return { success: false, error: e.message || '获取微信配置失败' };
} }
return false;
}; };