<camera
device-position="back"
flash="off"
style="width: 100%; height: 560rpx"
mode="scanCode"
bindinitdone="initdone"
binderror="catchCamera"
/>
initdone(e) {
const c = wx.createCameraContext()
const max = e.detail.maxZoom
c.setZoom({
zoom: 1,
fail: e => {
console.log(e)
}
})
}
报错:errMsg: operateCamera:fail: zoom multiple not support
根据日志发现大部分机型集中华为、荣耀、vivo
setZoom 设置的值为小数时,使其为一位小数试试
handleZoom(type) {
// 0缩小 1放大
let z = this.current
if (type === 1) {
if (z >= this.maxZoom) {
return this.$msg('已达到最大缩放级别')
}
z = +(this.current + 0.2).toFixed(1)
if (z > this.maxZoom) {
z = this.maxZoom
}
} else {
if (z <= 1) {
return this.$msg('已达到最小缩放级别')
}
z = +(this.current - 0.2).toFixed(1)
if (z < 1) {
z = 1
}
}
this.current = z
this.$emit('zoom', this.current)
uni.setStorageSync('cameraZoom', z)
},