2 changed files with 91 additions and 123 deletions
@ -1,34 +1,62 @@ |
|||||
import { defineStore } from 'pinia' |
import { defineStore } from 'pinia' |
||||
import { ref } from 'vue' |
|
||||
|
import { computed, ref } from 'vue' |
||||
|
|
||||
|
interface SealStateItem { |
||||
|
pressure: string |
||||
|
workState: string |
||||
|
workStateDisplay: string |
||||
|
} |
||||
|
|
||||
/** |
|
||||
* 密封状态管理模块 |
|
||||
* @module useSealStore |
|
||||
*/ |
|
||||
export const useSealStore = defineStore('seal', () => { |
export const useSealStore = defineStore('seal', () => { |
||||
// 状态定义
|
|
||||
const sealState = ref('idle') |
|
||||
const sealInfo = ref<Seal.SealStateItem>({ |
|
||||
|
const sealInfo = ref<SealStateItem>({ |
||||
pressure: '0', |
pressure: '0', |
||||
workState: 'idle', |
workState: 'idle', |
||||
workStateDisplay: '空闲', |
workStateDisplay: '空闲', |
||||
}) |
}) |
||||
|
|
||||
/** |
|
||||
* @function updateSealInfo |
|
||||
* @param {Seal.SealStateItem} dataInfo - 密封状态信息 |
|
||||
* @desc 更新密封状态信息,包括压力值和工作状态 |
|
||||
*/ |
|
||||
const updateSealInfo = (dataInfo: Seal.SealStateItem) => { |
|
||||
|
const leakRemainingTime = ref('') |
||||
|
const _leakTimerId = ref<number | undefined>(undefined) |
||||
|
const _leakStartTs = ref(0) |
||||
|
|
||||
|
function startLeakTimer() { |
||||
|
if (_leakTimerId.value) |
||||
|
return |
||||
|
_leakStartTs.value = Date.now() |
||||
|
leakRemainingTime.value = '00:00:00' |
||||
|
_leakTimerId.value = window.setInterval(() => { |
||||
|
const diff = Date.now() - _leakStartTs.value |
||||
|
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') |
||||
|
leakRemainingTime.value = `${hh}:${mm}:${ss}` |
||||
|
}, 1000) |
||||
|
} |
||||
|
|
||||
|
function stopLeakTimer() { |
||||
|
if (_leakTimerId.value) { |
||||
|
clearInterval(_leakTimerId.value) |
||||
|
_leakTimerId.value = undefined |
||||
|
} |
||||
|
leakRemainingTime.value = '' |
||||
|
_leakStartTs.value = 0 |
||||
|
} |
||||
|
|
||||
|
function updateSealInfo(dataInfo: SealStateItem) { |
||||
sealInfo.value = dataInfo |
sealInfo.value = dataInfo |
||||
} |
} |
||||
|
|
||||
|
const currentPressure = computed(() => sealInfo.value.pressure) |
||||
|
|
||||
return { |
return { |
||||
// 状态属性
|
|
||||
sealState, |
|
||||
sealInfo, |
sealInfo, |
||||
|
|
||||
// 操作方法
|
|
||||
|
leakRemainingTime, |
||||
|
currentPressure, |
||||
|
startLeakTimer, |
||||
|
stopLeakTimer, |
||||
updateSealInfo, |
updateSealInfo, |
||||
} |
} |
||||
}) |
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue