فهرست منبع

行为轨迹统计

zhengjinyi 2 سال پیش
والد
کامیت
e5bfdb2c9d
1فایلهای تغییر یافته به همراه17 افزوده شده و 4 حذف شده
  1. 17 4
      src/main/resources/static/js/mixins/cmSysMixins.js

+ 17 - 4
src/main/resources/static/js/mixins/cmSysMixins.js

@@ -41,16 +41,29 @@ var cmSysVitaMixins = function () {
                 var url = `${NODE_ENV_BASE_URL}/user/record/StatisticsPc`
                 this.userRecordStatistics(url,this.cmSysParams); // 上送后台接口,将浏览时长等信息传到后台,离开当前路由后调用
                 clearInterval(this.clearTimeSet); // 离开页面后清除定时器
+            },
+            handleWindow(type){
+                const isBrowser = isPC ? 1 : 0;
+                const map = {
+                    0: 'pagehide',
+                    1: 'beforeunload',
+                };
+                const FunMap = {
+                    0:window.addEventListener(map[isBrowser], e => this.beforeunloadHandler(e)), // 绑定
+                    1:window.removeEventListener(map[isBrowser], e => this.beforeunloadHandler(e)) // 接触绑定
+                }
+                return FunMap[type];
             }
         },
         mounted() {
             // 页面加载完成后开始计时
             this.setTime();
-            // 绑定窗口关闭[监听]事件
-            window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
+            // 绑定窗口[监听]事件
+            this.handleWindow(0)
         },
-        destroyed() { // 解除窗口关闭[监听]事件
-            window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
+        destroyed() {
+            // 解除窗口关闭[监听]事件
+            this.handleWindow(1)
         }
     }
 }();