this.chooseImage('camera');
chooseImage(type) {
if(this.isDisabledAll){
uni.showToast({
title: '会话已超时,无法发送图片',
icon: 'none'
});
return false;
}
uni.chooseImage({
count: 10, //默认9
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: [type],
success: res => {
let fileMaxNum = 9 // 图片最大上传数量
let filterFileName = ['image/png', 'image/PNG', 'image/jpg', 'image/JPG', 'image/gif', 'image/GIF', 'image/jpeg', 'image/JPEG'] // 需要的文件格式
let whetherHasErrorPic = res.tempFiles.some(i => filterFileName.indexOf(i.type) == -1) // 是否存在不需要的文件格式
if (res.tempFiles.length > fileMaxNum) {
uni.showToast({
icon: 'none',
title: 图片数量不能超过${fileMaxNum}张!
,
duration: 2500
});
return;
}
if (whetherHasErrorPic) {
uni.showToast({
icon: 'none',
title: '选择的文件格式不正确,请重新选择!',
duration: 2500
});
return;
}
}
});
},
1 个回复
Diligent_UI - 【插件开发】【专治疑难杂症】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=193663(微信搜索飘逸科技UI小程序直接体验)】【骗子请绕道】问题咨询请加QQ群:120594820,代表作灵感实用工具小程序
uni.chooseImage可能有兼容问题,试试这个插件:https://ext.dcloud.net.cn/plugin?id=12401