feat: 登录支持条形码
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 55s

This commit is contained in:
luo
2026-07-03 12:17:32 +08:00
parent 8397a51f8c
commit 5b239c13b7

View File

@@ -186,6 +186,22 @@
doLogin(); doLogin();
}; };
const parseScanIdentifier = (resultStr) => {
const scanValue = (resultStr || '').trim();
if (!scanValue) return '';
const barcodeMatch = scanValue.match(/^[A-Z0-9_]+,(.+)$/);
if (barcodeMatch) return barcodeMatch[1].trim();
if (scanValue.includes('?')) {
const params = new URLSearchParams(scanValue.split('?')[1]);
return params.get('cardNum') || params.get('identifier') || '';
}
const match = scanValue.match(/=([^=]+)$/);
return match ? match[1].trim() : scanValue;
};
const handleScanLogin = async () => { const handleScanLogin = async () => {
// #ifdef H5 // #ifdef H5
try { try {
@@ -199,24 +215,13 @@
const resultStr = await wxScan(); const resultStr = await wxScan();
console.log('扫码结果:', resultStr); console.log('扫码结果:', resultStr);
let value = ''; const value = parseScanIdentifier(resultStr);
// 解析二维码内容
if (resultStr.includes('?')) {
const params = new URLSearchParams(resultStr.split('?')[1]);
value = params.get('cardNum') || '';
}
if (!value) {
const match = resultStr.match(/=([^=]+)$/);
value = match ? match[1] : '';
}
if (value) { if (value) {
identifier.value = value; identifier.value = value;
handleLogin(); handleLogin();
} else { } else {
uni.showToast({ title: '无效的二维码', icon: 'none' }); uni.showToast({ title: '无效的扫码内容', icon: 'none' });
} }
} catch (err) { } catch (err) {
console.error('扫码错误:', err); console.error('扫码错误:', err);