From b286a236ee8d9bf854ceb1e36d3708567f8514c4 Mon Sep 17 00:00:00 2001 From: kron Date: Wed, 6 Aug 2025 11:37:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/my-device.vue | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pages/my-device.vue b/src/pages/my-device.vue index 7f04b4b..a7ea70e 100644 --- a/src/pages/my-device.vue +++ b/src/pages/my-device.vue @@ -22,14 +22,22 @@ const handleScan = () => { onlyFromCamera: true, scanType: ["qrCode"], success: async (res) => { - const base64Decode = (str) => { - // 将 base64 转换为 utf8 字符串 - const bytes = wx.base64ToArrayBuffer(str); - return String.fromCharCode.apply(null, new Uint8Array(bytes)); - }; + try { + const base64Decode = (str) => { + // 将 base64 转换为 utf8 字符串 + const bytes = wx.base64ToArrayBuffer(str); + return String.fromCharCode.apply(null, new Uint8Array(bytes)); + }; - addDevice.value = JSON.parse(base64Decode(res.result)); - confirmBindTip.value = true; + addDevice.value = JSON.parse(base64Decode(res.result)); + confirmBindTip.value = true; + } catch (err) { + uni.showToast({ + title: "无效二维码", + icon: "none", + duration: 2000, + }); + } }, fail: (err) => { console.error("扫码失败:", err);