Commit b1849dd9 authored by “yiyousong”'s avatar “yiyousong”

perf: 优化页面

parent aef9f1d3
...@@ -26,19 +26,53 @@ ...@@ -26,19 +26,53 @@
</template> </template>
<script> <script>
import { mapGetters } from "vuex";
export default { export default {
data() { data() {
return {}; return {
timeOut: null,
defaultTimes: 300,
times: 0,
};
}, },
computed: {
...mapGetters(["times"]), created() {
this.isTimeOut();
}, },
created() {},
methods: { methods: {
handleBack() { handleBack() {
this.$router.back(); this.$router.back();
}, },
// 返回首页
startTimer() {
clearInterval(this.timeOut);
this.times = this.defaultTimes;
this.timeOut = setInterval(() => {
if (this.times == 0) {
this.$router.push({ path: "/" });
}
this.times -= 1;
}, 1000);
},
// 无任何操作返回首页
isTimeOut() {
if (this.$route.path == "/" || this.$route.path == "/home") {
return;
}
this.startTimer();
document.body.addEventListener("mousemove", this.startTimer);
document.body.addEventListener("mouseup", this.startTimer);
document.body.addEventListener("keyup", this.startTimer);
document.body.addEventListener("click", this.startTimer);
document.body.addEventListener("touchend", this.startTimer);
},
},
beforeDestroy() {
document.body.removeEventListener("mousemove", this.startTimer);
document.body.removeEventListener("mouseup", this.startTimer);
document.body.removeEventListener("keyup", this.startTimer);
document.body.removeEventListener("click", this.startTimer);
document.body.removeEventListener("touchend", this.startTimer);
this.timeOut && clearInterval(this.timeOut);
}, },
}; };
</script> </script>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
</template> </template>
<script> <script>
import { mapMutations, mapGetters } from "vuex"; // import { mapMutations, mapGetters } from "vuex";
export default { export default {
data() { data() {
return { return {
...@@ -13,45 +13,45 @@ export default { ...@@ -13,45 +13,45 @@ export default {
}; };
}, },
computed: { computed: {
...mapGetters(["times"]), // ...mapGetters(["times"]),
}, },
created() { created() {
this.isTimeOut(); // this.isTimeOut();
}, },
methods: { methods: {
...mapMutations(["SET_times"]), // ...mapMutations(["SET_times"]),
// 返回首页 // 返回首页
startTimer() { // startTimer() {
clearInterval(this.timeOut); // clearInterval(this.timeOut);
this.SET_times(this.defaultTimes); // this.SET_times(this.defaultTimes);
this.timeOut = setInterval(() => { // this.timeOut = setInterval(() => {
if (this.times == 0) { // if (this.times == 0) {
this.$router.push({ path: "/" }); // this.$router.push({ path: "/" });
} // }
this.SET_times(this.times - 1); // this.SET_times(this.times - 1);
}, 1000); // }, 1000);
}, // },
// 无任何操作返回首页 // // 无任何操作返回首页
isTimeOut() { // isTimeOut() {
if (this.$route.path == "/" || this.$route.path == "/home") { // if (this.$route.path == "/" || this.$route.path == "/home") {
return; // return;
} // }
this.startTimer(); // this.startTimer();
document.body.addEventListener("mousemove", this.startTimer); // document.body.addEventListener("mousemove", this.startTimer);
document.body.addEventListener("mouseup", this.startTimer); // document.body.addEventListener("mouseup", this.startTimer);
document.body.addEventListener("keyup", this.startTimer); // document.body.addEventListener("keyup", this.startTimer);
document.body.addEventListener("click", this.startTimer); // document.body.addEventListener("click", this.startTimer);
document.body.addEventListener("touchend", this.startTimer); // document.body.addEventListener("touchend", this.startTimer);
}, // },
},
beforeDestroy() {
document.body.removeEventListener("mousemove", this.startTimer);
document.body.removeEventListener("mouseup", this.startTimer);
document.body.removeEventListener("keyup", this.startTimer);
document.body.removeEventListener("click", this.startTimer);
document.body.removeEventListener("touchend", this.startTimer);
clearInterval(this.timeOut);
}, },
// beforeDestroy() {
// document.body.removeEventListener("mousemove", this.startTimer);
// document.body.removeEventListener("mouseup", this.startTimer);
// document.body.removeEventListener("keyup", this.startTimer);
// document.body.removeEventListener("click", this.startTimer);
// document.body.removeEventListener("touchend", this.startTimer);
// clearInterval(this.timeOut);
// },
}; };
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment