l***@163.com
l***@163.com
  • 发布:2018-03-02 13:19
  • 更新:2018-03-02 13:19
  • 阅读:2343

相册多选图片,压缩图片异步问题解决方案(Vue 和 html5+结合使用, 离线打包APP)

分类:HTML5+

我的是Vue项目
/**

  • 从相册选择
    */
    pictrueImg () {
    let maxImgCount = 9 - this.imgList.length
    mui("#picture").popover("hide")
    plus.gallery.pick((e) => {
    this.imgFileArray = e.files
    this.compressImg(0)
    }, (e) => {
    mui.toast('取消选择图片')
    }, {filter:"image",multiple:true,maximum:maxImgCount,system:false,onmaxed:() => {
    plus.nativeUI.alert('最多只能选择' + maxImgCount + '张图片');
    }
    })
    },
    /**
    • 递归函数压缩图片
      */
      compressImg (num) {
      var imgFile = this.imgFileArray[num]
      var name = imgFile.substr(imgFile.lastIndexOf('/') + 1)
      plus.zip.compressImage({
      src: imgFile,
      dst: '_doc/' + name,
      overwrite: true,
      quality: 50
      }, (zip) => {
      this.imgList.push({
      imgUrl: zip.target,
      imgNumber: this.imgNumber ++
      })
      this.compressImg(num + 1)
      }, (zipe) => {
      mui.toast('压缩失败!')
      })
      },
0 关注 分享

要回复文章请先登录注册