打开相册又出现扫码的bug

This commit is contained in:
BAKEYi 2026-05-26 14:29:00 +08:00
parent 0c6ce09506
commit f6ed231d12
1 changed files with 25 additions and 2 deletions

View File

@ -106,17 +106,40 @@ export default {
});
},
// 从相册选择图片并识别二维码
chooseFromAlbum() {
uni.chooseImage({
count: 1,
sourceType: ['album'], // 仅限相册
success: (res) => {
const filePath = res.tempFilePaths[0];
uni.showLoading({ title: '识别中...' });
// #ifdef APP-PLUS
// 调用 App 底层引擎,静默解析本地图片,绝不弹出原生扫码界面
plus.barcode.scan(
filePath,
(type, result) => {
uni.hideLoading();
// 成功识别到二维码,直接将内容丢给你的处理逻辑
this.handleCodeResult(result);
},
(error) => {
uni.hideLoading();
uni.showToast({ title: '未识别到有效二维码', icon: 'none' });
}
);
// #endif
// #ifndef APP-PLUS
// 非 App 环境(比如小程序兜底),才走普通的 scanCode
uni.hideLoading();
uni.scanCode({
onlyFromCamera: false,
scanType: ['qrCode'],
success: (scanRes) => {
this.handleCodeResult(scanRes.result);
}
});
// #endif
}
});
},