App.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <ConfigProvider :locale="zhCN">
  3. <router-view />
  4. </ConfigProvider>
  5. </template>
  6. <script setup>
  7. import { onMounted, nextTick } from 'vue'
  8. import { ConfigProvider } from 'ant-design-vue'
  9. import zhCN from 'ant-design-vue/es/locale/zh_CN'
  10. import useSettingsStore from '@/store/modules/settings'
  11. import { handleThemeStyle } from '@/utils/theme'
  12. onMounted(() => {
  13. nextTick(() => {
  14. const settingsStore = useSettingsStore()
  15. // 初始化主题样式
  16. handleThemeStyle(settingsStore.theme)
  17. // 初始化暗黑模式
  18. if (settingsStore.isDark) {
  19. document.documentElement.classList.add('dark')
  20. } else {
  21. document.documentElement.classList.remove('dark')
  22. }
  23. // 检查是否为分享页面
  24. const isSharePage = window.location.pathname.startsWith('/share/')
  25. // 移除 Loading 动画并显示 App
  26. const loader = document.querySelector('.app-loading')
  27. const app = document.getElementById('app')
  28. if (loader) {
  29. if (isSharePage) {
  30. // 分享页面立即移除加载动画,不延迟
  31. loader.style.opacity = '0'
  32. loader.style.visibility = 'hidden'
  33. // 停止星空动画,释放性能
  34. if (window.stopLoadingAnimation) {
  35. window.stopLoadingAnimation()
  36. }
  37. // 立即移除节点
  38. setTimeout(() => {
  39. loader.remove()
  40. }, 100)
  41. if (app) {
  42. app.classList.add('app-loaded')
  43. }
  44. } else {
  45. // 其他页面保持原有逻辑:强制延迟 1.5s 再开始淡出,让用户看清星空
  46. setTimeout(() => {
  47. loader.style.opacity = '0'
  48. loader.style.visibility = 'hidden'
  49. // 停止星空动画,释放性能
  50. if (window.stopLoadingAnimation) {
  51. window.stopLoadingAnimation()
  52. }
  53. // 动画结束后移除节点
  54. setTimeout(() => {
  55. loader.remove()
  56. }, 1200) // 对应 CSS 中的 1.2s transition
  57. if (app) {
  58. app.classList.add('app-loaded')
  59. }
  60. }, 1500)
  61. }
  62. } else {
  63. // 如果没有 loader(比如热更新),直接显示 app
  64. if (app) {
  65. app.classList.add('app-loaded')
  66. }
  67. }
  68. })
  69. })
  70. </script>