Browse Source

fix: 系统初始化进度条

feature/three
guoapeng 3 months ago
parent
commit
8453ee89ed
  1. 20
      src/app.vue
  2. 3
      src/stores/systemStore.ts
  3. 1
      src/types/system.d.ts

20
src/app.vue

@ -4,14 +4,16 @@ import { socket } from 'libs/socket'
import { useSystemStore } from 'stores/systemStore'
import { onBeforeUnmount, onMounted, ref } from 'vue'
const systemStore = useSystemStore()
onMounted(async () => {
document.body.style.setProperty('--el-color-primary', '#1989fa')
const res = await getStatus()
useSystemStore().updateSystemStatus(res)
console.log(res)
// systemStore.updateSystemStatus(res)
startProgress()
})
socket.init((data: System.SystemStatus) => {
useSystemStore().updateSystemStatus(data)
systemStore.updateSystemStatus(data)
}, 'status')
const progress = ref(0)
@ -19,19 +21,23 @@ let timer: any = null
const version = __APP_VERSION__
const startProgress = () => {
const max = Math.floor(Math.random() * (90 - 80 + 1)) + 80
timer = setInterval(() => {
const randomStep = Math.floor(Math.random() * 9 + 1)
if (systemStore.systemStatus.initComplete) {
//
progress.value = Math.min(progress.value + randomStep, 100)
}
else {
progress.value = Math.min(progress.value + randomStep, max)
}
if (progress.value >= 100) {
clearInterval(timer)
}
}, 50)
}, 100)
}
onMounted(() => {
startProgress()
})
//
onBeforeUnmount(() => {

3
src/stores/systemStore.ts

@ -4,7 +4,8 @@ export const useSystemStore = defineStore('system', {
state: (): System.SystemStore => ({
systemStatus: {
virtual: false,
initComplete: true,
initComplete: false,
selfTest: true,
emergencyStop: false,
door: {
status: false,

1
src/types/system.d.ts

@ -13,6 +13,7 @@ declare namespace System {
interface SystemStatus {
virtual: boolean
initComplete: boolean
selfTest: boolean
emergencyStop: boolean
door: {
status: boolean

Loading…
Cancel
Save