shareEntry.js 2.0 KB

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