cmSysMixins.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // 统计数据
  2. // 统计类型 1:首页banner;2:直播模块;3:最新活动;4:热门文章;5:新品橱窗;6:活动列表
  3. var cmSysVitaMixins = function () {
  4. return {
  5. data() {
  6. return {
  7. cmSysParams:{
  8. accessClient: 0,// 来源 0网站 1小程序
  9. pagePath:'',//页面路径
  10. accessDuration:0,//停留时间
  11. pageType:'',//页面类型
  12. pageLabel:'',//页面标签
  13. userId:0,//用户Id
  14. productId:0,//商品Id
  15. shopId:0,//供应商Id
  16. behaviorType:1, // 用户行为类型
  17. headUserId: '', // 内容库协销ID
  18. productArchiveId: '', // 内容库文件id
  19. },
  20. handleProsId:'',
  21. handleShopId:'',
  22. handlearticleId:'',
  23. handleProsKey:'',
  24. handleShopKey:'',
  25. consultParams:{
  26. ip:'',
  27. shopProductId:'',
  28. createTime:'',
  29. consultMobile: '',
  30. consultName: '',
  31. isClick:1
  32. },
  33. popUpParams:{
  34. shopId:'',
  35. productId:'',
  36. infoId:'',
  37. keyword:''
  38. },
  39. advertisement:{},// 弹窗广告信息
  40. showRossHtml:false,
  41. isDisabled:true,
  42. shopAdvert:[]
  43. }
  44. },
  45. methods: {
  46. // 校验返回页面类型
  47. checkedIsIncludeType(url){
  48. if (!url) return false
  49. return includeList.find(item => url === item.url)
  50. },
  51. // 校验是否为配置的路径
  52. checkedIsInclude(url) {
  53. if (!url) return false
  54. return includeList.some(item => url === item.url)
  55. },
  56. handleCmSysNetInfo() {
  57. //设置定时器
  58. const globalUserData = JSON.parse(localStorage.getItem('userInfo'));
  59. const databaseShareData = JSON.parse(sessionStorage.getItem('saveParams'))
  60. console.log('handleProsKey',this.handleProsKey)
  61. if(globalUserData){ this.cmSysParams.userId = globalUserData.userId * 1; }
  62. if( this.handleProsId || this.handleShopId || this.handlearticleId || this.handleProsKey || this.handleShopKey ){
  63. this.popUpParams.shopId = this.handleShopId
  64. this.popUpParams.productId = this.handleProsId
  65. this.popUpParams.infoId = this.handlearticleId
  66. this.popUpParams.keyword = this.handleProsKey ? this.handleProsKey : '' || this.handleShopKey ? this.handleShopKey : ''
  67. this.cmSysParams.behaviorType = 2;
  68. if (!GLOBAL_USER_ID>0) {
  69. this.userInformationIsClick()
  70. }
  71. }
  72. const pageUrls = window.location.pathname;
  73. const pagePath = window.location.href;
  74. if(this.checkedIsInclude(pageUrls)){
  75. const pageData = this.checkedIsIncludeType(pageUrls);
  76. this.cmSysParams.pageType = pageData ? pageData.pageType : '';
  77. this.cmSysParams.pageLabel = pageData ? pageData.pageLabel : '';
  78. }
  79. this.cmSysParams.pagePath = pagePath;
  80. this.cmSysParams.headUserId = databaseShareData?.suid || ''
  81. this.cmSysParams.productArchiveId = databaseShareData?.id || ''
  82. console.log(this.cmSysParams)
  83. setTimeout(()=>{
  84. this.handleSetNetworks(this.cmSysParams);
  85. },2000)
  86. },
  87. handleSetNetworks(params){// 进入页面执行统计
  88. console.log(`页面路径:${params.pagePath}`,`标签:${params.pageLabel}`)
  89. PublicApi.userRecordStatisticsApp(params,function(response){
  90. if(response.code === 0){
  91. console.log('上送浏览记录统计成功~')
  92. }else{
  93. console.log('上送浏览记录统计失败~')
  94. }
  95. });
  96. },
  97. handleInputName(e){
  98. this.consultParams.consultName = e.target.value;
  99. this.handldeCheckInput();
  100. },
  101. handleInputPhone(e){
  102. this.consultParams.consultMobile = e.target.value;
  103. this.handldeCheckInput();
  104. },
  105. handldeCheckInput(){
  106. this.isDisabled = !(this.consultParams.consultName !== "" && this.consultParams.consultMobile !== "");
  107. },
  108. handleSubmit(){
  109. // 提交联系人信息
  110. if(this.isDisabled){ return }
  111. let reg = RegExp(/^1\d{10}$/);
  112. if(!reg.test(this.consultParams.consultMobile)){
  113. CAIMEI.dialog('请输入正确的手机号');
  114. return
  115. }
  116. this.userInformationInsertRoos(this.consultParams);
  117. },
  118. handleClose(){
  119. // 关闭Ross 广告弹窗
  120. this.userInformationInsertRoos(this.consultParams);
  121. },
  122. getUserPopUpInfo(params){
  123. //查看供应商广告弹框信息
  124. let _self = this;
  125. PublicApi.getUserPopUpInfo(params, function (response) {
  126. if(response.code === 0){
  127. _self.advertisement = response.data
  128. _self.consultParams.shopProductId = response.data.shopProductId
  129. }else{
  130. console.log('error',response.msg);
  131. }
  132. })
  133. },
  134. userInformationIsClick(){
  135. //查询是否需要弹广告
  136. let _self = this;
  137. PublicApi.userInformationIsClick(_self.popUpParams, function (response) {
  138. if(response.code === 0){
  139. if(response.data){
  140. setTimeout(()=>{
  141. _self.showRossHtml = true
  142. _self.getUserPopUpInfo(_self.popUpParams)
  143. },5000)
  144. }
  145. }else{
  146. console.log('error',response.msg);
  147. }
  148. })
  149. },
  150. userInformationInsertRoos(params){
  151. //提交记录咨询人&&关闭弹窗
  152. let _self = this;
  153. PublicApi.userInformationInsertRoos(params, function (response) {
  154. if(response.code === 0){
  155. _self.showRossHtml = false
  156. }else{
  157. console.log('error',response.msg);
  158. }
  159. })
  160. },
  161. getShopAdvert(params){
  162. //查看访问者是否浏览过roos相关页面
  163. let _self = this;
  164. PublicApi.getShopAdvert(params, function (response) {
  165. if(response.code === 0){
  166. _self.shopAdvert = response.data
  167. console.log('shopAdvert',_self.shopAdvert);
  168. }else{
  169. console.log('error',response.msg);
  170. }
  171. })
  172. },
  173. userRecordStatistics() {// navigator.sendBeacon 方式 暂时废弃
  174. const NODE_ENV_BASE_URL = $("#coreServer").val();
  175. const url = `${NODE_ENV_BASE_URL}/user/record/StatisticsPc`;
  176. const blob = new Blob([JSON.stringify(this.cmSysParams)], {
  177. type: 'application/json; charset=UTF-8',
  178. });
  179. navigator.sendBeacon(url, blob);
  180. },
  181. handleWindow(type){ // 暂时废弃
  182. const isBrowser = isPC ? 1 : 0;
  183. const map = {
  184. 0: 'pagehide',
  185. 1: 'beforeunload',
  186. };
  187. const FunMap = {
  188. 0:window.addEventListener(map[isBrowser], e => this.beforeunloadHandler(e)), // 绑定
  189. 1:window.removeEventListener(map[isBrowser], e => this.beforeunloadHandler(e)) // 接触绑定
  190. }
  191. return FunMap[type];
  192. },
  193. },
  194. mounted() {
  195. // 页面加载完成后[监听]执行事件
  196. this.handleCmSysNetInfo()
  197. // 查看访问者是否浏览过roos相关页面
  198. this.getShopAdvert({ userId: this.cmSysParams.userId })
  199. },
  200. destroyed() {
  201. }
  202. }
  203. }();