App.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <script setup lang="ts">
  2. import {
  3. NConfigProvider,
  4. NMessageProvider,
  5. useDialog,
  6. useMessage,
  7. } from "naive-ui";
  8. import { zhCN, dateZhCN } from "naive-ui";
  9. import { defineComponent, watchEffect } from "vue";
  10. import { useStore, setStore, store } from "./store/store";
  11. import themeOverrides from "./themeOverrides";
  12. setStore(useStore());
  13. const spinning = $computed(() => store.hasGlobalMask);
  14. const DummyComp = defineComponent({
  15. setup() {
  16. /** @ts-expect-error 特殊处理,其他地方是可以直接用$message的 */
  17. window.$message = useMessage();
  18. /** @ts-expect-error 特殊处理,其他地方是可以直接用$dialog的 */
  19. window.$dialog = useDialog();
  20. },
  21. render() {
  22. return null;
  23. },
  24. });
  25. watchEffect(() => {
  26. const bodyScrollProp = spinning ? "hidden" : "auto";
  27. document.body.style.overflow = bodyScrollProp;
  28. });
  29. </script>
  30. <template>
  31. <n-message-provider :duration="10000">
  32. <n-dialog-provider>
  33. <n-config-provider
  34. :locale="zhCN"
  35. :dateLocale="dateZhCN"
  36. :themeOverrides="themeOverrides"
  37. >
  38. <router-view />
  39. <DummyComp />
  40. </n-config-provider>
  41. </n-dialog-provider>
  42. </n-message-provider>
  43. <div
  44. v-if="spinning"
  45. style="position: absolute; top: 0; left: 0; width: 100vw; height: 100vh"
  46. >
  47. <n-spin :show="spinning" size="large" class="global-mask fade-in"> </n-spin>
  48. </div>
  49. </template>
  50. <style>
  51. .global-mask {
  52. position: absolute;
  53. top: 0;
  54. left: 0;
  55. height: 100vh;
  56. width: 100vw;
  57. /* 不知道为啥在窗口宽度小于#app min-width 的时候,遮罩层覆盖不全。要控制body的overflow。 */
  58. min-width: var(--app-min-width);
  59. overflow: hidden;
  60. display: flex;
  61. place-content: center;
  62. align-items: center;
  63. background-color: rgba(0, 0, 0, 0.7);
  64. z-index: 6000;
  65. }
  66. .fade-in {
  67. opacity: 0;
  68. animation-name: fadeInOpacity;
  69. animation-delay: 1.5s;
  70. animation-iteration-count: 1;
  71. animation-timing-function: ease-in;
  72. animation-duration: 60s;
  73. }
  74. @keyframes fadeInOpacity {
  75. 0% {
  76. opacity: 0;
  77. }
  78. 10% {
  79. opacity: 0.7;
  80. }
  81. 100% {
  82. opacity: 0.7;
  83. }
  84. }
  85. </style>