share-entry.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }
  16. }
  17. },
  18. methods: {
  19. // 处理分享参数
  20. shareHandle(query, type) {
  21. if (!query) return;
  22. console.log(query)
  23. // 小程序分享
  24. if (type === 'state_str') {
  25. this.shareData = {
  26. ...this.shareData,
  27. ...JSON.parse(this.$crypto.decrypt(decodeURIComponent(query)))
  28. }
  29. } else if (type === 'scene') {
  30. this.shareData = {
  31. ...this.shareData,
  32. ...queryParse(enCodeQueryStr(decodeURIComponent(query)))
  33. }
  34. } else {
  35. return this.$router.switchTab('home')
  36. }
  37. // 保存分享者的用户id
  38. if (this.shareData.inviteUserId) {
  39. this.$store.commit('user/SET_INVITE_USER_ID', this.shareData.inviteUserId)
  40. }
  41. console.log(this.shareData);
  42. this.shareData.type = parseInt(this.shareData.type)
  43. this.jumpTopSharePage()
  44. },
  45. // 跳转到对应的分享页面
  46. jumpTopSharePage() {
  47. const { type = 0, collageId, jumpState, productId, activityId, dealerUserId, keyWord } = this.shareData
  48. const path = {
  49. 0: 'home', //首页
  50. 1: `goods/goods-detail?type=share&jumpState=${jumpState}&productId=${productId}`, //商品详情
  51. // 2: `goods/goods-search?keyWord=${keyWord}`, // 搜索页面
  52. 3: `activity/activity-detail?type=share&activityId=${activityId}&dealerUserId=${dealerUserId}`, //活动商品列表
  53. 4: `share-buy/share-buy-entry?type=share&collageId=${collageId}` // 拼团分享
  54. }
  55. if (type === 0) {
  56. this.$router.switchTab(path[type])
  57. } else {
  58. this.$router.redirectTo(path[type])
  59. }
  60. }
  61. }
  62. }
  63. export default shareEntry