You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.8 KiB

5 years ago
//分享操作
const ids = [{
id: "weixin",
ex: "WXSceneSession"
}, {
id: "qq"
}, {
id: "sinaweibo"
}, {
id: "tencentweibo"
}]
const bts = [{
title: "分享给微信好友"
}, {
title: "分享给 QQ好友"
}, {
title: "分享到新浪微博"
}, {
title: "分享到腾讯微博"
}];
const shares = {};
mui.plusReady(function() {
plus.share.getServices(function(s) {
if(s && s.length > 0) {
for(var i = 0; i < s.length; i++) {
var t = s[i];
shares[t.id] = t;
}
}
}, function() {
console.log("获取分享服务列表失败");
});
});
class AppShare {
constructor({
href = "链接未知",
title = "标题未知",
thumbs = "logo未知"
} = {}) {
this.href = href;
this.title = title;
this.thumbs = thumbs;
}
goShare() {
plus.nativeUI.actionSheet({
cancel: "取消",
buttons: bts
}, (e) => {
var i = e.index;
if(i > 0) {
var s_id = ids[i - 1].id;
var share = shares[s_id];
var ex = ids[i - 1].ex;
var shareFun = (share, ex) => {
var msg = {
extra: {
scene: ex
}
};
[msg.href, msg.title, msg.thumbs, msg.content] = [this.href, this.title, this.thumbs, this.href];
console.log(JSON.stringify(msg));
if(~share.id.indexOf('weibo')) {
msg.content += `;体验地址:${this.href}`;
}
share.send(msg, function() {
console.log("分享到\"" + share.description + "\"成功! ");
}, function(e) {
console.log("分享到\"" + share.description + "\"失败: " + e.code + " - " + e.message);
});
}
if(share.authenticated) {
// shareMessage(share, ids[i - 1].ex);
shareFun(share, ex);
} else {
share.authorize(function() {
// shareMessage(share, ids[i - 1].ex);
}, function(e) {
console.log("认证授权失败:" + e.code + " - " + e.message);
});
}
}
});
}
}