赞
踩
需求:点击分享页面的分享到微信/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可以实现