share.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. export default {
  2. data() {
  3. return {
  4. //设置默认的分享参数
  5. //如果页面不设置share,就触发这个默认的分享
  6. share: {
  7. title: '',
  8. path: '',
  9. imageUrl: '',
  10. desc: '',
  11. content: ''
  12. }
  13. }
  14. },
  15. onShareAppMessage(res) {
  16. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  17. let path = routes[routes.length - 1].route //获取当前页面路由
  18. let share_user_id
  19. try {
  20. share_user_id = this.$store.state.userInfo.id
  21. } catch (err) {
  22. console.log(err)
  23. }
  24. if (share_user_id) {
  25. path += `?share_user_id=${share_user_id}`
  26. }
  27. // console.log(path)
  28. return {
  29. title: this.share.title,
  30. path: this.share.path || path,
  31. imageUrl: this.share.imageUrl,
  32. desc: this.share.desc,
  33. content: this.share.content,
  34. success(res) {
  35. uni.showToast({
  36. title: '分享成功'
  37. })
  38. },
  39. fail(res) {
  40. uni.showToast({
  41. title: '分享失败',
  42. icon: 'none'
  43. })
  44. }
  45. }
  46. }
  47. }