当页面未操作30分钟后跳转到登录页面

  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();
            }

        }
    }
1 <div id="app" @mouseover="OperatingWebsite()" >
2     <router-view/>
3   </div>

 

posted @ 2019-03-21 16:47  前端极客  阅读(495)  评论(0编辑  收藏