zoukankan      html  css  js  c++  java
  • 小程序保存图片的坑

    saveHB: function () {
        console.log('保存海报');
        // wx.navigateTo({
        //   url: '/pages/hualang/shengchenghb/taskCardPost',
        // })
          var that =this;
          wx.showLoading({
            title: '保存中...',
          })
          wx.downloadFile({
           url: that.data.iteminfo.framed_url,
            success: function (res) {
              wx.hideLoading()
               var imageFilePath = res.tempFilePath;
                  if (imageFilePath!='') {
                   wx.saveImageToPhotosAlbum({
                   filePath: imageFilePath,
                   success: function (data) {
                   wx.showToast({
                   title: "保存成功",
                   })
                 }, 
                 fail: function (err) {
                  if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg ==="saveImageToPhotosAlbum:fail authorize no response") {
                    // 这边微信做过调整,必须要在按钮中触发,因此需要在弹框回调中进行调用
                    wx.showModal({
                      title: '提示',
                      content: '需要您授权保存相册',
                      showCancel: false,
                      success:modalSuccess=>{
                        wx.openSetting({
                          success(settingdata) {
                            console.log("settingdata", settingdata)
                            if (settingdata.authSetting['scope.writePhotosAlbum']) {
                              wx.showModal({
                                title: '提示',
                                content: '获取权限成功,再次点击图片即可保存',
                                showCancel: false,
                              })
                            } else {
                              wx.showModal({
                                title: '提示',
                                content: '获取权限失败,将无法保存到相册哦~',
                                showCancel: false,
                              })
                            }
                          },
                          fail(failData) {
                            console.log("failData",failData)
                          },
                          complete(finishData) {
                            console.log("finishData", finishData)
                          }
                        })
                      }
                    })
                  }
                },
                complete(res) {
                  wx.hideLoading()
                }
           })
           }
         },
         
        })
      },
     上面的代码是解决权限问题的,还有一个坑就是真机调试是好的,体验版本保存不了,后来发现是图片路径的域名不合法。

     必须设置downloadFile合法域名

  • 相关阅读:
    HDU 5115 Dire Wolf (区间DP)
    HDU 4283 You Are the One(区间DP(最优出栈顺序))
    ZOJ 3469 Food Delivery(区间DP好题)
    LightOJ 1422 Halloween Costumes(区间DP)
    POJ 1651 Multiplication Puzzle(区间DP)
    NYOJ 石子合并(一)(区间DP)
    POJ 2955 Brackets(括号匹配一)
    POJ 1141 Brackets Sequence(括号匹配二)
    ZOJ 3537 Cake(凸包+区间DP)
    Graham求凸包模板
  • 原文地址:https://www.cnblogs.com/wupeng88/p/12360571.html
Copyright © 2011-2022 走看看