推拿小程序前端代码仓库
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.

79 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. ]
  34. });
  35. jWeixin.ready(function() {
  36. // 微信分享的数据
  37. var shareData = {
  38. "link": addQueryParams(data.url),
  39. "desc": "愈然工坊",
  40. "title": "愈然工坊,温柔呵护每一刻!",
  41. imgUrl : Vue.prototype.$config.redirect + '/static/share/logo.png',
  42. success: function() {
  43. //分享成功可以做相应的数据处理
  44. // uni.showToast({
  45. // mask: true,
  46. // duration: 1000,
  47. // title: '注册分享成功',
  48. // });
  49. }
  50. };
  51. //分享微信朋友圈内容设置
  52. jWeixin.updateTimelineShareData(shareData);
  53. //分享给朋友内容设置
  54. jWeixin.updateAppMessageShareData(shareData);
  55. //分享到微博内容设置
  56. jWeixin.onMenuShareWeibo(shareData);
  57. });
  58. jWeixin.error(function(err){
  59. console.error(err);
  60. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  61. })
  62. }
  63. })
  64. }
  65. function addQueryParams(url) {
  66. if (url) {
  67. //获取用户id
  68. let userInfo = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : null
  69. if(userInfo){
  70. url += `?vid=${userInfo.id}`
  71. }
  72. }
  73. return url
  74. }
  75. export default share