share-entry.js 2.5 KB

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