uniApp实现微信分享页面/二维码功能

需求:点击分享页面的分享到微信/wx朋友圈按钮将该页面分享到对应路径。

<view class="content">
   <image :src="src" class="qrcode"></image>
   <view class="btn">
		<view>
			<image @tap="shareWeiXin('WXSceneSession')" src="../../../../static/fxb1.jpg" class="wxfx"></image>
		</view>
		<view>
			<image @tap="shareWeiXin('WXSenceTimeline')" src="../../../../static/fxb2.jpg" class="wxfx"></image>
		</view>
		<view class="wx">
			邀请码: {{invitation}}
		</view>
	</view>
</view>
//该方法是将当前页面绘制成图片保存到本地然后调用分享方法。
shareWeiXin(scene){
	let _this = this
	let sc = scene
	_this.capture(sc)
},
capture(scene) {
  let _this = this
  let pages = getCurrentPages();
  let page = pages[pages.length - 1];
  let bitmap=null;  
  let currentWebview = page.$getAppWebview();    
  bitmap = new plus.nativeObj.Bitmap('amway_img');  
  // 将webview内容绘制到Bitmap对象中  
  currentWebview.draw(bitmap,function(){  
      console.log('截屏绘制图片成功');  
      // bitmap.save( "_doc/"+Math.random()+".jpg"
      bitmap.save( "_doc/invite.jpg"
      ,{}  
      ,function(i){  
          console.log('保存图片成功:'+JSON.stringify(i));  
          uni.saveImageToPhotosAlbum({  
              filePath: i.target,  
              success: function () {
_this.path = i.target
                  bitmap.clear(); //销毁Bitmap图片  
                  uni.showToast({  
                      title: '保存图片成功',  
                      mask: false,  
                      duration: 1500  
                  }); 
				uni.share({
					provider: "weixin",
					scene: scene,
					type: 2,
					imageUrl : _this.path,
					success: function (res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function (err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
              } 
          });  
      }  
      ,function(e){  
          console.log('保存图片失败:'+JSON.stringify(e));  
      });  
  },function(e){  
      console.log('截屏绘制图片失败:'+JSON.stringify(e));  
  });  
  //currentWebview.append(amway_bit);    
}

如果是要单独分享二维码就简单地多了,不过值得注意的一点是uni.share不支持分享base64,所以如果是base64的话要先将其转成path路径。官方论坛有人发布了一款工具images-tools.js可以实现

https://ask.dcloud.net.cn/article/35512

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值