You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.5 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <script setup lang="ts">
  2. import { getStatus } from 'apis/system'
  3. import { socket } from 'libs/socket'
  4. import { useSystemStore } from 'stores/systemStore'
  5. import { onBeforeUnmount, onMounted, ref } from 'vue'
  6. const systemStore = useSystemStore()
  7. onMounted(async () => {
  8. const res = await getStatus()
  9. console.log(res)
  10. systemStore.updateSystemStatus(res)
  11. startProgress()
  12. })
  13. socket.init((data: System.SystemStatus) => {
  14. systemStore.updateSystemStatus(data)
  15. }, 'status')
  16. const progress = ref(0)
  17. let timer: any = null
  18. const version = __APP_VERSION__
  19. const startProgress = () => {
  20. const max = Math.floor(Math.random() * (90 - 80 + 1)) + 80
  21. timer = setInterval(() => {
  22. const randomStep = Math.floor(Math.random() * 9 + 1)
  23. if (systemStore.systemStatus.initComplete) {
  24. // 停止计时器
  25. progress.value = Math.min(progress.value + randomStep, 100)
  26. }
  27. else {
  28. progress.value = Math.min(progress.value + randomStep, max)
  29. }
  30. if (progress.value >= 100) {
  31. clearInterval(timer)
  32. }
  33. }, 100)
  34. }
  35. // 组件卸载时清理定时器
  36. onBeforeUnmount(() => {
  37. clearInterval(timer)
  38. })
  39. </script>
  40. <template>
  41. <!-- 进度条容器 -->
  42. <div v-if="progress < 100" class="main-content">
  43. <div class="progress-container">
  44. <div class="progress-bar" :style="{ width: `${progress}%` }" />
  45. <div class="progress-text">
  46. v{{ version }}系统初始化中 {{ progress }}%
  47. </div>
  48. </div>
  49. </div>
  50. <router-view v-else v-slot="{ Component }" class="main-content">
  51. <transition name="el-zoom-in-center">
  52. <component :is="Component" />
  53. </transition>
  54. </router-view>
  55. </template>
  56. <style scoped lang="scss">
  57. .main-content {
  58. width: 100%;
  59. height: 100%;
  60. background: url("assets/images/background.svg") no-repeat center;
  61. background-size: cover;
  62. overflow: hidden;
  63. }
  64. .login-container {
  65. display: flex;
  66. flex-direction: column;
  67. align-items: center;
  68. justify-content: center;
  69. height: 100vh;
  70. background: #f0f2f5;
  71. }
  72. img {
  73. width: 600px;
  74. position: absolute;
  75. top: 40%;
  76. right: 20%;
  77. }
  78. .progress-container {
  79. width: 50%;
  80. height: 20px;
  81. background: #e4e7ed;
  82. border-radius: 30px;
  83. position: relative;
  84. top: 90%;
  85. margin: 0 auto;
  86. }
  87. .progress-bar {
  88. height: 100%;
  89. background: linear-gradient(90deg, #1989FA, #096ae0);
  90. border-radius: 30px;
  91. transition: width 0.3s ease;
  92. }
  93. .progress-text {
  94. position: absolute;
  95. top: 50%;
  96. left: 50%;
  97. transform: translate(-50%, -50%);
  98. color: #fff;
  99. font-size: 12px;
  100. line-height: 12px;
  101. font-weight: 500;
  102. }
  103. </style>