|
@@ -11,16 +11,13 @@ let stayTime = 0
|
|
|
let intervalTimer=null
|
|
|
|
|
|
export const openLoginTimer=()=>{
|
|
|
- // 登录时间
|
|
|
- localStorage.setItem("loginTime",new Date())
|
|
|
|
|
|
clearInterval(intervalTimer)
|
|
|
intervalTimer = setInterval(()=>{
|
|
|
- // let inactiveTime = time || new Date()
|
|
|
let ActiveTime=0
|
|
|
if(localStorage.getItem('loginTime')){
|
|
|
ActiveTime = (new Date()-new Date(localStorage.getItem('loginTime')))/1000
|
|
|
- console.log("1分钟间隔记录时长",ActiveTime+'s');
|
|
|
+ console.log("间隔记录时长",ActiveTime+'s');
|
|
|
recordActiveLogin({ActiveTime:Math.round(ActiveTime)}).then(res=>{
|
|
|
if(res.Ret!==200) return
|
|
|
})
|
|
@@ -39,7 +36,7 @@ export const recordActiveLoginFun=(time)=>{
|
|
|
}).finally(()=>{
|
|
|
// 清除工作
|
|
|
clearInterval(intervalTimer)
|
|
|
- localStorage.removeItem('loginTime')
|
|
|
+ // localStorage.removeItem('loginTime')
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -49,6 +46,7 @@ let timer = null
|
|
|
//打开计时器
|
|
|
export const optionTimeCalc = ()=>{
|
|
|
const IsActive = sessionStorage.getItem('IsActive')
|
|
|
+ // console.log(IsActive,'IsActive');
|
|
|
if(Number(IsActive)===0){
|
|
|
//console.log('打开计时器')
|
|
|
sessionStorage.setItem('IsActive',1)
|
|
@@ -62,7 +60,6 @@ export const startCalc = ()=>{
|
|
|
sessionStorage.setItem('preTitle',document.title)
|
|
|
timer = setInterval(()=>{
|
|
|
stayTime++
|
|
|
-
|
|
|
if(stayTime>=TimeInterval){
|
|
|
endCalc('timeup',0)
|
|
|
}
|
|
@@ -137,24 +134,25 @@ let rewriteHis = function(type){
|
|
|
}
|
|
|
|
|
|
export function init(){
|
|
|
- const unloadT = sessionStorage.getItem('unloadT')
|
|
|
- const IsActive = sessionStorage.getItem('IsActive')
|
|
|
- if(unloadT){
|
|
|
- //console.log('刷新该页呆了时长',unloadT)
|
|
|
- sessionStorage.removeItem('unloadT')
|
|
|
- sessionStorage.setItem('preTitle',document.title)
|
|
|
- if(Number(IsActive)){
|
|
|
- endCalc('unload',unloadT)
|
|
|
- }
|
|
|
- }
|
|
|
- timeStr = new Date().getTime()
|
|
|
+ // const unloadT = sessionStorage.getItem('unloadT')
|
|
|
+ // console.log("init",unloadT,IsActive);
|
|
|
+ // if(unloadT){
|
|
|
+ // //console.log('刷新该页呆了时长',unloadT)
|
|
|
+ // sessionStorage.removeItem('unloadT')
|
|
|
+ // sessionStorage.setItem('preTitle',document.title)
|
|
|
+ // if(Number(IsActive)){
|
|
|
+ // endCalc('unload',unloadT)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // timeStr = new Date().getTime()
|
|
|
+ sessionStorage.setItem('IsActive',0)
|
|
|
optionTimeCalc()
|
|
|
+ // const IsActive = sessionStorage.getItem('IsActive')
|
|
|
|
|
|
- if((!localStorage.getItem("loginTime")) && localStorage.getItem('auth')){
|
|
|
- // 初始化的时候 先重置最近登录时长
|
|
|
- recordActiveLogin({ActiveTime:0}).then(res=>{
|
|
|
- if(res.Ret!==200) return
|
|
|
- })
|
|
|
+ // if(Number(IsActive)){
|
|
|
+ // sessionStorage.setItem('unloadT',t)
|
|
|
+ // }
|
|
|
+ if(localStorage.getItem("loginTime") && localStorage.getItem('auth')){
|
|
|
openLoginTimer()
|
|
|
}
|
|
|
}
|
|
@@ -195,10 +193,23 @@ export const doPageEventListener=function(){
|
|
|
window.addEventListener('beforeunload',(e)=>{
|
|
|
console.log('beforeunload')
|
|
|
let t = new Date().getTime() - timeStr
|
|
|
+ // const unloadT = sessionStorage.getItem('unloadT')
|
|
|
const IsActive = sessionStorage.getItem('IsActive')
|
|
|
- if(Number(IsActive)){
|
|
|
- sessionStorage.setItem('unloadT',t)
|
|
|
- }
|
|
|
+ console.log("init",IsActive);
|
|
|
+ // if(unloadT){
|
|
|
+ //console.log('刷新该页呆了时长',unloadT)
|
|
|
+ // sessionStorage.removeItem('unloadT')
|
|
|
+ // sessionStorage.setItem('preTitle',document.title)
|
|
|
+ if(Number(IsActive)){
|
|
|
+ endCalc('unload',t)
|
|
|
+ }
|
|
|
+ // }
|
|
|
+ // timeStr = new Date().getTime()
|
|
|
+ // optionTimeCalc()
|
|
|
+ // const IsActive = sessionStorage.getItem('IsActive')
|
|
|
+ // if(Number(IsActive)){
|
|
|
+ // sessionStorage.setItem('unloadT',t)
|
|
|
+ // }
|
|
|
})
|
|
|
|
|
|
//刷新离开页面
|
|
@@ -207,7 +218,7 @@ export const doPageEventListener=function(){
|
|
|
recordActiveLoginFun()
|
|
|
// 猜测在unload这里 浏览器不会等待异步返回 清除工作在这进行
|
|
|
clearInterval(intervalTimer)
|
|
|
- localStorage.removeItem('loginTime')
|
|
|
+ // localStorage.removeItem('loginTime')
|
|
|
})
|
|
|
|
|
|
//popstate会在router.before/afterEach 之前触发,所以这里不对计时操作,操作放到before/afterEach
|
|
@@ -242,29 +253,6 @@ export const doPageEventListener=function(){
|
|
|
optionTimeCalc()
|
|
|
})
|
|
|
|
|
|
- //页面监听
|
|
|
- /* document.addEventListener('visibilitychange', function () {
|
|
|
- // 用户离开了当前页面
|
|
|
- if (document.visibilityState === 'hidden') {
|
|
|
- console.log('hidden')
|
|
|
- const IsActive = sessionStorage.getItem('IsActive')
|
|
|
- if(Number(IsActive)){
|
|
|
- let t = new Date().getTime() - timeStr
|
|
|
- timeStr = new Date().getTime()
|
|
|
- endCalc('hidden',t)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 用户打开或回到页面
|
|
|
- if (document.visibilityState === 'visible') {
|
|
|
- console.log('visible')
|
|
|
- const IsActive = sessionStorage.getItem('IsActive')
|
|
|
- if(IsActive==='0'){
|
|
|
- timeStr = new Date().getTime()
|
|
|
- optionTimeCalc()
|
|
|
- }
|
|
|
- }
|
|
|
- }); */
|
|
|
document.addEventListener('click',(e)=>{
|
|
|
|
|
|
//console.log('click',e,e.composedPath())
|
|
@@ -274,6 +262,7 @@ export const doPageEventListener=function(){
|
|
|
if(contentIndex===-1) return
|
|
|
//console.log('合法的click')
|
|
|
const IsActive = sessionStorage.getItem('IsActive')
|
|
|
+ console.log(IsActive,'IsActive');
|
|
|
if(Number(IsActive)===0){
|
|
|
optionTimeCalc()
|
|
|
}else{
|