// 统计数据 // 统计类型 1:首页banner;2:直播模块;3:最新活动;4:热门文章;5:新品橱窗;6:活动列表 var cmSysVitaMixins = function () { return { data() { return { browseTime: 0, // 浏览时长初始值为 0 clearTimeSet: null, cmSysParams:{ pagePath:'',//页面路径 accessDuration:0,//停留时间 pageType:'',//页面类型 pageLabel:'',//页面标签 userId:0,//用户Id productId:0//商品Id } } }, methods: { setTime() { //设置定时器 let _self = this; if(GLOBAL_TOKEN){ this.cmSysParams.userId = GLOBAL_USER_ID; } this.cmSysParams.pagePath = window.location.href; this.clearTimeSet = setInterval(() => { _self.cmSysParams.accessDuration++; console.log(`页面路径:${_self.cmSysParams.pagePath}`,`停留:${_self.cmSysParams.accessDuration}s`,`标签:${_self.cmSysParams.pageLabel}`) }, 1000); }, userRecordStatistics(params) { var _this = this; PublicApi.userRecordStatistics(params,function (response) { if(response.code === 0){ alert('111111111111111') console.log('<-------上送用户行为记录成功------>') }else{ console.log('<-------上送用户行为记录异常------>') } }) }, beforeunloadHandler(e) { debugger this.userRecordStatistics(this.cmSysParams); // 上送后台接口,将浏览时长等信息传到后台,离开当前路由后调用 console.log('关闭窗口之后',this.cmSysParams) clearInterval(this.clearTimeSet); // 离开页面后清除定时器 } }, mounted() { // 页面加载完成后开始计时 this.setTime(); // 绑定窗口关闭[监听]事件 window.addEventListener('beforeunload', e => this.beforeunloadHandler(e)) }, destroyed() { // 解除窗口关闭[监听]事件 window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e)) } } }();