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

This commit is contained in:
sexygoat
2026-04-17 10:45:26 +08:00
parent b3c925b0ca
commit 715e4f6f7d
2 changed files with 11 additions and 5 deletions

View File

@@ -127,6 +127,7 @@
const handleScanLogin = async () => {
// #ifdef H5
const ready = await initWxSdk();
console.log(ready);
if (!ready) {
uni.showToast({ title: '扫一扫功能暂不可用', icon: 'none' });
return;

View File

@@ -1,15 +1,17 @@
import { APP_ID } from './env.js';
import { wechatApi } from '@/api/index.js';
export const initWxSdk = async () => {
if (typeof wx === 'undefined') return false;
try {
const data = await wechatApi.getJssdkConfig(window.location.href);
const currentUrl = window.location.href.split('#')[0];
console.log('JSSDK URL:', currentUrl);
const data = await wechatApi.getJssdkConfig(currentUrl);
console.log('JSSDK Config:', data);
wx.config({
debug: false,
appId: APP_ID,
debug: true,
appId: data.app_id,
timestamp: data.timestamp,
nonceStr: data.nonce_str,
signature: data.signature,
@@ -18,7 +20,10 @@ export const initWxSdk = async () => {
return new Promise((resolve) => {
wx.ready(() => resolve(true));
wx.error(() => resolve(false));
wx.error((err) => {
console.error('wx.config error:', err);
resolve(false);
});
});
} catch (e) {
console.error('WX SDK init failed', e);