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.0 KiB

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