stat.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const sldStatCommonProperty = ''
  2. import { useFiltersStore } from '@/store/filter.js'
  3. import { post } from './request';
  4. /**
  5. * 初始化统计
  6. * @params showDebug Boolean 是否开启统计日志,默认false 不开启
  7. * @zjf-2021-06-27
  8. */
  9. export function initStat(showDebug = false, initStatCommonProperty) {
  10. //获取udid
  11. let uuid = ''
  12. uuid = getUUID();
  13. sldStatCommonProperty = {
  14. ...initStatCommonProperty,
  15. uuid: uuid,
  16. }
  17. console.log(sldStatCommonProperty)
  18. }
  19. /**
  20. * 设置/更新统计的公共属性
  21. * @params data Object 要更新的属性数据
  22. * @zjf-2021-06-27
  23. */
  24. let StatCommonProperty = {}
  25. export function updateStatCommonProperty(data) {
  26. let target = {};
  27. // const value = localStorage.getItem('sldStatCommonProperty');
  28. // if (value) {
  29. // target = JSON.parse(value);
  30. // }
  31. // target = {
  32. // ...target,
  33. // ...data
  34. // }; //更新或者新增统计的公共属性
  35. // localStorage.sldStatCommonProperty = JSON.stringify(target);
  36. console.log(data)
  37. StatCommonProperty = data
  38. return data;
  39. }
  40. /**
  41. * 同步获取指定key对应的内容
  42. * @params key 指定的缓存key
  43. * @zjf-2021-06-27
  44. */
  45. export function getStatStorage(key) {
  46. // let target = {};
  47. // const value = localStorage.getItem(key);
  48. // if (value) {
  49. // target = JSON.parse(value);
  50. // }
  51. // return target;
  52. }
  53. /**
  54. * 获取uuid
  55. * 如:1624819897644-1389918-0ed8161319cedb-22991203
  56. * Math.random().toString(16).replace('.', ''):0~1的随机数以十六进制显示,并去掉小数点,如:0.f03fb618bf531,并去掉小数点
  57. * @zjf-2021-06-27
  58. */
  59. export function getUUID() {
  60. return "" + Date.now() + '-' + Math.floor(1e7 * Math.random()) + '-' + Math.random().toString(16).replace('.', '') +
  61. '-' + String(Math.random() * 31242).replace('.', '').slice(0, 8);
  62. }
  63. /**
  64. * 统计事件
  65. * @params params Object 参数
  66. * @zjf-2021-06-27
  67. */
  68. export function sldStatEvent(data) {
  69. const filtersStore = useFiltersStore()
  70. let a = {
  71. equipmentType: 1,//设备类型,1-pc,2-移动设备,3-其他
  72. source: 'pc',//终端名称,pc-pc;h5-H5;android-Android;ios-IOS;xcx-微信小程序
  73. memberId: 0,//会员id默认为0
  74. ip: '',//移动端ip默认都为空
  75. cityCode: "",
  76. cityName: "",
  77. location: "",
  78. provinceCode: "",
  79. provinceName: "",
  80. }
  81. //获取udid
  82. let uuid = ''
  83. if(filtersStore.getUUid != ''){
  84. uuid = filtersStore.getUUid
  85. }else{
  86. uuid = getUUID();
  87. filtersStore.setUUid(uuid)
  88. }
  89. let targetParams = {
  90. ...a,
  91. uuid: uuid,
  92. ...data,
  93. ...StatCommonProperty
  94. };
  95. //发送请求
  96. post("v3/statistics/front/member/behavior/save", { u: base64Encode(JSON.stringify(targetParams)) }).then();
  97. }