App.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <script setup>
  2. import { RouterView } from 'vue-router'
  3. import { ref, onMounted } from 'vue'
  4. import { isMobile } from './utils/mobileDetector.js'
  5. const isLoading = ref(true)
  6. onMounted(() => {
  7. // 只在移动端显示loading,PC端直接显示内容
  8. if (isMobile()) {
  9. // 移动端:延迟显示,避免PC样式闪现
  10. setTimeout(() => {
  11. isLoading.value = false
  12. }, 500)
  13. } else {
  14. // PC端:立即显示内容
  15. isLoading.value = false
  16. }
  17. })
  18. </script>
  19. <template>
  20. <div class="app">
  21. <!-- Loading状态 -->
  22. <div v-if="isLoading" class="loading-container">
  23. <div class="loading-spinner">
  24. <div class="spinner"></div>
  25. <div class="loading-text">加载中...</div>
  26. </div>
  27. </div>
  28. <!-- 路由出口 -->
  29. <RouterView v-else />
  30. </div>
  31. </template>
  32. <style>
  33. /* 引入阿里巴巴普惠体3字体 */
  34. /* @import url('https://fonts.alicdn.com/t/c/font_4406263_pofp8o0bkt.css'); */
  35. * {
  36. margin: 0;
  37. padding: 0;
  38. box-sizing: border-box;
  39. font-family: 'Alibaba PuHuiTi 3.0';
  40. }
  41. html, body {
  42. margin: 0;
  43. padding: 0;
  44. height: 100%;
  45. }
  46. #app {
  47. height: 100%;
  48. }
  49. /* Loading样式 */
  50. .loading-container {
  51. position: fixed;
  52. top: 0;
  53. left: 0;
  54. width: 100%;
  55. height: 100%;
  56. background: #EBF3FF;
  57. display: flex;
  58. align-items: center;
  59. justify-content: center;
  60. z-index: 9999;
  61. }
  62. .loading-spinner {
  63. display: flex;
  64. flex-direction: column;
  65. align-items: center;
  66. gap: 16px;
  67. }
  68. .spinner {
  69. width: 40px;
  70. height: 40px;
  71. border: 3px solid #e5e7eb;
  72. border-top: 3px solid #3e7bfa;
  73. border-radius: 50%;
  74. animation: spin 1s linear infinite;
  75. }
  76. .loading-text {
  77. font-size: 18px;
  78. color: #6b7280;
  79. font-weight: 500;
  80. }
  81. @keyframes spin {
  82. 0% { transform: rotate(0deg); }
  83. 100% { transform: rotate(360deg); }
  84. }
  85. </style>