如果想要在使用微信小程序扫码时直接扫码(不通过相册扫码),可以在wx.scanCode中写入代码:
onlyFromCamera:true,
scanCode的onlyFromCamera默认值为false,改为true即可关闭授权
完整示例代码如下:
scanCode: function () {
wx.scanCode({
onlyFromCamera:true,
success: function (resul) {
console.log(resul);
let that = this;
let tenant = wx.getStorageSync('schoolId');
if (!tenant) {
wx.navigateTo({
url: '../school/school',
})
}
wx.showToast({
title: '扫码成功...',
icon: 'success',
duration: 1500,
mask: true
});
// wx.chooseMedia({
// count:1,
// sourceType: 'camera',
// })
// wx.chooseImage({
// count:1,
// sourceType: 'camera',
// // success (res) {
// // // tempFilePath可以作为img标签的src属性显示图片
// // const tempFilePaths = res.tempFilePaths
// // }
// })
wx.request({
url: app.api + '/rider/orderModify',
method: 'get',
header: { 'content-type': 'application/json', 'tenant': tenant },
data: {
orderId: resul.result,
deliverId: wx.getStorageSync('deliverId'),
userType: wx.getStorageSync('userType')
},
success: function (res) {
if (res.data.code == 200) {
wx.showToast({
title: '扫码成功',
icon: 'success',
duration: 1200,
mask: true
});
} else {
wx.showToast({
title: '网络开小差了...',
icon: 'loading',
duration: 1200,
mask: true
});
}
}
})
}
})
},
官方接口文档地址https://developers.weixin.qq.com/miniprogram/dev/api/device/scan/wx.scanCode.html