shareEntry.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. const state_str = decodeURIComponent(option.state_str)
  22. if (!state_str) return
  23. // 解密参数
  24. this.shareData = {
  25. ...this.shareData,
  26. ...JSON.parse(this.$crypto.decrypt(state_str))
  27. }
  28. // 保存分享者的用户id
  29. this.setInviteUserId(this.shareData.inviteUserId)
  30. this.jumpTopSharePage()
  31. },
  32. // 跳转到对应的分享页面
  33. jumpTopSharePage() {
  34. if (!this.shareData.type || this.shareData.type === 0) return
  35. const path = {
  36. 0: '/pages/tabBar/index/index', //首页
  37. 1: `/pages/goods/product-detail?productId=${this.shareData.productId}&jumpState=${this.shareData.jumpState}`, //商品详情
  38. 2: `/pages/goods/search?type=share&keyWord=${this.shareData.keyWord}`, // 搜索页面
  39. 3: `/pages/user/activity/activity?type=share&activityId=${this.shareData.activityId}&userId=${this.shareData.userId}` //活动商品列表
  40. }
  41. // 200 ms后跳转
  42. setTimeout(() => {
  43. this.$api.navigateTo(path[this.shareData.type])
  44. }, 200)
  45. }
  46. }
  47. }
  48. export default shareEntry