当前位置:   article > 正文

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

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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
//该方法是将当前页面绘制成图片保存到本地然后调用分享方法。
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);    
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/287093
推荐阅读