Browse Source

fix: 系统初始化进度条

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

22
src/app.vue

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

3
src/stores/systemStore.ts

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

1
src/types/system.d.ts

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

Loading…
Cancel
Save