cmSrsMixins.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // 统计Ross 用户
  2. import Vue from 'vue'
  3. import { includeList } from '@/utils/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. behaviorType: 1 // 统计类型
  14. }
  15. const cmSrsMixins = {
  16. data() {
  17. return {
  18. handleProsId: 0,
  19. handleShopId: 0,
  20. handleProsKey: '',
  21. handleShopKey: '',
  22. productIdList: [7247, 7248], //Ross 商品ID集合
  23. shopIds: [1378], // Ross 供应商Id
  24. keyWords: ['Binary Premium', '智能体疗管理系统', '448k', '肌肉重塑疗法', '西班牙ROSS', 'ROSS', '智能体疗', '西班牙Ross', 'Ross',
  25. '西班牙ross', 'ross',
  26. ], // Ross 搜索商品关键词 集合
  27. shopKeyWords: ['深圳艾斯佰丽生物科技有限公司', '艾斯佰丽'],
  28. showRossHtml: false,
  29. isDisabled: true
  30. }
  31. },
  32. methods: {
  33. checkedIsRossSet() {
  34. if (this.productIdList.includes(this.handleProsId * 1) ||
  35. this.shopIds.includes(this.handleShopId * 1) ||
  36. this.keyWords.includes(this.handleProsKey) ||
  37. this.shopKeyWords.includes(this.handleShopKey)
  38. ) {
  39. uni.setStorageSync('behaviorType', 2)
  40. this.setingSysParams()
  41. if (!this.hasLogin) {
  42. this.userInformationIsClick()
  43. }
  44. }else{
  45. this.setingSysParams()
  46. }
  47. },
  48. // 接口参数设置
  49. async setingSysParams(){
  50. const sysParams = Object.assign({}, defaultParams)
  51. const userSync = uni.getStorageSync('userInfo')
  52. const pagePath = this.getPath()
  53. const pageData = this.isIncludeType(pagePath)
  54. // 协销不记录
  55. if (userSync.userIdentity === 1) return
  56. // 参数设置
  57. sysParams.userId = userSync.userId ? userSync.userId : 0
  58. sysParams.pagePath = pagePath
  59. sysParams.pageType = pageData ? pageData.pageType : ''
  60. sysParams.behaviorType = uni.getStorageSync('behaviorType') ? uni.getStorageSync('behaviorType') : 1
  61. // 根据path获取不同的参数
  62. sysParams.pageLabel = uni.getStorageSync('pageLabel') ? uni.getStorageSync('pageLabel') : pageData.pageLabel
  63. console.log('记录路径:', sysParams.pagePath, '标签:', sysParams.pageLabel)
  64. // 统计接口调用
  65. this.userRecordStatistics(sysParams)
  66. console.log('---用户行为轨迹记录成功---')
  67. },
  68. userRecordStatistics(params){
  69. // 上送
  70. this.UserService.userRecordStatistics(params)
  71. .then(response => {
  72. console.log('---用户行为轨迹记录成功---')
  73. uni.removeStorageSync('pageLabel')
  74. uni.removeStorageSync('behaviorType')
  75. })
  76. .catch(error => {
  77. console.log('---用户行为轨迹记录失败---')
  78. })
  79. },
  80. userInformationIsClick() {
  81. // 查看用户是否有过弹框游客当天是否有过弹框
  82. this.UserService.userInformationIsClick()
  83. .then(response => {
  84. if (response.data) {
  85. setTimeout(() => {
  86. this.showRossHtml = true
  87. }, 5000)
  88. }
  89. })
  90. .catch(error => {
  91. console.log('查询失败~')
  92. })
  93. },
  94. isIncludeType(url){
  95. // 校验返回页面类型
  96. if (!url) return false
  97. return includeList.find(item => url === item.url)
  98. },
  99. getPath(){
  100. // 获取路径
  101. const pages = getCurrentPages()
  102. const len = pages.length
  103. const page = pages[len - 1]
  104. return '/' + page.$page.fullPath
  105. }
  106. }
  107. }
  108. export default cmSrsMixins