
<template>
<div></div>
</template>
<script>
import Vue from 'vue'
import { mapMutations } from 'vuex'
import { mapGetters } from 'vuex'
import { mapActions } from 'vuex'
import wx from 'weixin-js-sdk';
export default {
props:{
detail : Object
},
data() {
return {
wxFile:{
title : '',
desc : '',
link : '',
imgUrl: 'https://vuejs.org/images/logo.png',
}
}
},
mounted() {
var self = this;
self.$store.dispatch('actWx',{
url: window.location.href.split('#')[0],//notice:参与签名的url不能带#号后的部分
isNeedWechatJsInfo: true
});
},
methods: {
initWx(jsSdkUiPackage) {
var self = this;
var jsApiList = [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'onMenuShareQZone'
];
var wxConfig = {
debug: true,
appId: jsSdkUiPackage.appId,
timestamp: jsSdkUiPackage.timestamp,
nonceStr: jsSdkUiPackage.nonceStr,
signature: jsSdkUiPackage.signature,
jsApiList: jsApiList
};
// ReSharper disable once UseOfImplicitGlobalInFunctionScope
wx.config(wxConfig);
// ReSharper disable once UseOfImplicitGlobalInFunctionScope
wx.error(function (res) {
//show_notice('微信配置有误' + JSON.stringify(res),3);
});
// ReSharper disable once UseOfImplicitGlobalInFunctionScope
wx.ready(function () {
// ReSharper disable once UseOfImplicitGlobalInFunctionScope
//分享到微信
console.log(self.wxFile);
console.log(self.wxFile.title);
wx.onMenuShareAppMessage({
title: self.wxFile.title,
desc: self.wxFile.desc,
link: self.wxFile.link,
imgUrl: self.wxFile.imgUrl,
trigger: function (res) {
},
success: function (res) {
//show_notice("分享成功",1);
},
cancel: function (res) {
},
fail: function (res) {
//show_notice("分享失败",1);
}
});
//分享到朋友圈
wx.onMenuShareTimeline({
title: self.wxFile.title,
desc: self.wxFile.desc,
link: self.wxFile.link,
imgUrl: self.wxFile.imgUrl,
trigger: function (res) {
},
success: function (res) {
console.log('分享成功');
//show_notice("分享成功",1);
},
cancel: function (res) {
},
fail: function (res) {
console.log('分享失败');
//show_notice("分享失败",1);
}
});
// ReSharper disable once UseOfImplicitGlobalInFunctionScope
//分享到QQ
wx.onMenuShareQQ({
title: self.wxFile.title,
desc: self.wxFile.desc,
link: self.wxFile.link,
imgUrl: self.wxFile.imgUrl,
trigger: function (res) {
},
complete: function (res) {
},
success: function (res) {
//show_notice("分享成功",1);
},
cancel: function (res) {
},
fail: function (res) {
//show_notice("分享失败",1);
}
});
// ReSharper disable once UseOfImplicitGlobalInFunctionScope
//分享到微博
wx.onMenuShareWeibo({
title: self.wxFile.title,
desc: self.wxFile.desc,
link: self.wxFile.link,
imgUrl: self.wxFile.imgUrl,
trigger: function (res) {
},
complete: function (res) {
},
success: function (res) {
//show_notice("分享成功",1);
},
cancel: function (res) {
},
fail: function (res) {
//show_notice("分享失败",1);
}
});
// ReSharper disable once UseOfImplicitGlobalInFunctionScope
//分享到QQ空间
wx.onMenuShareQZone({
title: self.wxFile.title,
desc: self.wxFile.desc,
link: self.wxFile.link,
imgUrl: self.wxFile.imgUrl,
trigger: function (res) {
},
complete: function (res) {
},
success: function (res) {
//show_notice("分享成功",1);
},
cancel: function (res) {
},
fail: function (res) {
//show_notice("分享失败",1);
}
});
});
},
},
computed: {
...mapGetters({
wxShare: 'getWx',
}),
},
watch:{
wxShare(res){
var self = this;
var jsSdkUiPackage = res.jsSdkUiPackage;
if (jsSdkUiPackage && jsSdkUiPackage.appId) {
self.initWx(jsSdkUiPackage);
}
},
detail(res){
var self = this;
//self.wxFile.title = res.title || res.name;
self.wxFile.desc = res.content;
self.wxFile.link = window.location.href.split('#')[0];
self.$set(self.wxFile,'title',res.title || res.name);
},
$route (to, from) {
if(to.path.includes('detail') || to.path.includes('mpDetail')){
var self = this;
self.$store.dispatch('actWx',{
url: window.location.href.split('#')[0],//notice:参与签名的url不能带#号后的部分
isNeedWechatJsInfo: true
});
}
}
},
components: {
}
}
</script>
<style lang="scss" scoped>
</style>