ShareServer.vue 3.7 KB

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