index.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="app-main" @click="handClick">
  3. <router-view v-slot="{ Component, route }">
  4. <Transition :enter-active-class="proxy?.animate.page.enter">
  5. <component :is="Component" :key="route.path" />
  6. </Transition>
  7. </router-view>
  8. <RankingWindow ref="rankingWindowRef" @getClose="openRanking"></RankingWindow>
  9. </div>
  10. </template>
  11. <script setup name="AppMain" lang="ts">
  12. import VConsole from 'vconsole';
  13. const { proxy } = getCurrentInstance() as any;
  14. const router = useRouter();
  15. const rankingWindowRef = ref();
  16. const data = reactive<any>({
  17. timer: null
  18. });
  19. const { timer } = toRefs(data);
  20. const handClick = () => {
  21. //getClearTimer();
  22. if (!rankingWindowRef.value.rankingState) {
  23. openRanking();
  24. }
  25. };
  26. /**
  27. * 定时打开排行榜
  28. */
  29. const openRanking = () => {
  30. clearTimeout(timer.value);
  31. if (rankingWindowRef.value.rankingState) {
  32. rankingWindowRef.value.close();
  33. }
  34. //console.log("timer.value", timer.value)
  35. let state = localStorage.getItem('rankingSwitch1');
  36. if (state != "1") {
  37. return false;
  38. }
  39. // 设置新的定时器
  40. timer.value = setTimeout(() => {
  41. if (!rankingWindowRef.value.rankingState) {
  42. if (
  43. !['/ranking', '/login', '/login/qrcode', '/login/mobile', '/login/sunshineRun', '/sunshineRun', '/game/humanBody', '/game/football', '/game/fruit', '/game/basketball'].includes(router.currentRoute.value.fullPath)
  44. ) {
  45. rankingWindowRef.value.open();
  46. }
  47. }
  48. }, 1000 * 60 * 10);
  49. };
  50. const getClearTimer = () => {
  51. clearTimeout(timer.value);
  52. };
  53. onBeforeMount(() => {
  54. let state1 = localStorage.getItem('rankingSwitch1');
  55. if (state1 == undefined) {
  56. localStorage.setItem('rankingSwitch1', "1");
  57. }
  58. });
  59. onMounted(() => {
  60. openRanking();
  61. const vConsole = new VConsole({ theme: 'dark' });
  62. const vConsoleIcon: any = document.querySelector('.vc-switch');
  63. if (vConsoleIcon) {
  64. vConsoleIcon.style.display = 'none';
  65. localStorage.setItem('vConsole', "0");
  66. }
  67. });
  68. onBeforeUnmount(() => {
  69. getClearTimer();
  70. });
  71. </script>
  72. <style lang="scss" scoped>
  73. .app-main {
  74. height: 100vh;
  75. width: 100%;
  76. background: radial-gradient(87% 87% at 9% -34%, #315f7e 0%, #0f1926 100%);
  77. }
  78. </style>