From 9f3deb5b6c9cc5205f3d4dbb3ae7eaf9168de46d Mon Sep 17 00:00:00 2001 From: duxingchen Date: Wed, 12 Aug 2026 16:53:31 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20=E6=81=A2=E5=A4=8D=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E9=A1=B5=E4=B8=BA=E5=8F=8C=E6=8C=89=E9=92=AE=E7=89=88=E6=9C=AC?= =?UTF-8?q?(=E6=8B=8D=E7=85=A7+=E7=9B=B8=E5=86=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- track-uniapp/src/pages/scan/index.vue | 167 ++++++++++++++++++++------ 1 file changed, 131 insertions(+), 36 deletions(-) diff --git a/track-uniapp/src/pages/scan/index.vue b/track-uniapp/src/pages/scan/index.vue index 0d56add..d0469ad 100644 --- a/track-uniapp/src/pages/scan/index.vue +++ b/track-uniapp/src/pages/scan/index.vue @@ -1,30 +1,50 @@ @@ -58,9 +78,12 @@ export default { } }, handleSearch() { this.doQuery(this.serialNumber.trim()); }, - handleScanCode() { + + // 📷 全屏相机扫码 + handleScanCamera() { uni.scanCode({ - onlyFromCamera: true, scanType: ["qrCode", "barCode"], + onlyFromCamera: true, + scanType: ["qrCode", "barCode"], success: (res) => { const sn = (res.result || "").replace(/[^a-zA-Z0-9]/g, "").slice(0, 16); this.doQuery(sn); @@ -72,27 +95,99 @@ export default { }, }); }, + + // 🖼️ 从相册识别二维码 + handleScanAlbum() { + uni.chooseImage({ + count: 1, + sizeType: ["original", "compressed"], + sourceType: ["album"], + success: (chooseRes) => { + const path = chooseRes.tempFilePaths[0]; + if (!path) return; + // 使用 uni.getImageInfo 获取图片后,再调用 scanCode 的 base64 模式 + // 或者直接用 #ifdef 编译条件 + // #ifdef APP-PLUS + this.decodeQRFromImage(path); + // #endif + // #ifndef APP-PLUS + uni.scanCode({ + onlyFromCamera: false, + scanType: ["qrCode"], + success: (scanRes) => { + const sn = (scanRes.result || "").replace(/[^a-zA-Z0-9]/g, "").slice(0, 16); + this.doQuery(sn); + }, + fail: () => { + uni.showToast({ title: "未识别到二维码", icon: "none" }); + }, + }); + // #endif + }, + fail: (err) => { + if (!err.errMsg || !err.errMsg.includes("cancel")) { + uni.showToast({ title: "选择失败", icon: "none" }); + } + }, + }); + }, + + // APP-PLUS: 从图片解码二维码 + decodeQRFromImage(path) { + // #ifdef APP-PLUS + plus.barcode.scan(path, (type, result) => { + const sn = (result || "").replace(/[^a-zA-Z0-9]/g, "").slice(0, 16); + this.doQuery(sn); + }, (err) => { + uni.showToast({ title: "未识别到二维码", icon: "none" }); + }, { + filters: ["QRCODE"], + scanBoth: true, + }); + // #endif + }, }, };