瀏覽代碼

添加定时跳转到排行榜

林旭祥 8 月之前
父節點
當前提交
841424817b
共有 1 個文件被更改,包括 32 次插入1 次删除
  1. 32 1
      src/layout/index.vue

+ 32 - 1
src/layout/index.vue

@@ -1,5 +1,5 @@
 <template>
-  <div class="app-main">
+  <div class="app-main" @click="handClick">
     <router-view v-slot="{ Component, route }">
       <Transition :enter-active-class="proxy?.animate.page.enter">
         <component :is="Component" :key="route.path" />
@@ -10,6 +10,37 @@
 
 <script setup name="AppMain" lang="ts">
 const { proxy } = getCurrentInstance() as any;
+const router = useRouter();
+
+const data = reactive<any>({
+  timer: null,
+
+});
+const { timer } = toRefs(data);
+
+
+const handClick = () => {
+  getClearTimer()
+  getCountDown();
+};
+
+const getCountDown = () => {
+  timer.value = setTimeout(() => {
+    router.push({ path: '/ranking' });
+  }, 1000 * 60 * 15)
+};
+
+const getClearTimer = () => {
+  clearTimeout(timer.value)
+};
+
+onMounted(() => {
+  getCountDown()
+})
+
+onUnmounted(() => {
+  getClearTimer()
+})
 </script>
 <style lang="scss" scoped>
 .app-main {