diff --git a/src/stores/useSystemStore.ts b/src/stores/useSystemStore.ts index 2300f72..280a279 100644 --- a/src/stores/useSystemStore.ts +++ b/src/stores/useSystemStore.ts @@ -1,5 +1,42 @@ import { defineStore } from 'pinia' +class TimerService { + private timerId: number | null = null + private startTs: number = 0 + remainingTime: string = '00:00:00' + + start(callback?: () => void) { + if (this.timerId) + return + + this.startTs = Date.now() + this.remainingTime = '00:00:00' + + this.timerId = window.setInterval(() => { + const diff = Date.now() - this.startTs + const secs = Math.floor(diff / 1000) + const h = Math.floor(secs / 3600) + const m = Math.floor((secs % 3600) / 60) + const s = secs % 60 + + this.remainingTime = [ + String(h).padStart(2, '0'), + String(m).padStart(2, '0'), + String(s).padStart(2, '0'), + ].join(':') + + callback?.() + }, 1000) + } + + stop() { + if (this.timerId) { + window.clearInterval(this.timerId) + this.timerId = null + } + this.startTs = 0 + } +} export const useSystemStore = defineStore('system', { state: () => ({ systemStatus: { @@ -27,12 +64,9 @@ export const useSystemStore = defineStore('system', { targetHumidity: 0, targetSlideTemperature: 0, targetNozzleTemperature: 0, - cleanRemainingTime: '', // 清洗管道用时 - cleanTimerId: null, // 清洗管道定时器 - cleanStartTs: 0, // 清洗管道开始时间 - preRemainingTime: '', // 预充用时 - preTimerId: null, // 预充定时器 - preStartTs: 0, // 预充开始时间 + syringeCleanTimerId: new TimerService(), // 清洗注射器管道定时器 + nozzleCleanTimerId: new TimerService(), // 清洗喷嘴管道定时器 + preTimerId: new TimerService(), // 预充定时器 }), actions: { updateTargetHumidity(humidity: number) { @@ -59,53 +93,23 @@ export const useSystemStore = defineStore('system', { pushSystemList(text: any) { this.systemList.push(text) }, - startCleanTimer() { - if (this.cleanTimerId) - return - this.cleanStartTs = Date.now() - this.cleanRemainingTime = '00:00:00' - this.cleanTimerId = window.setInterval(() => { - const diff = Date.now() - this.cleanStartTs - const secs = Math.floor(diff / 1000) - const h = Math.floor(secs / 3600) - const m = Math.floor((secs % 3600) / 60) - const s = secs % 60 - const hh = String(h).padStart(2, '0') - const mm = String(m).padStart(2, '0') - const ss = String(s).padStart(2, '0') - this.cleanRemainingTime = `${hh}:${mm}:${ss}` - }, 1000) - }, - stopCleanTimer() { - if (this.cleanTimerId) { - window.clearInterval(this.cleanTimerId) - this.cleanTimerId = null - } + startNozzleCleanTimer() { + this.nozzleCleanTimerId.start() + }, + stopNozzleCleanTimer() { + this.nozzleCleanTimerId.stop() + }, + startSyringeCleanTimer() { + this.syringeCleanTimerId.start() + }, + stopSyringeCleanTimer() { + this.syringeCleanTimerId.stop() }, startPreTimer() { - if (this.preTimerId) - return - this.preStartTs = Date.now() - this.preRemainingTime = '00:00:00' - this.preTimerId = window.setInterval(() => { - const diff = Date.now() - this.preStartTs - const secs = Math.floor(diff / 1000) - const h = Math.floor(secs / 3600) - const m = Math.floor((secs % 3600) / 60) - const s = secs % 60 - const hh = String(h).padStart(2, '0') - const mm = String(m).padStart(2, '0') - const ss = String(s).padStart(2, '0') - this.preRemainingTime = `${hh}:${mm}:${ss}` - }, 1000) + this.preTimerId.start() }, stopPreTimer() { - if (this.preTimerId) { - window.clearInterval(this.preTimerId) - this.preTimerId = undefined - } - // this.preRemainingTime = '' - this.preStartTs = 0 + this.preTimerId.stop() }, }, }) diff --git a/src/views/clean/index.vue b/src/views/clean/index.vue index 252f268..ea71729 100644 --- a/src/views/clean/index.vue +++ b/src/views/clean/index.vue @@ -3,7 +3,7 @@ import { ElMessageBox } from 'element-plus' import { FtMessage } from 'libs/message' import { sendControl } from 'libs/utils' import { useSystemStore } from 'stores/useSystemStore' -import { h, ref } from 'vue' +import { computed, h, ref } from 'vue' const systemStore = useSystemStore() // 使用 systemStore // 注射器管路清洗开始 @@ -36,12 +36,12 @@ const syringePipelineWash = () => { speed: syringeSpeed.value, }, } - try { - await sendControl(params) - } - finally { - syringePipelineWashRef.value.setLoading(false) - } + await sendControl(params) + syringePipelineWashRef.value.setLoading(false) + systemStore.syringeCleanTimerId.start() + }).catch(() => { + syringePipelineWashRef.value.setLoading(false) + systemStore.syringeCleanTimerId.stop() }) } // 喷嘴管路清洗开始 @@ -65,12 +65,12 @@ const nozzlePipelineWash = () => { params: { }, } - try { - await sendControl(params) - } - finally { - nozzlePipelineWashRef.value.setLoading(false) - } + await sendControl(params) + systemStore.nozzleCleanTimerId.start() + nozzlePipelineWashRef.value.setLoading(false) + }).catch(() => { + syringePipelineWashRef.value.setLoading(false) + systemStore.nozzleCleanTimerId.stop() }) } // 注射器管路清洗结束 @@ -81,6 +81,7 @@ const syringePipelineWashStop = async () => { params: {}, } await sendControl(params) + systemStore.syringeCleanTimerId.stop() } // 喷嘴管路清洗结束 const nozzlePipelineWashStop = async () => { @@ -90,8 +91,11 @@ const nozzlePipelineWashStop = async () => { params: {}, } await sendControl(params) + systemStore.nozzleCleanTimerId.stop() } const syringeSpeed = ref(0) +const syringeCleanRemainingTime = computed(() => systemStore.syringeCleanTimerId.remainingTime) +const nozzleCleanRemainingTime = computed(() => systemStore.nozzleCleanTimerId.remainingTime)
@@ -339,30 +339,62 @@ const nozzleStop = async () => { > 清洗注射器管路 - - - - - - - - + 停止清洗 + + + 计时 {{ syringeCleanRemainingTime }} + +
+ + + +
+
+ 清洗速度 + + uL/min +
+ + 清洗喷嘴管路 + + 停止清洗 - 清洗计时: {{ cleanRemainingTime }} + + 计时 {{ nozzleCleanRemainingTime }} +