share-entry.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const shareEntry = {
  2. data() {
  3. return {
  4. // 分享链接携带的数据
  5. shareData: {
  6. type: '',
  7. inviteUserId: '', // 邀请者用户ID
  8. activityId: '', // 分享者活动ID
  9. dealerUserId: '', // 协销用户ID
  10. keyWord: '', // 搜索关键词
  11. productId: '', // 产品ID
  12. jumpState: '' // 跳转类型 普通用户 协销
  13. }
  14. }
  15. },
  16. methods: {
  17. // 处理分享参数
  18. shareHandle(state_str) {
  19. if (!state_str) return
  20. state_str = decodeURIComponent(state_str)
  21. try {
  22. const decrypt = this.$crypto.decrypt(state_str)
  23. // 解密参数
  24. this.shareData = {
  25. ...this.shareData,
  26. ...JSON.parse(decrypt)
  27. }
  28. // 保存分享者的用户id
  29. if (this.shareData.inviteUserId) {
  30. this.$store.commit('SET_INVITE_USER_ID', this.shareData.inviteUserId)
  31. }
  32. this.shareData.type = parseInt(this.shareData.type)
  33. this.jumpTopSharePage()
  34. } catch (e) {
  35. return
  36. }
  37. },
  38. // 跳转到对应的分享页面
  39. jumpTopSharePage() {
  40. const { type = 0, collageId, jumpState, productId, dealerUserId, keyWord } = this.shareData
  41. const path = {
  42. 0: 'home', //首页
  43. 1: `goods/goods-detail?jumpState=${jumpState}&productId=${productId}`, //商品详情
  44. 2: `goods/goods-search?keyWord=${keyWord}`, // 搜索页面
  45. 3: `activity/activity-detail?dealerUserId=${dealerUserId}`, //活动商品列表
  46. 4: `share-buy/share-buy-entry?collageId=${collageId}` // 拼团分享
  47. }
  48. if (type === 0) {
  49. this.$router.switchTab(path[type])
  50. } else {
  51. this.$router.redirectTo(path[type])
  52. }
  53. }
  54. }
  55. }
  56. export default shareEntry