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

This commit is contained in:
sexygoat
2026-04-17 15:48:55 +08:00
parent 5dc948efec
commit 25fc534619
3 changed files with 5 additions and 58 deletions

View File

@@ -69,7 +69,7 @@
import { authApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
import { APP_ID } from '@/utils/env.js';
import { initWxConfig, wxScan, isInWechat } from '@/utils/wxsdk.js';
import { wxScan, isInWechat } from '@/utils/wxsdk.js';
const userStore = useUserStore();
@@ -80,18 +80,6 @@
}
handleWechatCallback();
getPathDeviceId();
// 初始化微信 SDK (仅在微信浏览器内执行)
// #ifdef H5
if (isInWechat()) {
try {
await initWxConfig();
console.log('微信 SDK 初始化成功');
} catch (e) {
console.error('微信 SDK 初始化失败', e);
}
}
// #endif
});
const identifier = ref('');

View File

@@ -1,42 +1,4 @@
// utils/wxsdk.js —— 封装微信扫一扫
import jweixin from 'jweixin-module'
import { wechatApi } from '@/api/index.js'
/**
* 初始化微信 JS-SDK
*/
export async function initWxConfig() {
// iOS 微信 SPA 需用首次进入的 URL 签名
const url = window.location.href.split('#')[0]
try {
// 调用后端接口获取签名
const data = await wechatApi.getJssdkConfig(url)
const { app_id, timestamp, nonce_str, signature } = data
return new Promise((resolve, reject) => {
jweixin.config({
debug: true,
appId: app_id,
timestamp: timestamp,
nonceStr: nonce_str,
signature: signature,
jsApiList: ['scanQRCode']
})
jweixin.ready(() => {
console.log('微信 SDK 就绪')
resolve()
})
jweixin.error((err) => {
console.error('wx.config 失败', err)
reject(err)
})
})
} catch (e) {
console.error('获取微信签名失败', e)
throw e
}
}
/**
* 调起微信扫一扫
@@ -44,12 +6,11 @@ export async function initWxConfig() {
*/
export function wxScan() {
return new Promise((resolve, reject) => {
jweixin.scanQRCode({
needResult: 1, // 1 = 返回结果给开发者
scanType: ['qrCode', 'barCode'], // 同时支持二维码和条形码
uni.scanCode({
scanType: ['qrCode', 'barCode'],
success(res) {
console.log('扫码成功:', res)
resolve(res.resultStr)
resolve(res.result)
},
fail(err) {
console.error('扫码失败:', err)

View File

@@ -3,14 +3,12 @@ import uni from '@dcloudio/vite-plugin-uni'
export default defineConfig({
plugins: [uni()],
// 指定项目根目录为输入目录
root: process.cwd(),
css: {
preprocessorOptions: {
scss: {
// 静默 sass 废弃警告
silenceDeprecations: ['legacy-js-api', 'import']
}
}
}
})
})