|
|
@@ -3,19 +3,64 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { mapState } from 'vuex';
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- timer: null
|
|
|
+ timer: null,
|
|
|
+ x: null,
|
|
|
+ y: null,
|
|
|
+ count: 0,
|
|
|
+ outTime: 60
|
|
|
};
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ ...mapState(['userInfo'])
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ userInfo() {
|
|
|
+ if (!this.timer) {
|
|
|
+ this.timer = setInterval(this.go, 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
mounted() {
|
|
|
- window.addEventListener('visibilitychange', this.focusChange);
|
|
|
+ // window.addEventListener('visibilitychange', this.focusChange);
|
|
|
+ document.onmousemove = event => {
|
|
|
+ /* Act on the event */
|
|
|
+ var x1 = event.clientX;
|
|
|
+ var y1 = event.clientY;
|
|
|
+ if (this.x != x1 || this.y != y1) {
|
|
|
+ this.count = 0;
|
|
|
+ }
|
|
|
+ this.x = x1;
|
|
|
+ this.y = y1;
|
|
|
+ };
|
|
|
+ document.onkeydown = event => {
|
|
|
+ this.count = 0;
|
|
|
+ };
|
|
|
+ this.timer = setInterval(this.go, 1000);
|
|
|
},
|
|
|
destroyed() {
|
|
|
- window.removeEventListener('visibilitychange');
|
|
|
+ // window.removeEventListener('visibilitychange');
|
|
|
+ if (this.timer) {
|
|
|
+ clearInterval(this.timer);
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
+ go() {
|
|
|
+ this.count++;
|
|
|
+ if (this.count == this.outTime * 60 && this.$route.name !== 'login') {
|
|
|
+ sessionStorage.removeItem('token');
|
|
|
+ clearInterval(this.timer);
|
|
|
+ this.$alert('网站由于长时间未访问,已经下线账号', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ callback: action => {
|
|
|
+ this.$router.push('/login');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
focusChange() {
|
|
|
if (document.hidden) {
|
|
|
// 失去焦点
|
|
|
@@ -35,7 +80,7 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- }, 1000 * 60 * 30);
|
|
|
+ }, 1000 * 60 * this.outTime);
|
|
|
} else {
|
|
|
// 获取焦点
|
|
|
}
|