zoukankan      html  css  js  c++  java
  • 小程序实现下载图片到手机及文字到手机粘贴板

    1、按钮

    <button bindtap="downloadImages">
    2、实现
    downloadImages: function() {
    this.setData({
    shareName: null
    })
    //复制文本
    let share = this.data.product.goodsDto.share;
    console.log("share=", share);
    wx.setClipboardData({
    data: share,
     
    success: function(res) {
    wx.showToast({
    title: '复制成功',
    duration: 1000
    })
    wx.hideToast();
    }
    })
    //复制图片
    
    
    wx.getSetting({
    success: (res) => {
    console.log("scope.writePhotosAlbum的状态", res.authSetting['scope.writePhotosAlbum']);
    if (res.authSetting['scope.writePhotosAlbum'] == false) {
    wx.openSetting({
    success(settingdata) {
    console.log("======settingdata=======", settingdata)
    },
    fail(res) {
    console.log("再次发起授权失败了")
    }
    })
    }
     
    }
    })
    
    
    // let image = this.data.product.images3;
    
    // let img1 = [];
    // for (let j = 0; j < image.length; j++) {
    // img1.push(image[j].uri);
    // }
    
    var img1 = ["https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3892521478,1695688217&fm=26&gp=0.jpg", "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1694681277,1453280371&fm=26&gp=0.jpg"];
    
    console.log("uri", img1);
    let count = 0;
    for (let i = 0; i < img1.length; i++) {
    
    wx.downloadFile({
    url: img1[i],
    success: function(res) {
    console.log("图片保存到本地", res);
    //图片保存到本地
    wx.saveImageToPhotosAlbum({
    // filePath: res.tempFilePath,
    filePath: res.tempFilePath,
    success: function(data) {
    count++;
    wx.showLoading({
    title: '保存中...',
    mask: true,
    });
    console.log("count", count);
    console.log("img1.length=", img1.length);
    if (img1.length === count) {
    if (img1.length === count) {
    wx.showToast({
    title: '保存成功',
    icon: 'success',
    duration: 1000
    })
    } else {
    wx.showToast({
    title: '请重新保存',
    duration: 1000
    })
    }
    }
    
    console.log("data:",data);
    },
    fail: function(err) {
    console.log("err=", err);
    if (err.errMsg == "saveImageToPhotosAlbum:fail auth deny") {
    wx.showToast({
    title: '请授权下载',
    duration: 1000,
    icon:'none'
    })
    console.log("用户一开始拒绝了,再次发起授权")
    console.log('打开设置窗口')
    
    }
    }
    })
    },
    fail: function(err) {
    wx.showToast({
    title: '请重新下载',
    duration: 1000
    })
    }
    })
    
    }
    },
     
  • 相关阅读:
    oracle安装过程中遇到的问题
    HttpContext.Current 的缺陷
    oracle 复杂语句
    .net 中 ref out params的区别
    查看修改mysql编码方式[转载]
    Oracle 中的dual是什么东西
    KindEditor问题汇总【不定时更新】
    java中import、package作用和用法
    [笔记]: 哈弗曼树(最优二叉树) 标签: 二叉树 2017-05-17 16:38 34人阅读 评论(0) 收
    [noip 2004普及组] FBI树 标签: 二叉树递归 2017-05-17 14:29 40人阅读 评论(0)
  • 原文地址:https://www.cnblogs.com/ki16/p/14527888.html
Copyright © 2011-2022 走看看