Browse Source

保存图片

twt 3 years ago
parent
commit
4a12a92b0e
1 changed files with 37 additions and 7 deletions
  1. 37 7
      pages/me/inviteImg.vue

+ 37 - 7
pages/me/inviteImg.vue

@@ -16,9 +16,9 @@
 		
 		data() {
 			return {
-				
+				base64:'',
 				qrImg: '',
-				 openSettingBtnHidden: true,//是否授权
+				openSettingBtnHidden: true,//是否授权
 			}
 		},
 		onLoad() {
@@ -44,7 +44,7 @@
 				this.$httpBinary(url, params, 'GET').then(res => {
 					uni.hideLoading();
 
-
+                    this.base64=uni.arrayBufferToBase64(res)
 					this.qrImg = 'data:image/png;base64,' + uni.arrayBufferToBase64(res)
 					
 				})
@@ -57,12 +57,40 @@
 			                content: '确定要保存图片吗',
 			                success: e => {
 			                    if (e['confirm']) {
-			                        this.saveImgFile();
+			                        //this.saveImgFile();
+									this.saveImageToPhotosAlbum()
 			                    }
 			                }
 			            });
 			        },
-					
+					saveImageToPhotosAlbum(){
+						let base64=this.base64;
+						let fileName = new Date().getTime();
+						 let filePath=wx.env.USER_DATA_PATH + `/hym_pay${fileName}_qrcode.png`;
+						 uni.getFileSystemManager().writeFile({
+						                 filePath:filePath ,  //创建一个临时文件名
+						                 data: base64,    //写入的文本或二进制数据
+						                 encoding: 'base64',  //写入当前文件的字符编码
+						                 success: res => {
+						                     uni.saveImageToPhotosAlbum({
+						                         filePath: filePath,
+						                         success: function(res2) {
+						                             uni.showToast({
+						                                 title: '保存成功,请从相册选择再分享',
+						                                 icon:"none",
+						                                 duration:5000
+						                             })
+						                         },
+						                         fail: function(err) {
+						                             // console.log(err.errMsg);
+						                         }
+						                     })
+						                 },
+						                 fail: err => {
+						                     //console.log(err)
+						                 }
+						             })
+					},
 					//微信小程序保存到相册
 					      
 							
@@ -76,14 +104,16 @@
 					                       scope: 'scope.writePhotosAlbum',
 					                       success() {
 					                         //这里是用户同意授权后的回调
-					                         that.saveBase64Img(that.qrImg);
+					                         //that.saveBase64Img(that.qrImg);
+											 that.saveImageToPhotosAlbum()
 					                       },
 					                       fail() {//这里是用户拒绝授权后的回调
 					                           that.openSettingBtnHidden=false
 					                       }
 					                     })
 					                   } else {//用户已经授权过了
-					                     that.saveBase64Img(that.qrImg);
+					                     //that.saveBase64Img(that.qrImg);
+										 that.saveImageToPhotosAlbum()
 					                   }
 					                 }
 					               })