Browse Source

1.面对面邀请,图片保存

guo 3 years ago
parent
commit
52e280e047
1 changed files with 89 additions and 55 deletions
  1. 89 55
      pages/me/inviteImg.vue

+ 89 - 55
pages/me/inviteImg.vue

@@ -5,7 +5,7 @@
 			
 			<image :src="qrImg" mode="" class="QR"></image>
 		</view>
-		<image src="../../static/img/saveBtn.png" mode="" class="saveBtn" @click="toSave"></image>
+		<image src="../../static/img/saveBtn.png" mode="" class="saveBtn" @click="saveEwm"></image>
 
 	</view>
 </template>
@@ -18,11 +18,13 @@
 			return {
 				
 				qrImg: '',
+				 openSettingBtnHidden: true,//是否授权
 			}
 		},
 		onLoad() {
-			
+			 
 			this.getQR();
+			
 		},
 		methods: {
 
@@ -46,55 +48,87 @@
 					this.qrImg = 'data:image/png;base64,' + uni.arrayBufferToBase64(res)
 					
 				})
-			},
-			
-			saveImgFile() {
-			            let base64 = this.qrImg;
-			            const bitmap = new plus.nativeObj.Bitmap("test");
-			            bitmap.loadBase64Data(base64, function() {
-			                const url = "_doc/" + new Date().getTime() + ".png";  // url为时间戳命名方式
-			                console.log('saveHeadImgFile', url)
-			                bitmap.save(url, {
-			                    overwrite: true,  // 是否覆盖
-			                    quality: 'quality'  // 图片清晰度
-			                }, (i) => {
-			                    uni.saveImageToPhotosAlbum({
-			                        filePath: url,
-			                        success: function() {
-			                            uni.showToast({
-			                                title: '图片保存成功',
-			                                icon: 'none'
-			                            })
-			                            bitmap.clear()
-			                        }
-			                    });
-			                }, (e) => {
-			                    uni.showToast({
-			                        title: '图片保存失败',
-			                        icon: 'none'
-			                    })
-			                    bitmap.clear()
-			                });
-			            }, (e) => {
-			                uni.showToast({
-			                    title: '图片保存失败',
-			                    icon: 'none'
-			                })
-			                bitmap.clear()
-			            });
-			        },
-			        toSave() {
-			            uni.showModal({
-			                title: '图片保存',
-			                content: '确定要保存图片吗',
-			                success: e => {
-			                    if (e['confirm']) {
-			                        this.saveImgFile();
-			                    }
-			                }
-			            });
-			        }
+			},
+			
 			
+			        toSave() {
+			            uni.showModal({
+			                title: '图片保存',
+			                content: '确定要保存图片吗',
+			                success: e => {
+			                    if (e['confirm']) {
+			                        this.saveImgFile();
+			                    }
+			                }
+			            });
+			        },
+					
+					//微信小程序保存到相册
+					      
+							
+					        saveEwm:function(e){
+								let that = this;
+					            //获取相册授权
+					               uni.getSetting({
+					                 success(res) {
+					                   if (!res.authSetting['scope.writePhotosAlbum']) {
+					                     uni.authorize({
+					                       scope: 'scope.writePhotosAlbum',
+					                       success() {
+					                         //这里是用户同意授权后的回调
+					                         that.saveBase64Img(that.qrImg);
+					                       },
+					                       fail() {//这里是用户拒绝授权后的回调
+					                           that.openSettingBtnHidden=false
+					                       }
+					                     })
+					                   } else {//用户已经授权过了
+					                     that.saveBase64Img(that.qrImg);
+					                   }
+					                 }
+					               })
+					        },
+							
+							//#ifdef MP-WEIXIN || H5
+							saveBase64Img(base64) {
+							    
+							    const bitmap = new plus.nativeObj.Bitmap('test');
+							    
+							    bitmap.loadBase64Data(
+							        base64,
+							        function() {
+							            const url = '_doc/' + new Date() + '.png'; // url建议用时间戳命名方式
+							            console.log('url:', url);
+							            bitmap.save(
+							                url,
+							                {
+							                    overwrite: true ,// 是否覆盖
+							                    quality: 'quality' , // 图片清晰度
+							                },
+							                i => {
+							                    uni.saveImageToPhotosAlbum({
+							                        filePath: url,
+							                        success: function() {
+							                            console.log('保存成功');
+							                            bitmap.clear();
+							                        }
+							                    });
+							                },
+							                e => {
+							                    console.log('保存失败', e);
+							                    bitmap.clear();
+							                }
+							            );
+							        },
+							        e => {
+							            console.log('保存失败', e);
+							            bitmap.clear();
+							        }
+							    );
+							}
+							 //#endif
+							
+							
 
 			
 		}
@@ -123,10 +157,10 @@
 		background-color: #FFFFFF;
 		padding: 20rpx;
 
-	}
-	.QR{
-		width: 100%;
-		height: 100%;
+	}
+	.QR{
+		width: 100%;
+		height: 100%;
 	}
 
 	.saveBtn {
@@ -134,4 +168,4 @@
 		height: 115rpx;
 		margin-top: 60rpx;
 	}
-</style>
+</style>