易软
易软
  • 发布:2025-04-22 10:53
  • 更新:2025-04-22 10:53
  • 阅读:23

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

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: windows11

HBuilderX类型: 正式

HBuilderX版本号: 3.8.7

手机系统: Android

手机系统版本号: Android 12

手机厂商: 小米

手机机型: 红米 note 11

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

App下载地址或H5⽹址: 应用市场 搜索 易软云

示例代码:

compressImage(src) {
return new Promise((resolve, reject) => {
uni.compressImage({
src: src,
quality: 30, // 质量压缩(0-100)
width: '50%', // 宽度按比例压缩
success: (res) => resolve(res.tempFilePath),
fail: reject
});
});
},
chooseImg(item){
uni.chooseImage({
count: 8,
sourceType: ['camera'],
sizeType: ['compressed'],
sourceType: this.sourceType,
success: res => {
console.log(res)
if (res.errMsg == 'chooseImage:ok') {
res.tempFilePaths.map(async items => {
// #ifdef APP
if(items.indexOf(".jpg") !=-1){
let compressed = await this.compressImage(items)
console.log(compressed)
if(compressed){
uni.saveFile({
tempFilePath: compressed,
success:res => {
console.log(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: compressed });
isProcessing = false
}
});
}else{
uni.saveFile({
tempFilePath: items,
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 });
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
});
}
},
fail:err=>{
isProcessing = false;
uni.showToast({
icon:"none",
title:"无法获取正确的路劲拍照失败"
})

                        }  
                    });  

}

操作步骤:

进入工作台 点击 设备任务 已接任务 开始任务 选择 图片

预期结果:

能够正常的拍照显示图片

实际结果:

拍摄多张后无法显示

bug描述:

由于项目上要做离线数据,且离线的数据哦拍照的数量有点多,可能多达100张+ 。之前测试了在线拍照 还是比较流畅,但是在离线状态下自己将手机设置为飞行模式,然后进行拍照发现拍了十多张后就卡死了,自己也做了图片压缩和删除临时图片地址还是不行。
而且发现 在在线模式下 在 chooseImage 进程 compressImage 进程 saveFile 进程下 我打出数据log出来很快,但是一断网 log 就很慢。是否这几个API 需要有联网状态下的I/O处理
而且 拍照多了 直接进入了fail 显示
{
"errMsg": "chooseImage:fail 路径不存在",
"errCode": 14,
"code": 14
}

2025-04-22 10:53 负责人:无 分享
已邀请:

要回复问题请先登录注册