|
|
@ -45,6 +45,13 @@ export const useWebSocketStore = defineStore({ |
|
|
|
this.eventHandlers[event].push(handler); |
|
|
|
}, |
|
|
|
|
|
|
|
// emit event
|
|
|
|
emitEvent( event, ... data ) { |
|
|
|
let handlers = this.eventHandlers[event] || []; |
|
|
|
for ( const handler of handlers ) { |
|
|
|
handler(... data); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -52,6 +59,8 @@ export const useWebSocketStore = defineStore({ |
|
|
|
initCommandSocket() { |
|
|
|
const url = import.meta.env.VITE_BASE_WS1_URL |
|
|
|
const init = new Socket(url) |
|
|
|
init.onConnected = () => this.emitEvent('Connected', 'CommnadExecutor'); |
|
|
|
|
|
|
|
const settingStore = useSettingStore() |
|
|
|
const userStore = useUserStore() |
|
|
|
const testStore = useTestStore() |
|
|
@ -74,7 +83,9 @@ export const useWebSocketStore = defineStore({ |
|
|
|
let response = JSON.parse(ev.data); |
|
|
|
const handler = $this.callPromiseHandlers[messageId]; |
|
|
|
delete $this.callPromiseHandlers[messageId]; |
|
|
|
console.log(`[Call Response : ${messageId}] ${handler.message.command} => ${JSON.stringify(response)}`); |
|
|
|
if ( false !== handler.options.log ) { |
|
|
|
console.log(`[Call Response : ${messageId}] ${handler.message.command} => ${JSON.stringify(response)}`); |
|
|
|
} |
|
|
|
if ( 0 === response.ackcode ) { |
|
|
|
handler.resolve(response); |
|
|
|
} else { |
|
|
@ -88,118 +99,7 @@ export const useWebSocketStore = defineStore({ |
|
|
|
console.log(JSON.parse(ev.data)) |
|
|
|
switch (messageId) { |
|
|
|
case 'getState': |
|
|
|
// 初始化完毕
|
|
|
|
const { state } = JSON.parse(ev.data) |
|
|
|
const { |
|
|
|
disinfectionWorkState, |
|
|
|
disinfectionState, |
|
|
|
preHeat, |
|
|
|
preHeatRaminTimeS, |
|
|
|
estimatedRemainingTimeS, |
|
|
|
disinfection_id, |
|
|
|
isLogin, |
|
|
|
permissionLevel, |
|
|
|
sensor_data, |
|
|
|
drainingWorkState, |
|
|
|
replenishingFluidsWorkState, |
|
|
|
} = state || {} |
|
|
|
if (!isLogin) { |
|
|
|
window.location.href = 'http://127.0.0.1/#/' |
|
|
|
return |
|
|
|
} |
|
|
|
const { |
|
|
|
h2o2_1, |
|
|
|
h2o2_2, |
|
|
|
h2o2_3, |
|
|
|
humid_1, |
|
|
|
humid_2, |
|
|
|
humid_3, |
|
|
|
saturation_1, |
|
|
|
temp_1, |
|
|
|
temp_2, |
|
|
|
temp_3, |
|
|
|
airCompressor, |
|
|
|
disinfectant_volume, |
|
|
|
heatingStrip, |
|
|
|
airBlower, |
|
|
|
sprinklerPump, |
|
|
|
chargingPump, |
|
|
|
waterImmersionSensor1, |
|
|
|
waterImmersionSensor2, |
|
|
|
chargingPumpRPM, |
|
|
|
sprinklerPumpRPM, |
|
|
|
sprinklerPumpGPM, |
|
|
|
pressure, |
|
|
|
AirInletProportionalValve, |
|
|
|
AirOutletProportionalValve, |
|
|
|
} = sensor_data |
|
|
|
const { channelState } = airCompressor || {} |
|
|
|
testStore.updateAirCompressorChannel(channelState) |
|
|
|
const { nowlog, targetlog } = disinfectionState || {} |
|
|
|
deviceStore.updateTargetLog(targetlog) |
|
|
|
// 必须开始的时候才改变log 否则不懂
|
|
|
|
if ([1, 2, 3, 4].includes(disinfectionWorkState)) { |
|
|
|
localStorage.setItem('logVal', targetlog) |
|
|
|
} |
|
|
|
deviceStore.updateNowLog(nowlog) |
|
|
|
if ([1, 2, 3, 4].includes(disinfectionWorkState)) { |
|
|
|
operatorStore.updateShowStartReady(false) |
|
|
|
} else { |
|
|
|
operatorStore.updateStopReady(false) |
|
|
|
} |
|
|
|
sealStore.updateAllPressure(pressure) |
|
|
|
settingStore.updateSprinklerPumpGPM(sprinklerPumpGPM) |
|
|
|
settingStore.updateChargingPumpRPM(chargingPumpRPM) |
|
|
|
settingStore.updateSprinklerPumpRPM(sprinklerPumpRPM) |
|
|
|
operatorStore.updateDrainingWorkState(drainingWorkState) |
|
|
|
operatorStore.updateReplenishingFluidsWorkState( |
|
|
|
replenishingFluidsWorkState, |
|
|
|
) |
|
|
|
testStore.updateWaterImmersionSensor1( |
|
|
|
waterImmersionSensor1 == 0 ? false : true, |
|
|
|
) |
|
|
|
testStore.updateWaterImmersionSensor2( |
|
|
|
waterImmersionSensor2 == 0 ? false : true, |
|
|
|
) |
|
|
|
// 将sensor_data中的数据更新到store中
|
|
|
|
testStore.updateAirCompressorObj(airCompressor) |
|
|
|
testStore.updateAirBlowerObj(airBlower) |
|
|
|
testStore.updateHeatingStripObj(heatingStrip) |
|
|
|
testStore.updateSprinklerPump(sprinklerPump) |
|
|
|
testStore.updateChargingPump(chargingPump) |
|
|
|
settingStore.updateDeviceIp('192.168.8.13') |
|
|
|
deviceStore.updateDisinfectantCapacity(disinfectant_volume) |
|
|
|
deviceStore.updateBinTemperature(temp_1) |
|
|
|
deviceStore.updateBinHumidity(humid_1) |
|
|
|
deviceStore.updateBinHP(h2o2_1) |
|
|
|
deviceStore.updateBinSaturation(saturation_1) |
|
|
|
deviceStore.updateEnvirTemperature1(temp_2) |
|
|
|
deviceStore.updateEnvirHumidity1(humid_2) |
|
|
|
deviceStore.updateEnvirHP1(h2o2_2) |
|
|
|
deviceStore.updateEnvirTemperature2(temp_3) |
|
|
|
deviceStore.updateEnvirHumidity2(humid_3) |
|
|
|
deviceStore.updateEnvirHP2(h2o2_3) |
|
|
|
|
|
|
|
userStore.updatePermission(permissionLevel) |
|
|
|
settingStore.updateInitLoading() |
|
|
|
operatorStore.updatePreHeatRaminTimeS(preHeatRaminTimeS) |
|
|
|
operatorStore.updatePreHeat(preHeat) |
|
|
|
operatorStore.updateDisinfectStatus(disinfectionWorkState) |
|
|
|
operatorStore.updateEstimatedRemainingTimeS(estimatedRemainingTimeS) |
|
|
|
operatorStore.updateDisinfectionId(disinfection_id) |
|
|
|
// 将sensor_data中的数据更新到store中
|
|
|
|
|
|
|
|
if ([1, 2, 3, 4].includes(operatorStore.disinfectStatus)) { |
|
|
|
saveEchartsDataToLocal( |
|
|
|
moment().utcOffset(8).format('HH:mm'), |
|
|
|
[temp_1, humid_1, h2o2_1, saturation_1], |
|
|
|
[temp_2, humid_2, h2o2_2, saturation_1], |
|
|
|
[temp_3, humid_3, h2o2_3, saturation_1], |
|
|
|
) |
|
|
|
echartsStore.updateBinCharts( |
|
|
|
JSON.parse(localStorage.getItem('bin')), |
|
|
|
) |
|
|
|
} |
|
|
|
throw new Error('存在未处理的getState消息'); |
|
|
|
break |
|
|
|
case 'getAllUser': |
|
|
|
const { dbval } = JSON.parse(ev.data) |
|
|
@ -368,7 +268,7 @@ export const useWebSocketStore = defineStore({ |
|
|
|
}, |
|
|
|
|
|
|
|
// call and wait for response
|
|
|
|
call( command, params=null ) { |
|
|
|
call( command, params=null,options={} ) { |
|
|
|
this.callIdCounter += 1; |
|
|
|
if ( this.callIdCounter > 1000000 ) { |
|
|
|
this.callIdCounter = 0; |
|
|
@ -385,9 +285,13 @@ export const useWebSocketStore = defineStore({ |
|
|
|
message.params = params; |
|
|
|
} |
|
|
|
} |
|
|
|
this.callPromiseHandlers[callId] = { resolve, reject, message }; |
|
|
|
this.callPromiseHandlers[callId] = { resolve, reject, message, options }; |
|
|
|
console.log(`[Call Request : ${callId}] ${command}(${JSON.stringify(params)})`); |
|
|
|
this.sendCommandMsg(message); |
|
|
|
|
|
|
|
if ( null === this.socketCommandInstance ) { |
|
|
|
throw new Error('Command Socket Not Ready'); |
|
|
|
} |
|
|
|
this.socketCommandInstance.msg(message); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
@ -395,6 +299,7 @@ export const useWebSocketStore = defineStore({ |
|
|
|
initEventSocket() { |
|
|
|
const url = import.meta.env.VITE_BASE_WS2_URL |
|
|
|
const init = new Socket(url) |
|
|
|
init.onConnected = () => this.emitEvent('Connected', 'EventReporter'); |
|
|
|
init.connect() |
|
|
|
const deviceStore = useDeviceStore() |
|
|
|
const testStore = useTestStore() |
|
|
|