const MAX_IDLE_TIME = 30 * 60 * 1000;
let lastActionTime = new Date();
import store from "@/store";
import router from "@/router/router";

function updateLastActionTime() {
  lastActionTime = new Date();
}

// 定义一个计时器
let timeoutId = setTimeout(() => {
  console.log('用户已经很长时间没有操作了！');
  backLogOut()
}, MAX_IDLE_TIME);

// 监听页面上任何一个元素的点击事件
document.addEventListener('click', () => {
  updateLastActionTime();
  clearTimeout(timeoutId);
  timeoutId = setTimeout(() => {
    console.log('用户已经很长时间没有操作了！');
    backLogOut()
  }, MAX_IDLE_TIME);
});

function backLogOut() {
  store.dispatch("LogOut").then(() => {
    router.push({path: "/login"});
  });
}
