|
@@ -3,23 +3,10 @@ import router from '@/router/index'
|
|
|
import { setLog } from '@/apis/log'
|
|
import { setLog } from '@/apis/log'
|
|
|
import tokenInfo from '@/stores/modules/token'
|
|
import tokenInfo from '@/stores/modules/token'
|
|
|
|
|
|
|
|
-let outTime = 0;
|
|
|
|
|
-let outTimeObj: NodeJS.Timeout | null = null;
|
|
|
|
|
-
|
|
|
|
|
-const outFun = function(status = 'init', currentRouter: any) {
|
|
|
|
|
- if(status == 'init'){
|
|
|
|
|
- outTime = 0;
|
|
|
|
|
- if(outTimeObj) clearInterval(outTimeObj)
|
|
|
|
|
- }
|
|
|
|
|
- outTimeObj = setInterval(() => {
|
|
|
|
|
- if(outTime == 10){
|
|
|
|
|
- // setLogInfoRemain(currentRouter)
|
|
|
|
|
- outTime = 0
|
|
|
|
|
- } else {
|
|
|
|
|
- outTime++;
|
|
|
|
|
- }
|
|
|
|
|
- }, 1000)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// 使用时间戳精确计算页面停留时间,避免间隔计时带来的误差
|
|
|
|
|
+let pageEnterAt = 0;
|
|
|
|
|
+const resetEnterTime = () => { pageEnterAt = Date.now(); };
|
|
|
|
|
+const getStaySeconds = () => Math.max(0, Math.round((Date.now() - pageEnterAt) / 1000));
|
|
|
|
|
|
|
|
export function setLogInfo(router: any, describe: any) {
|
|
export function setLogInfo(router: any, describe: any) {
|
|
|
setLog({
|
|
setLog({
|
|
@@ -28,7 +15,7 @@ export function setLogInfo(router: any, describe: any) {
|
|
|
describe: describe
|
|
describe: describe
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- outFun('init', router);
|
|
|
|
|
|
|
+ resetEnterTime();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function setLogInfoHide(router: any, describe: any) {
|
|
export function setLogInfoHide(router: any, describe: any) {
|
|
@@ -36,7 +23,7 @@ export function setLogInfoHide(router: any, describe: any) {
|
|
|
page: router.meta.title,
|
|
page: router.meta.title,
|
|
|
page_url: router.fullPath,
|
|
page_url: router.fullPath,
|
|
|
describe: describe,
|
|
describe: describe,
|
|
|
- time: outTime,
|
|
|
|
|
|
|
+ time: getStaySeconds(),
|
|
|
type: 3
|
|
type: 3
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -50,7 +37,7 @@ export function setLogInfoRemain(router: any) {
|
|
|
action: '停留' + router.meta.title + '10s',
|
|
action: '停留' + router.meta.title + '10s',
|
|
|
query: { ...router.query, ...router.params }
|
|
query: { ...router.query, ...router.params }
|
|
|
},
|
|
},
|
|
|
- time: outTime,
|
|
|
|
|
|
|
+ time: getStaySeconds(),
|
|
|
type: 6
|
|
type: 6
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|