yxgocn
    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});
            }
        });
    }

扫码券微信小程序:

分类:

技术点:

相关文章: