cmSrsMixins.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.openId = userSync.openId ? userSync.openId : ''
  60. sysParams.pagePath = route.fullPath
  61. sysParams.pageType = pageData ? pageData.pageType : ''
  62. sysParams.behaviorType = uni.getStorageSync('behaviorType') ? uni.getStorageSync('behaviorType') : 1
  63. // 根据path获取不同的参数
  64. if (route.path === '/pages/supplier/user/my-shop') {
  65. sysParams.shopId = route.query.shopId ? route.query.shopId : 0
  66. }
  67. if (route.path === '/pages/goods/product') {
  68. sysParams.productId = route.query.id ? route.query.id : 0
  69. sysParams.pageLabel = uni.getStorageSync('productLabel')
  70. } else {
  71. sysParams.pageLabel = uni.getStorageSync('pageLabel') ? uni.getStorageSync('pageLabel') :
  72. pageData.pageLabel
  73. }
  74. console.log('记录路径:', sysParams.pagePath, '标签:', sysParams.pageLabel)
  75. // 统计接口调用
  76. this.userRecordStatistics(sysParams)
  77. console.log('---用户行为轨迹记录成功---')
  78. },
  79. userRecordStatistics(params) {
  80. // 上送
  81. this.UserService.userRecordStatistics(params)
  82. .then(response => {
  83. console.log('---用户行为轨迹记录成功---')
  84. uni.removeStorageSync('pageLabel')
  85. uni.removeStorageSync('behaviorType')
  86. })
  87. .catch(error => {
  88. console.log('---用户行为轨迹记录失败---')
  89. })
  90. },
  91. async userInformationIsClick() {
  92. // 查看用户是否有过弹框游客当天是否有过弹框
  93. try {
  94. const res = await this.UserService.userInformationIsClick(this.popUpParams)
  95. if (res.data) {
  96. this.getUserPopUpInfo()
  97. setTimeout(() => {
  98. this.showRossHtml = true
  99. }, 5000)
  100. }
  101. } catch (error) {
  102. console.log('查询失败~')
  103. }
  104. },
  105. async getUserPopUpInfo() {
  106. // 获取供应商广告弹窗信息
  107. try {
  108. const res = await this.UserService.getUserPopUpInfo(this.popUpParams)
  109. const data = res.data
  110. this.advertisement = data
  111. this.consultParams.shopId = data.shopId
  112. } catch (error) {
  113. console.log('获取失败~')
  114. }
  115. },
  116. isIncludeType(url) {
  117. // 校验返回页面类型
  118. if (!url) return false
  119. return includeList.find(item => url === item.url)
  120. },
  121. getPath() {
  122. // 获取路径
  123. const pages = getCurrentPages()
  124. const len = pages.length
  125. const page = pages[len - 1]
  126. const route = { path: '/' + page.route, fullPath: page.$page.fullPath, query: page.options, meta: {} }
  127. return route
  128. }
  129. }
  130. }
  131. export default cmSrsMixins