001. uniapp点击分享

一、点击拉起分享

  • 点击分享按钮拉起微信分享界面(代码)
var msg = {
  pictures: [img], // pictures 参数为数组  注意图片路径要是本地路径 base64也可以
  type: 'image'
};
plus.share.sendWithSystem(msg, function() {
  uni.showToast({
    title: '分享成功'
  })
}, function(e) {
  console.log('分享失败:' + JSON.stringify(e));
});

二、点击生成截图

  • 手动截屏(可根据官方文档或其他优秀up主进行参数修改,可改为自动保存至相册)

        其中  let that = this ,如遇到有关 this 指向的问题 建议直接使用箭头函数,不使用箭头函数则 声明 “let 变量 = this” 引入

data() {
		return {
			imgTarget: '', // 图片地址
			shareNum: 0,
		};
	},
methods: {
shareFn() {
			this.shareNum++;
			let that = this;
			that.imgTarget = '';
			var pages = getCurrentPages();
			var page = pages[pages.length - 1];
			// console.log('当前页' + (pages.length - 1));
			var bitmap = null;
			var currentWebview = page.$getAppWebview();
			bitmap = new plus.nativeObj.Bitmap('amway_img');
			//     将webview内容绘制到Bitmap对象中
			currentWebview.draw(
				bitmap,
				function() {
					// console.log('截屏绘制图片成功');
					bitmap.save(
						`_doc/a${that.current}-${that.shareNum}.jpg`,
						{},
						function(i) {
							that.showImg = true;
							that.imgTarget = i.target;
							bitmap.clear(); //销毁Bitmap图片
						},
						function(e) {
							console.log('保存图片失败:' + JSON.stringify(e));
						}
					);
				},
				function(e) {
					console.log('截屏绘制图片失败:' + JSON.stringify(e));
				}
			);
		},
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值