vue页面无操作10分钟内调转到登录页面

https://blog.csdn.net/lbPro0412/article/details/83864454

页面在设定时间内无任何操作(鼠标的点击、滑动、路由的切换、是否请求接口等),跳转到登录页,在跳转前把url存起来,点击登录的时候用。

 

<template>
  <div id="app" @mouseover="OperatingWebsite()">
    <router-view/>
  </div>
</template>
<script>
export default {
  data() {
    return {
      currentTime: new Date().getTime() 
    };
  },
  methods: {
    OperatingWebsite() {
      let currentTime = this.currentTime;
      console.log(currentTime, "currentTime");
      let lastTime = new Date().getTime();
      console.log(lastTime, "lastTime");
      let timeOut = 10 * 60 * 1000; //设置时间 10分钟
      if (lastTime - currentTime > timeOut) {
        // 未操作页面,跳转登录页面
        this.currentTime = new Date().getTime(); 
        const fullPath = this.$route.fullPath;
        const query = this.$Base64.encode(fullPath);
        this.$router.push({
          path: "/user",
          query: {
            type: query
          }
        });
      } else {
        this.currentTime = new Date().getTime(); 
      }
 
      // const truthPathQuery = this.$route.query.type;
      // const truthPath = this.$Base64.decode(truthPathQuery); //点击登录的时候跳转这个地址
    }
  }

}

  

posted @ 2019-03-28 16:52  瑞蚨祥qianjin  阅读(956)  评论(0编辑  收藏  举报