方法

/** * 选择上传照片 * page_that:调用方法的页面, * cb_key:返回参数数组的名称 * count:上传张数 * 返回值:数组 */function selecImg(page_that, cb_key, count) {  console.log("选择图片");  wx.chooseImage({    count: count,    sizeType: ['compressed'],    sourceType: ['album', 'camera'],    success: function(res) {      console.log(res)      var pathArray = [];      var PicNums = res.tempFiles.length;      for (var inta = 0; inta < PicNums; inta++) {        var size = res.tempFiles[inta].size;        var path = res.tempFiles[inta].path;        var formatImage = path.split(".")[(path.split(".")).length - 1];        console.log("图片格式" + formatImage)        if (formatImage != "png" && formatImage != "jpg" && formatImage != "jpeg") {          return wx.showToast({            title: '只能上传.png、.jpg、.jpep 格式',            icon: 'none',            image: '',            duration: 2000,            mask: true,          })        }        if (config.image_size < size) {          return wx.showToast({            title: '图片大小限制:' + (config.image_size / 1024 / 1024) + "MB",  ///config.image_size 配置文件中设置            icon: 'none',            image: '',            duration: 1500,            mask: true,          })        }        pathArray.push(path);        if (inta == PicNums-1) {          var cb = {};          cb[cb_key] = pathArray;          page_that.setData(cb);        }      }    }  })}
.wxml
<image src="../../Image/bg_pic1.png" mode='widthFix' style="width:100px" bindtap='Oncarm' data-whopic='idcard'></image>

.js 调用

 Oncarm: function(e) {    var whopic = e.currentTarget.dataset.whopic;    /**     * page_that:调用方法的页面,     * cb_key:返回参数数组的名称,     * count:上传张数,     * 返回值:数组     */    util.selecImg(this, whopic, 1);  },

小程序

TAG标签: 小程序微信上传视频大小限制

http://www.xiaochengxub.com/read-107225.html