shareEntry.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // 分享
  2. import { mapMutations } from 'vuex'
  3. const shareEntry = {
  4. data() {
  5. return {
  6. shareData: {
  7. type: '',
  8. inviteUserId: '',
  9. activityId: '',
  10. productId: '',
  11. userId: '',
  12. keyWord: '',
  13. jumpState: ''
  14. }
  15. }
  16. },
  17. methods: {
  18. ...mapMutations('user', ['setInviteUserId']),
  19. // 处理分享参数
  20. shareHandle(option) {
  21. let state_str = option.state_str
  22. if (!state_str) return
  23. state_str = decodeURIComponent(state_str)
  24. try {
  25. const decrypt = this.$crypto.decrypt(state_str)
  26. // 解密参数
  27. this.shareData = {
  28. ...this.shareData,
  29. ...JSON.parse(decrypt)
  30. }
  31. // 保存分享者的用户id
  32. this.setInviteUserId(this.shareData.inviteUserId)
  33. this.jumpTopSharePage()
  34. } catch (e) {
  35. console.log(e)
  36. return
  37. }
  38. },
  39. // 跳转到对应的分享页面
  40. jumpTopSharePage() {
  41. if (!this.shareData.type || this.shareData.type === 0) return
  42. const path = {
  43. 0: '/pages/tabBar/index/index', //首页
  44. 1: `/pages/goods/product-detail?productId=${this.shareData.productId}&jumpState=${this.shareData.jumpState}`, //商品详情
  45. 2: `/pages/goods/search?type=share&keyWord=${this.shareData.keyWord}`, // 搜索页面
  46. 3: `/pages/user/activity/activity?type=share&activityId=${this.shareData.activityId}&userId=${this.shareData.userId}` //活动商品列表
  47. }
  48. // 1000 ms后跳转
  49. setTimeout(() => {
  50. this.$api.navigateTo(path[this.shareData.type])
  51. }, 1000)
  52. }
  53. }
  54. }
  55. export default shareEntry