易软
易软
  • 发布:2025-04-21 17:31
  • 更新:2025-04-22 10:10
  • 阅读:85

使用uni.chooseImage选择图片在离线状态下手机无网络的情况下卡死

分类:uni-app

由于项目上要做离线数据,且离线的数据哦拍照的数量有点多,可能多达100张+ 。之前测试了在线拍照 还是比较流畅,但是在离线状态下自己将手机设置为飞行模式,然后进行拍照发现拍了十多张后就卡死了,自己也做了图片压缩和删除临时图片地址还是不行

if (isProcessing) return;  
isProcessing = true;  
uni.chooseImage({  
                            count: 8,  
                            sourceType: ['camera'],  
                            sizeType: ['compressed'],  
                            sourceType: this.sourceType,  
                            success: res => {  
                                if (res.errMsg == 'chooseImage:ok') {  
                                    res.tempFilePaths.map(items => {  
                                        // #ifdef APP  
                                        if(items.indexOf(".jpg") !=-1){  
                                            uni.compressImage({  
                                                src: items,   
                                                quality: 30 ,  
                                                success:img=>{  
                                                    uni.saveFile({  
                                                        tempFilePath: img.tempFilePath,  
                                                        success:res => {  
                                                            var savedFilePath = res.savedFilePath;  
                                                            item.fldImgList.push(savedFilePath)  
                                                            if (item.fldImgList.length > 8) {  
                                                                item.fldImgList = item.fldImgList.slice(0, 8);  
                                                            }  
                                                            uni.removeSavedFile({ filePath: items });  
                                                            uni.removeSavedFile({ filePath: img.tempFilePath });  
                                                            isProcessing = false  
                                                        }  
                                                    });  
                                                }  
                                            });  
                                        }else{  
                                            uni.saveFile({  
                                                tempFilePath: items,  
                                                success:async res => {  
                                                    var savedFilePath = res.savedFilePath;  
                                                    item.fldImgList.push(savedFilePath)  
                                                    if (item.fldImgList.length > 8) {  
                                                        item.fldImgList = item.fldImgList.slice(0, 8);  
                                                    }  
                                                    uni.removeSavedFile({ filePath: items });  
                                                    isProcessing = false  
                                                }  
                                            });   
                                        }  
                                        // #endif  
                                        // #ifdef H5  
                                        item.fldImgList.push(items);  
                                        // #endif  
                                    });  
                                }  
                            }  
                        });

isProcessing 为做的 一个全局便变量避免还未渲染的时候又点击拍照
item.fldImgList 为页面循环的数据列表的img集合,数据可能有50多个 每个都有拍照的要求。
HBuilder 的版本是 3.8.7
离线数据保存在sqlite的。
请问各位有什么好的解决办法吗? 也把相机的同步地理位置关了的!

2025-04-21 17:31 负责人:无 分享
已邀请:
易软

易软 (作者)

item.fldImgList 中的item 为方法带过来的

易软

易软 (作者)

而且发现 在在线模式下 在 chooseImage 进程 compressImage 进程 saveFile 进程下 我打出数据log出来很快,但是一断网 log 就很慢。是否这几个API 需要有联网状态下的I/O处理

易软

易软 (作者)

而且 拍照多了 直接进入了fail 显示
{
"errMsg": "chooseImage:fail 路径不存在",
"errCode": 14,
"code": 14
}

要回复问题请先登录注册