cmSrsMixins.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // 统计Ross 用户
  2. import Vue from 'vue'
  3. import { includeList , roosConfig } 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: 0,
  20. handleShopId: 0,
  21. handleProsKey: '',
  22. handleShopKey: '',
  23. showRossHtml: false,
  24. isDisabled: true
  25. }
  26. },
  27. methods: {
  28. checkedIsRossSet() {
  29. if (roosConfig.productIdList.includes(this.handleProsId * 1) ||
  30. roosConfig.shopIds.includes(this.handleShopId * 1) ||
  31. roosConfig.keyWords.includes(this.handleProsKey) ||
  32. roosConfig.shopKeyWords.includes(this.handleShopKey)
  33. ) {
  34. uni.setStorageSync('behaviorType', 2)
  35. this.setingSysParams()
  36. if (!this.hasLogin) {
  37. this.userInformationIsClick()
  38. }
  39. }else{
  40. this.setingSysParams()
  41. }
  42. },
  43. // 接口参数设置
  44. async setingSysParams(){
  45. const sysParams = Object.assign({}, defaultParams)
  46. const userSync = uni.getStorageSync('userInfo')
  47. const route = this.getPath()
  48. const pageData = this.isIncludeType(route.path)
  49. // 协销不记录
  50. if (userSync.userIdentity === 1) return
  51. // 参数设置
  52. sysParams.userId = userSync.userId ? userSync.userId : 0
  53. sysParams.pagePath = route.fullPath
  54. sysParams.pageType = pageData ? pageData.pageType : ''
  55. sysParams.behaviorType = uni.getStorageSync('behaviorType') ? uni.getStorageSync('behaviorType') : 1
  56. // 根据path获取不同的参数
  57. if (route.path === '/pages/supplier/user/my-shop') {
  58. sysParams.shopId = route.query.shopId ? route.query.shopId : 0
  59. }
  60. if (route.path === '/pages/goods/product') {
  61. sysParams.productId = route.query.id ? route.query.id : 0
  62. sysParams.pageLabel = uni.getStorageSync('productLabel')
  63. } else {
  64. sysParams.pageLabel = uni.getStorageSync('pageLabel') ? uni.getStorageSync('pageLabel') : pageData.pageLabel
  65. }
  66. console.log('记录路径:', sysParams.pagePath, '标签:', sysParams.pageLabel)
  67. // 统计接口调用
  68. this.userRecordStatistics(sysParams)
  69. console.log('---用户行为轨迹记录成功---')
  70. },
  71. userRecordStatistics(params){
  72. // 上送
  73. this.UserService.userRecordStatistics(params)
  74. .then(response => {
  75. console.log('---用户行为轨迹记录成功---')
  76. uni.removeStorageSync('pageLabel')
  77. uni.removeStorageSync('behaviorType')
  78. })
  79. .catch(error => {
  80. console.log('---用户行为轨迹记录失败---')
  81. })
  82. },
  83. userInformationIsClick() {
  84. // 查看用户是否有过弹框游客当天是否有过弹框
  85. this.UserService.userInformationIsClick()
  86. .then(response => {
  87. if (response.data) {
  88. setTimeout(() => {
  89. this.showRossHtml = true
  90. }, 5000)
  91. }
  92. })
  93. .catch(error => {
  94. console.log('查询失败~')
  95. })
  96. },
  97. isIncludeType(url){
  98. // 校验返回页面类型
  99. if (!url) return false
  100. return includeList.find(item => url === item.url)
  101. },
  102. getPath(){
  103. // 获取路径
  104. const pages = getCurrentPages()
  105. const len = pages.length
  106. const page = pages[len - 1]
  107. const route = { path: '/' + page.route, fullPath: page.$page.fullPath, query: page.options, meta: {} }
  108. return route
  109. }
  110. }
  111. }
  112. export default cmSrsMixins