微信小程序点击保存到手机相册

        clickCanvas() {
            console.log("点击按钮保存");
            let rpx = this.rpx;
            let that = this;
            // let width = 357 * rpx;
            // let height = 579 * rpx;
            let width = that.canvasWidth;
            let height = that.canvasHeight;
            Taro.canvasToTempFilePath({
                x: 0,
                y: 0,
                width,
                height,
                destWidth: width,
                destHeight: height,
                quality: 1,
                fileType: "jpg",
                canvasId: "poster",
                success: function(res) {
                    wx.saveImageToPhotosAlbum({
                        filePath: res.tempFilePath,
                        success: result => {
                            Taro.showToast({
                                title: "保存成功,从相册中分享到朋友圈吧!",
                                icon: "none"
                            });
                        },
                        fail: err => {
                            if (
                                err.errMsg ===
                                    "saveImageToPhotosAlbum:fail:auth denied" ||
                                err.errMsg ===
                                    "saveImageToPhotosAlbum:fail auth deny"
                            ) {
                                Taro.showModal({
                                    title: "提示",
                                    content: "需要您授权保存相册",
                                    showCancel: false,
                                    success: modalSuccess => {
                                        Taro.openSetting({
                                            success(settingdata) {
                                                if (
                                                    settingdata.authSetting[
                                                        "scope.writePhotosAlbum"
                                                    ]
                                                ) {
                                                    Taro.showModal({
                                                        title: "提示",
                                                        content:
                                                            "获取权限成功,再次点击即可保存",
                                                        showCancel: false
                                                    });
                                                } else {
                                                    Taro.showModal({
                                                        title: "提示",
                                                        content:
                                                            "获取权限失败,将无法保存到相册哦~",
                                                        showCancel: false
                                                    });
                                                }
                                            },
                                            fail(failData) {},
                                            complete(finishData) {}
                                        });
                                    }
                                });
                            }
                        }
                    });
                }
            });
        },
posted @ 2021-07-14 14:22  Wayhome'  阅读(408)  评论(0)    收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css