App.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <Locale>
  3. <RouterView v-slot="{ Component }">
  4. <!-- <KeepAlive> -->
  5. <component :is="Component" />
  6. <!-- </KeepAlive> -->
  7. </RouterView>
  8. <div id="dialog"></div>
  9. </Locale>
  10. </template>
  11. <script lang="ts" setup>
  12. import Locale from "@/config/locale.vue";
  13. import { ElLoading } from "element-plus";
  14. import { lifeHook } from "./request/state";
  15. let loading: ReturnType<typeof ElLoading.service> | null = null;
  16. let timeout: ReturnType<typeof setTimeout>;
  17. let exixts = false;
  18. lifeHook.push({
  19. start: () => {
  20. clearTimeout(timeout);
  21. if (!exixts) {
  22. // service可能会再次引起life所以需要额外变量提前占位
  23. exixts = true;
  24. loading = ElLoading.service({
  25. lock: true,
  26. fullscreen: true,
  27. text: "加载中",
  28. background: "rgba(0, 0, 0, 0.7)",
  29. });
  30. }
  31. },
  32. end: () => {
  33. if (exixts) {
  34. clearTimeout(timeout);
  35. timeout = setTimeout(() => {
  36. console.log("close");
  37. loading!.close();
  38. loading = null;
  39. exixts = false;
  40. }, 16);
  41. }
  42. },
  43. });
  44. </script>