一、点击拉起分享
- 点击分享按钮拉起微信分享界面(代码)
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));
}
);
},
}