特易招,招聘小程序
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.

74 lines
1.9 KiB

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