uniapp 上传指定jpg,png格式图片 |
您所在的位置:网站首页 › 图片的png格式 › uniapp 上传指定jpg,png格式图片 |
// 上传图片前事件
chooseImage: async function() {
if (this.imageList.length === 6) {
let isContinue = await this.isFullImg();
if (!isContinue) {
return;
}
}
uni.chooseImage({
sourceType: sourceType[this.sourceTypeIndex],
sizeType: sizeType[this.sizeTypeIndex],
count:
this.imageList.length + this.count[this.countIndex] > 6
? 6 - this.imageList.length
: this.count[this.countIndex],
success: res => {
// 上传图片前判断是否为jpg,png格式
let url = res.tempFiles[0].name;
//获取最后一个.的位置
let index = url.lastIndexOf(".");
//获取后缀
let jpgUrl = url.substr(index + 1);
if (jpgUrl != "png" && jpgUrl != "jpg" && jpgUrl != "jpeg") {
uni.showToast({
icon: "none",
title: "请上传格式为jpg,png"
});
} else {
// 自带的压缩,压缩后的略大一些
this.imageList = this.imageList.concat(res.tempFilePaths); //非APP平台不支持自定义压缩,暂时没有处理,可通过uni-app上传组件的sizeType属性压缩
}
}
});
},
chooseImage: async function() { if (this.imageList.length === 6) { let isContinue = await this.isFullImg(); if (!isContinue) { return; } } uni.chooseImage({ sourceType: sourceType[this.sourceTypeIndex], sizeType: sizeType[this.sizeTypeIndex], count: this.imageList.length + this.count[this.countIndex] > 6 ? 6 - this.imageList.length : this.count[this.countIndex], success: res => { // 上传图片前判断是否为jpg,png格式 let url = res.tempFiles[0].name; //获取最后一个.的位置 let index = url.lastIndexOf("."); //获取后缀 let jpgUrl = url.substr(index + 1); if (jpgUrl != "png" && jpgUrl != "jpg" && jpgUrl != "jpeg") { uni.showToast({ icon: "none", title: "请上传格式为jpg,png" }); } else { // 自带的压缩,压缩后的略大一些 this.imageList = this.imageList.concat(res.tempFilePaths); //非APP平台不支持自定义压缩,暂时没有处理,可通过uni-app上传组件的sizeType属性压缩 } } }); }, |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |