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:"无法获取正确的路劲拍照失败"
})
}
});
}
0 个回复