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

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