uni.chooseImage({
count: this.imageCount, //默认9
//sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
success: (res) => {
var data = res.tempFiles[0];
let index = data.name.lastIndexOf(".");
//获取后缀
let jpgUrl = data.name.substr(index + 1);
if (jpgUrl != "png" && jpgUrl != "jpg" && jpgUrl != "jpeg") {
uni.showToast({
icon: "none",
title: "上传图片格式不符合规范,应为png、jpg或jpeg格式!",
duration: 2500
}); return;
}
const MAX_SIZE = 9 - this.imgList.length;
this.imgList = this.imgList.concat(res.tempFilePaths.slice(0, MAX_SIZE).map((
it, i) => ({
path: res.tempFilePaths[i],
file: res.tempFiles[i],
fileId: fileId++,
})))
console.log(" this.imgList:", this.imgList)
this.uploadImages()
},
fail: (err) => {
}});