ShareServer.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. 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. this.isLoading = true;
  36. API_WeiXin.getConfig(window.location.href.split("#")[0]).then(response => {
  37. this.isLoading = false;
  38. var wxconfig = response.wxConfig;
  39. console.log(wxconfig.nonceStr)
  40. this.wxConfig = wxconfig;
  41. wx.config({
  42. debug: true, // 开启调试模式,
  43. appId: wxconfig.appId, // 必填,企业号的唯一标识,此处填写企业号corpid
  44. timestamp: wxconfig.timestamp, // 必填,生成签名的时间戳
  45. nonceStr: wxconfig.nonceStr, // 必填,生成签名的随机串
  46. signature: wxconfig.signature, // 必填,签名,见附录1
  47. jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage',
  48. 'onMenuShareQQ', 'onMenuShareQZone','updateAppMessageShareData','updateTimelineShareData'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  49. });
  50. wx.error(function(res){
  51. console.log(res)
  52. console.log("error")
  53. // config信息验证失败会执行 error 函数,如签名过期导致验证失败,具体错误信息可以打开 config 的debug模式查看,也可以在返回的 res 参数中查看,对于 SPA 可以在这里更新签名。
  54. });
  55. //this.wxShare()
  56. }).catch(error => {
  57. this.isLoading = false;
  58. })
  59. },
  60. setUrl(url){
  61. this.url=process.car.IMG_URL+"railroad-phone/#"+url;
  62. },
  63. setTitle(text,id){
  64. this.title=text;
  65. this.id=id;
  66. this.wxShare()
  67. },
  68. //微信分享自定义
  69. wxShare() {
  70. var userInfo=this.carhelp.getPersonInfo()
  71. //var img=require("@/assets/img/logo.png")
  72. var img=""
  73. var title="[微官网]"+this.title
  74. // var desc=
  75. let joinUrl = this.url;
  76. console.log(img);
  77. console.log(title);
  78. console.log(joinUrl);
  79. var _this = this;
  80. wx.ready(function() {
  81. wx.checkJsApi({
  82. jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage',
  83. 'onMenuShareQQ', 'onMenuShareQZone','updateAppMessageShareData','updateTimelineShareData'], // 需要检测的 JS 接口列表,所有 JS 接口列表见附录2,
  84. success: function(res) {
  85. console.log(res)
  86. console.log("1111")
  87. }
  88. });
  89. wx.updateTimelineShareData({
  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.updateAppMessageShareData({
  103. title: title,
  104. // desc:desc ,
  105. link: joinUrl,
  106. imgUrl: img,
  107. success: function() {
  108. if(userInfo){
  109. //_this.addPoint()
  110. }
  111. // 设置成功
  112. _this.$emit("wxShare",null);
  113. }
  114. })
  115. wx.onMenuShareAppMessage({
  116. title: title,
  117. // desc:desc ,
  118. link: joinUrl,
  119. imgUrl: img,
  120. success: function() {
  121. if(userInfo){
  122. //_this.addPoint()
  123. }
  124. // 设置成功
  125. _this.$emit("wxShare",null);
  126. }
  127. })
  128. wx.onMenuShareTimeline({
  129. title: title,
  130. //desc:desc ,
  131. link: joinUrl,
  132. imgUrl: img,
  133. success: function() {
  134. // 设置成功
  135. _this.$emit("wxShare",null);
  136. }
  137. })
  138. });
  139. }
  140. },
  141. mounted() {
  142. this.url=window.location.href;
  143. this.get_wx_config();
  144. },
  145. }
  146. </script>
  147. <style>
  148. </style>