From 5b239c13b71119399ca8a45170263e9163d2f5c0 Mon Sep 17 00:00:00 2001 From: luo Date: Fri, 3 Jul 2026 12:17:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BB=E5=BD=95=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=9D=A1=E5=BD=A2=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/login/login.vue | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/pages/login/login.vue b/pages/login/login.vue index 1efa9b2..c2fffce 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -186,6 +186,22 @@ 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 () => { // #ifdef H5 try { @@ -199,24 +215,13 @@ const resultStr = await wxScan(); console.log('扫码结果:', resultStr); - let value = ''; - - // 解析二维码内容 - if (resultStr.includes('?')) { - const params = new URLSearchParams(resultStr.split('?')[1]); - value = params.get('cardNum') || ''; - } - - if (!value) { - const match = resultStr.match(/=([^=]+)$/); - value = match ? match[1] : ''; - } + const value = parseScanIdentifier(resultStr); if (value) { identifier.value = value; handleLogin(); } else { - uni.showToast({ title: '无效的二维码', icon: 'none' }); + uni.showToast({ title: '无效的扫码内容', icon: 'none' }); } } catch (err) { console.error('扫码错误:', err);