微信小程式點選儲存到手機相簿
阿新 • • 發佈:2021-07-14
注:以上內容僅用於日常學習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) {} }); } }); } } }); } }); },