親自寫的項目~~
1.需要引入mui.js
2.拿我代碼去開發吧~~~~
<template>
<div>
<input type="button" value="微信分享" @click="shareHref()" />
</div>
</template>
<script>
var Intent = null,
File = null,
Uri = null,
main = null;
var shares = null;
var shareImageUrl = '';
export default {
methods: {
shareHref() {
let _this = this
var ids = [{
id: "weixin",
ex: "WXSceneSession" /*微信好友*/
}, {
id: "weixin",
ex: "WXSceneTimeline" /*微信朋友圈*/
}],
bts = [{
title: "發送給微信好友"
}, {
title: "分享到微信朋友圈"
}];
plus.nativeUI.actionSheet({
cancel: "取消",
buttons: bts
},
function(e) {
var i = e.index;
if(i > 0) {
_this.shareAction(ids[i - 1].id, ids[i - 1].ex);
}
}
);
},
shareAction(id, ex) {
alert('點選按鈕')
let _this = this
var s = null;
if(!id || !(s = shares[id])) {
alert('點選按鈕11')
_this.outLine("無效的分享服務!");
return;
}
alert('微信嗎'+id)
if(s.authenticated) {
_this.outSet("---已授權---");
_this.shareMessage(s, ex);
} else {
_this.outSet("---未授權---");
s.authorize(function() {
_this.shareMessage(s, ex);
}, function(e) {
_this.outLine("認證授權失敗");
});
}
},
outLine(msg) {
mui.toast(msg);
},
outSet(msg) {
alert(msg)
console.log(msg);
},
updateSerivces() {
let _this = this
plus.share.getServices(function(s) {
shares = {};
for(var i in s) {
var t = s[i];
shares[t.id] = t;
}
_this.outSet("擷取分享服務清單成功");
alert(299)
}, function(e) {
_this.outSet("擷取分享服務清單失敗:" + e.message);
});
},
shareMessage(s, ex) {
let AppID = '789'
var msg = {
content: 'ceshi',
href: 'http://www.xxx/xx.html?id='+AppID, //換成你自己的
title: '測試标題',
content: '測試内容',
thumbs: ["img/mmexp.png"],
pictures: ["img/mmexp.png"],
extra: {
scene: ex
}
};
alert('授權中w')
s.send(msg, function() {
_this.outLine("分享成功!");
}, function(e) {
_this.outLine("分享失敗!");
});
},
},
created () {
let _this = this
mui.plusReady(function() {
_this.updateSerivces();
if (window.plus) {
document.addEventListener('plusready', _this.updateSerivces())
} else {
alert('PC端')
}
})
},
}
</script>