let ctx = uni.createCameraContext();
try{
console.log('ctx', ctx)
ctx.takePhoto({
quality: "normal",
success: (res) => {
console.log('进入 ctx.takePhoto success')
const updateFile = () => {
console.log('uploadImages', res.tempImagePath)
// 处理网络异常时,直接用本地存储图片
const handleNetworkAnomaly = () => {
this.showCameraing = false // 拍照完成后,关掉相机组件
const newItem = {...item, scanImage:[{url:res.tempImagePath,mediaType:'IMAGE',mediaUrl: res.tempImagePath, createTime:this.$moment().format('YYYY-MM-DD HH:mm:ss')}] }
this.onNormalCheck(newItem, SIGN_TYPE.QRCODE_SCAN)
uni.hideLoading()
}
if(this.networkConnecting) { // 有网状态直接上传,无网状态暂存数据
try {
// #ifdef MP-WEIXIN
// wxLogs.error('uploadImages之前', {时间: new Date().getTime()})
// #endif
}catch (e) {}
uploadImages(res.tempImagePath).then((imgUrl)=>{
try {
// #ifdef MP-WEIXIN
// wxLogs.error('uploadImages之完成之后', {时间: new Date().getTime()})
// #endif
}catch (e) {}
this.showCameraing = false // 拍照完成后,关掉相机组件
const newItem = {...item, scanImage:[{url:imgUrl,mediaType:'IMAGE',mediaUrl: imgUrl, createTime:this.$moment().format('YYYY-MM-DD HH:mm:ss')}] }
this.onNormalCheck(newItem, SIGN_TYPE.QRCODE_SCAN)
}).catch(err => {
handleNetworkAnomaly()
})
} else {
handleNetworkAnomaly()
}
}
fileManage.getFileInfo({
filePath: res.tempImagePath,
success: (file) => {
console.log('进入 fileManage.getFileInfo success')
try {
// #ifdef MP-WEIXIN
wxLogs.error('getFileInfo,fileSize', {title: '判断文件大小', 'fileSize': file.size, '次数': this.cameraLoopNo})
// #endif
}catch (e) {}
// sizeFlag ios拍的黑屏图片也比较大,所以小于40K的认为需要重新拍,大于4OK的一般都是可以的
if(this.cameraLoopNo > 3 || file.size > sizeFlag) {
updateFile()
} else {
setTimeout(() => {
myTakePhoto(true)
}, 300)
this.cameraLoopNo = this.cameraLoopNo + 1
}
},
fail: (error) => {
console.log('进入 fileManage.getFileInfo fail')
if(this.cameraLoopNo >5 || file.size > 20*1024) {
updateFile()
} else {
setTimeout(() => {
myTakePhoto(true)
}, 300)
this.cameraLoopNo = this.cameraLoopNo + 1
}
}
})
},
fail: e => {
// 早期配置较差的机型,有时候200毫秒无法完全初始化,增加补偿机制
if(this.cameraLoopNo >5) {
this.showCameraing = false // 拍照是失败后,也关掉相机组件
this.onNormalCheck(item, SIGN_TYPE.QRCODE_SCAN)
} else {
setTimeout(myTakePhoto, this.cameraLoopNo * 150)
this.cameraLoopNo = this.cameraLoopNo + 1
}
console.log('fail1 e :', e)
try {
// #ifdef MP-WEIXIN
// wxLogs.error('sendOrderPatrol-takePhoto', {title: '拍照失败', error: e})
// #endif
}catch (e) {}
}
});
} catch(e) {
console.error('ctx.takePhoto catch', e)
}

但问题是,鸿蒙系统,当createCameraContext 未初始化成功时,调用ctx.takePhoto 没有进入fail的回调。多以后续不长机制就时效了。
请您针对这个问题 帮忙测一下可以吗?