cmSrsMixins.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // 统计Ross 用户
  2. import Vue from 'vue'
  3. import { includeList } from './router.config.js' // 配置信息
  4. // 参数
  5. const defaultParams = {
  6. accessClient: 1, // 来源 0 网站 1 小程序
  7. pagePath: '', //页面路径
  8. accessDuration: 0, //浏览时长初始值为 0
  9. pageType: '', //页面类型
  10. pageLabel: '', //页面标签
  11. userId: 0, //用户Id
  12. productId: 0, //商品Id
  13. shopId: 0, //供应商Id
  14. behaviorType: 1 // 统计类型
  15. }
  16. const cmSrsMixins = {
  17. data() {
  18. return {
  19. handleProsId: '',
  20. handleShopId: '',
  21. handleProsKey: '',
  22. handleShopKey: '',
  23. showRossHtml: false,
  24. isDisabled: true,
  25. advertisement:{},// 弹窗广告信息
  26. popUpParams: {
  27. shopId: '',
  28. productId: '',
  29. infoId: '',
  30. keyword: ''
  31. },
  32. }
  33. },
  34. methods: {
  35. checkedIsRossSet() {
  36. if (this.handleProsId || this.handleShopId || this.handleProsKey || this.handleShopKey) {
  37. this.popUpParams.shopId = this.handleShopId
  38. this.popUpParams.productId = this.handleProsId
  39. this.popUpParams.keyword = this.handleProsKey ? this.handleProsKey : '' || this.handleShopKey ? this.handleShopKey : ''
  40. uni.setStorageSync('behaviorType', 2)
  41. this.setingSysParams()
  42. if (!this.hasLogin) {
  43. this.userInformationIsClick()
  44. }
  45. } else {
  46. this.setingSysParams()
  47. }
  48. },
  49. // 接口参数设置
  50. async setingSysParams() {
  51. const sysParams = Object.assign({}, defaultParams)
  52. const userSync = uni.getStorageSync('userInfo')
  53. const route = this.getPath()
  54. const pageData = this.isIncludeType(route.path)
  55. // 协销不记录
  56. if (userSync.userIdentity === 1) return
  57. // 参数设置
  58. sysParams.userId = userSync.userId ? userSync.userId : 0
  59. sysParams.pagePath = route.fullPath
  60. sysParams.pageType = pageData ? pageData.pageType : ''
  61. sysParams.behaviorType = uni.getStorageSync('behaviorType') ? uni.getStorageSync('behaviorType') : 1
  62. // 根据path获取不同的参数
  63. if (route.path === '/pages/supplier/user/my-shop') {
  64. sysParams.shopId = route.query.shopId ? route.query.shopId : 0
  65. }
  66. if (route.path === '/pages/goods/product') {
  67. sysParams.productId = route.query.id ? route.query.id : 0
  68. sysParams.pageLabel = uni.getStorageSync('productLabel')
  69. } else {
  70. sysParams.pageLabel = uni.getStorageSync('pageLabel') ? uni.getStorageSync('pageLabel') :
  71. pageData.pageLabel
  72. }
  73. console.log('记录路径:', sysParams.pagePath, '标签:', sysParams.pageLabel)
  74. // 统计接口调用
  75. this.userRecordStatistics(sysParams)
  76. console.log('---用户行为轨迹记录成功---')
  77. },
  78. userRecordStatistics(params) {
  79. // 上送
  80. this.UserService.userRecordStatistics(params)
  81. .then(response => {
  82. console.log('---用户行为轨迹记录成功---')
  83. uni.removeStorageSync('pageLabel')
  84. uni.removeStorageSync('behaviorType')
  85. })
  86. .catch(error => {
  87. console.log('---用户行为轨迹记录失败---')
  88. })
  89. },
  90. async userInformationIsClick() {
  91. // 查看用户是否有过弹框游客当天是否有过弹框
  92. try {
  93. const res = await this.UserService.userInformationIsClick(this.popUpParams)
  94. if (res.data) {
  95. this.getUserPopUpInfo()
  96. setTimeout(() => {
  97. this.showRossHtml = true
  98. }, 5000)
  99. }
  100. } catch (error) {
  101. console.log('查询失败~')
  102. }
  103. },
  104. async getUserPopUpInfo() {
  105. // 获取供应商广告弹窗信息
  106. try {
  107. const res = await this.UserService.getUserPopUpInfo(this.popUpParams)
  108. const data = res.data
  109. this.advertisement = data
  110. this.consultParams.shopId = data.shopId
  111. } catch (error) {
  112. console.log('获取失败~')
  113. }
  114. },
  115. isIncludeType(url) {
  116. // 校验返回页面类型
  117. if (!url) return false
  118. return includeList.find(item => url === item.url)
  119. },
  120. getPath() {
  121. // 获取路径
  122. const pages = getCurrentPages()
  123. const len = pages.length
  124. const page = pages[len - 1]
  125. const route = { path: '/' + page.route, fullPath: page.$page.fullPath, query: page.options, meta: {} }
  126. return route
  127. }
  128. }
  129. }
  130. export default cmSrsMixins