App.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. loading!.close();
  37. loading = null;
  38. exixts = false;
  39. }, 16);
  40. }
  41. },
  42. });
  43. </script>