微信小程序,长按图片保存图片到相册功能


    SaveImg: function (file) {
        var _self = this;
        wx.showModal({content: '扫码券:保存到相册?',
            success(res){
                if (res.confirm) {
                    _self.SaveFile(file);
                }
            }
        });
    },
    SaveFile: function (file) {
        var _self = this;
        if(file.substring(0,4)=='http'&&file.indexOf("http://tmp/")==-1){
            wx.downloadFile({url:file,success: function(res) {
                    _self.SaveFile(res.tempFilePath);
                }});
        }else{
            wx.getSetting({
                success(res) {
                    if (!res.authSetting['scope.writePhotosAlbum']) {
                        wx.authorize({scope: 'scope.writePhotosAlbum',
                            success() {
                                _self.SavePath(file);
                            }
                        });
                    }else{
                        _self.SavePath(file);
                    }
                }
            });
        }

    },
    SavePath:function(file){
        var _self = this;
        wx.saveImageToPhotosAlbum({filePath: file,
            success(res) {
                _self.alert('扫码券:图片已保存到相册,赶紧去分享一下吧~');
            },
            fail(res) {
                wx.showToast({title: '扫码券:保存失败',icon: 'none',duration: 1000});
            }
        });
    }

扫码券微信小程序:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM