ShareServer.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view></view>
  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. id:'',
  14. title:'',
  15. url:'',
  16. isLoading: false,
  17. nowItem: {
  18. shareTitle: '',
  19. shareImg: '',
  20. shareDescription: ''
  21. }
  22. }
  23. },
  24. created() {},
  25. methods: {
  26. addPoint(){
  27. API_WeiXin.addPoint({
  28. id:this.id,
  29. pointCode:"70007"
  30. }).then(response => {
  31. })
  32. },
  33. //获取微信jssdk配置信息
  34. get_wx_config() {
  35. API_WeiXin.getConfig(window.location.href.split("#")[0]).then(response => {
  36. var wxconfig = response.data.wxConfig;
  37. console.log(wxconfig.nonceStr)
  38. //this.wxConfig = wxconfig;
  39. wx.config({
  40. debug: false, // 开启调试模式,
  41. appId: wxconfig.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
  42. timestamp: wxconfig.timestamp, // 必填,生成签名的时间戳
  43. nonceStr: wxconfig.nonceStr, // 必填,生成签名的随机串
  44. signature: wxconfig.signature, // 必填,签名,见附录1
  45. jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage',
  46. 'onMenuShareQQ', 'onMenuShareQZone'] ,// 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  47. //'checkJsApi',,'updateAppMessageShareData','updateTimelineShareData'
  48. });
  49. console.log("aaa")
  50. //this.wxShare()
  51. }).catch(error => {
  52. console.log(error)
  53. console.log("errorerror")
  54. })
  55. },
  56. setUrl(url){
  57. this.url=process.car.IMG_URL+"railroad-phone/#"+url;
  58. },
  59. setTitle(text,id){
  60. this.title=text;
  61. this.id=id;
  62. this.wxShare()
  63. },
  64. //微信分享自定义
  65. wxShare() {
  66. var userInfo=this.carhelp.getPersonInfo()
  67. var img=process.car.IMG_URL+"railroad-phone/"+require("@/assets/img/logo.png")
  68. var title="[微官网]"+this.title
  69. // var desc=
  70. let joinUrl = this.url;
  71. console.log(img);
  72. console.log(title);
  73. console.log(joinUrl);
  74. var _this = this;
  75. wx.ready(function() {
  76. // wx.updateTimelineShareData({
  77. // title: title,
  78. // // desc:desc ,
  79. // link: joinUrl,
  80. // imgUrl: img,
  81. // success: function() {
  82. // if(userInfo){
  83. // //_this.addPoint()
  84. // }
  85. // // 设置成功
  86. // _this.$emit("wxShare",null);
  87. // }
  88. // })
  89. // wx.updateAppMessageShareData({
  90. // title: title,
  91. // // desc:desc ,
  92. // link: joinUrl,
  93. // imgUrl: img,
  94. // success: function() {
  95. // if(userInfo){
  96. // //_this.addPoint()
  97. // }
  98. // // 设置成功
  99. // _this.$emit("wxShare",null);
  100. // }
  101. // })
  102. wx.onMenuShareAppMessage({
  103. title: title,
  104. // desc:desc ,
  105. link: joinUrl,
  106. imgUrl: img,
  107. success: function() {
  108. console.log('111')
  109. if(userInfo){
  110. _this.addPoint()
  111. }
  112. // 设置成功
  113. _this.$emit("wxShare",null);
  114. }
  115. })
  116. wx.onMenuShareTimeline({
  117. title: title,
  118. //desc:desc ,
  119. link: joinUrl,
  120. imgUrl: img,
  121. success: function() {
  122. console.log('222')
  123. if(userInfo){
  124. _this.addPoint()
  125. }
  126. // 设置成功
  127. _this.$emit("wxShare",null);
  128. }
  129. })
  130. });
  131. }
  132. },
  133. mounted() {
  134. this.url=window.location.href;
  135. this.get_wx_config();
  136. },
  137. }
  138. </script>
  139. <style>
  140. </style>