鸿宇研学生前端代码
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.

75 lines
2.0 KiB

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