小程序保存照片

8 篇文章 0 订阅

@[TOC]小程序开发//常用的小程序保存图片功能 利用mpvue开发

//触发函数
savePoster() {
      wx.getSetting({
        success: (res) => {
          if (res.authSetting['scope.writePhotosAlbum']) {
            this.wxSaveImg()
            console.log('已经授权了')
          } else if (res.authSetting['scope.writePhotosAlbum'] === undefined) {
            console.log('未授权')
            wx.authorize({
              scope: 'scope.writePhotosAlbum',
              success: () => {
                this.wxSaveImg()
              },
              fail: () => {
                wx.showToast({
                  title: '您没有授权,无法保存到相册',
                  icon: 'none'
                })
              }
            })
          } else {
            this.wxUtils.showToast('打开相册授权才能保存哦')
            wx.openSetting({
              success: (res) => {
                if (res.authSetting['scope.writePhotosAlbum']) {
                  this.saveImg()
                } else {
                  wx.showToast({
                    title: '您没有授权,无法保存到相册',
                    icon: 'none'
                  })
                }
              }
            })
          }
        }
      })
    }
保存
wxSaveImg() {
      this.wxUtils.showLoading('正在保存中')
      wx.getImageInfo({
        src: this.posterUrl,
        success: res => {
          wx.saveImageToPhotosAlbum({
            filePath: res.path,
            success: res => {
              this.wxUtils.showToast('保存成功')
              if (this.estateId) {
                this.appendEventLog({
                  eventPageAction: 6,
                  eventPage: 1,
                  dataId: this.estateId,
                  dataName: this.name,
                  dataType: 1,
                  eventDescribe: `保存了置业计划书`
                })
              }
            },
            fail: res => {
              console.log(res)
              this.wxUtils.showToast('保存失败,请重新尝试')
            },
            complete: res => {
              this.wxUtils.hideLoading('正在保存中')
              console.log(res, '结束')
            }
          })
        },
        complete: res => {
          console.log(res, 'complete')
        },
        fail: res => {
          console.log(res)
          this.wxUtils.showToast('保存失败,请重新尝试')
        }
      })
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值