推拿小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.1 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. import api from '@/api/api.js'
  2. import config from "../config.js"
  3. import jWeixin from './lib/jweixin-module.js'
  4. import Vue from 'vue'
  5. function share() { //微信分享
  6. //获取签名
  7. let data = {
  8. // location.href.split('#')[0])
  9. // url: Vue.prototype.$config.redirect + '/#/'
  10. url: location.href.split('#')[0]
  11. }
  12. api('getVipShareSign', data, res => {
  13. if (res.code == 200) {
  14. let {
  15. appId,
  16. nonceStr,
  17. signature,
  18. timestamp
  19. } = res.result
  20. jWeixin.config({
  21. debug: false,
  22. appId: appId,
  23. nonceStr: nonceStr,
  24. signature: signature,
  25. timestamp: timestamp,
  26. jsApiList: [
  27. 'updateTimelineShareData',
  28. 'updateAppMessageShareData',
  29. 'onMenuShareWeibo',
  30. 'getLocation',
  31. 'chooseWXPay',
  32. 'requestMerchantTransfer',
  33. 'checkJsApi',
  34. 'scanQRCode',
  35. ]
  36. });
  37. jWeixin.ready(function() {
  38. // 微信分享的数据
  39. var shareData = {
  40. "link": addQueryParams(data.url),
  41. "desc": "愈然工坊",
  42. "title": "愈然工坊,温柔呵护每一刻!",
  43. imgUrl : Vue.prototype.$config.redirect + '/static/share/logo.png',
  44. success: function() {
  45. //分享成功可以做相应的数据处理
  46. // uni.showToast({
  47. // mask: true,
  48. // duration: 1000,
  49. // title: '注册分享成功',
  50. // });
  51. }
  52. };
  53. //分享微信朋友圈内容设置
  54. jWeixin.updateTimelineShareData(shareData);
  55. //分享给朋友内容设置
  56. jWeixin.updateAppMessageShareData(shareData);
  57. //分享到微博内容设置
  58. jWeixin.onMenuShareWeibo(shareData);
  59. });
  60. jWeixin.error(function(err){
  61. console.error(err);
  62. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  63. })
  64. }
  65. })
  66. }
  67. function addQueryParams(url) {
  68. if (url) {
  69. //获取用户id
  70. let userInfo = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : null
  71. if(userInfo){
  72. url += `?vid=${userInfo.id}`
  73. }
  74. }
  75. return url
  76. }
  77. export default share