zoukankan      html  css  js  c++  java
  • 点击保存图片

    写法一:

    //点击保存图片
    save() {
    let that = this
     
    //若二维码未加载完毕,加个动画提高用户体验
    wx.showToast({
    icon: 'loading',
    title: '正在保存图片',
    duration: 1000
    })
    //判断用户是否授权"保存到相册"
    wx.getSetting({
    success(res) {
    //没有权限,发起授权
    if (!res.authSetting['scope.writePhotosAlbum']) {
    wx.authorize({
    scope: 'scope.writePhotosAlbum',
    success() { //用户允许授权,保存图片到相册
    that.savePhoto();
     
    },
    fail() { //用户点击拒绝授权,跳转到设置页,引导用户授权
    wx.openSetting({
    success() {
    wx.authorize({
    scope: 'scope.writePhotosAlbum',
    success() {
    that.savePhoto();
    }
    })
    }
    })
    }
    })
    } else { //用户已授权,保存到相册
    that.savePhoto()
    }
    }
    })
    },
    //下载图片地址并保存到相册,提示保存成功
    savePhoto() {
    let that = this
    wx.downloadFile({
    url: that.data.img,
    success: function(res) {
    wx.saveImageToPhotosAlbum({
    filePath: res.tempFilePath,
    success(res) {
    wx.showToast({
    title: '保存成功',
    icon: "success",
    duration: 1000
    })
    }
    })
    }
    })
    }
     
     
     
  • 相关阅读:
    【布局】483- 推荐 15 种水平垂直居中布局方案
    【Web技术】482- 浏览器将标签转成 DOM 的过程
    int和Integer的区别
    Rendom类
    java注释
    linux
    AI
    重载和重写
    Iterator接口
    集合和数组的区别
  • 原文地址:https://www.cnblogs.com/Annely/p/11168813.html
Copyright © 2011-2022 走看看