ShareServer.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div></div>
  3. </template>
  4. <script>
  5. import wx from 'weixin-js-sdk'
  6. import * as API_WeiXin from '@/apis/weixin'
  7. export default {
  8. name: 'Share',
  9. props: {
  10. },
  11. data() {
  12. return {
  13. url:'',
  14. isLoading: false,
  15. nowItem: {
  16. shareTitle: '',
  17. shareImg: '',
  18. shareDescription: ''
  19. }
  20. }
  21. },
  22. created() {},
  23. methods: {
  24. //获取微信jssdk配置信息
  25. get_wx_config() {
  26. this.isLoading = true;
  27. API_WeiXin.getConfig(window.location.href.split("#")[0]).then(response => {
  28. this.isLoading = false;
  29. var wxconfig = response.wxConfig;
  30. console.log(wxconfig.nonceStr)
  31. this.wxConfig = wxconfig;
  32. wx.config({
  33. debug: false, // 开启调试模式,
  34. appId: wxconfig.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
  35. timestamp: wxconfig.timestamp, // 必填,生成签名的时间戳
  36. nonceStr: wxconfig.nonceStr, // 必填,生成签名的随机串
  37. signature: wxconfig.signature, // 必填,签名,见附录1
  38. jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  39. });
  40. //this.wxShare()
  41. }).catch(error => {
  42. this.isLoading = false;
  43. this.mui.toast(error);
  44. })
  45. },
  46. setUrl(url){
  47. this.url=window.location.href.split("#")[0]+"#"+url;
  48. },
  49. setTitle(text){
  50. this.title=text;
  51. this.wxShare()
  52. },
  53. //微信分享自定义
  54. wxShare() {
  55. var img=window.location.href.split("#")[0]+"/"+require("@/assets/img/logo_qilian.jpg")
  56. console.log(this.nowItem);
  57. var title="[荆州市企业联合会]"+this.title
  58. // var desc=
  59. let joinUrl = this.url;
  60. var _this = this;
  61. wx.ready(function() {
  62. wx.onMenuShareAppMessage({
  63. title: title,
  64. // desc:desc ,
  65. link: joinUrl,
  66. imgUrl: img,
  67. success: function() {
  68. // 设置成功
  69. _this.$emit("wxShare",null);
  70. }
  71. })
  72. wx.onMenuShareTimeline({
  73. title: title,
  74. //desc:desc ,
  75. link: joinUrl,
  76. imgUrl: img,
  77. success: function() {
  78. // 设置成功
  79. _this.$emit("wxShare",null);
  80. }
  81. })
  82. });
  83. }
  84. },
  85. mounted() {
  86. this.url=window.location.href;
  87. this.get_wx_config();
  88. },
  89. }
  90. </script>
  91. <style>
  92. </style>