<view class="scan_qrcode">
<button class="scan_qrcode_button tap-item-active" @click="handleScanCode">扫码绑定用户</button>
</view>
/**
* 检查有没有开启摄像头权限
*/
// #ifdef APP-PLUS
const checkPermission = async ():Promise<number> => {
let status = permision.isIOS ? await permision.requestIOS('camera') : await permision.requestAndroid('android.permission.CAMERA');
if (status === null || status === 1) {
status = 1;
} else {
uni.showModal({
content: "需要相机权限",
confirmText: "设置",
success: function(res) {
if (res.confirm) {
permision.gotoAppSetting();
}
}
})
}
return status as number;
}
// #endif
const handleScanCode = async (): Promise<void> => {
// #ifdef APP-PLUS
let status = await checkPermission();
if (status !== 1) return;
// #endif
uni.scanCode({
onlyFromCamera: true,
success: (res: UniApp.ScanCodeSuccessRes) => {
console.log(res);
},
fail: () => {
console.log('error--')
}
})
}
JimmyLee
大佬解决了吗?遇到同样问题
2022-09-01 11:17