|
|
|
@ -4,6 +4,7 @@ import type { IOnlineDevice, IUpFirmwareStatus } from '@/views/stationData/type'
@@ -4,6 +4,7 @@ import type { IOnlineDevice, IUpFirmwareStatus } from '@/views/stationData/type'
|
|
|
|
|
import ZMQWorker from '@/composables/useZMQJsonWorker' |
|
|
|
|
import { getSubTopic, type SubMsgData } from '@/utils/zmq' |
|
|
|
|
import { getDeviceTopic } from '@/views/stationData/utils' |
|
|
|
|
import dayjs from "dayjs"; |
|
|
|
|
|
|
|
|
|
export const useTransferDataStore = defineStore('transfer', () => { |
|
|
|
|
const subDevices = getSubTopic('client', 'status', 'transfer') |
|
|
|
@ -25,14 +26,17 @@ export const useTransferDataStore = defineStore('transfer', () => {
@@ -25,14 +26,17 @@ export const useTransferDataStore = defineStore('transfer', () => {
|
|
|
|
|
const checkDeviceStatusInterval = ref<NodeJS.Timeout>() |
|
|
|
|
|
|
|
|
|
function checkDeviceStatus() { |
|
|
|
|
checkDeviceStatusInterval.value = setInterval(() => { |
|
|
|
|
checkDeviceStatusInterval.value = setInterval(checkDeviceStatusFn, 100); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const checkDeviceStatusFn = () => { |
|
|
|
|
const now = Date.now(); |
|
|
|
|
devicesMap.forEach((device: IOnlineDevice, sn) => { |
|
|
|
|
// console.log(device, dayjs(now).format('HH:mm:ss'), dayjs(device.lastUpdated).format('HH:mm:ss'), now - device.lastUpdated)
|
|
|
|
|
if (now - device.lastUpdated > 5500) { |
|
|
|
|
device.status = '离线'; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, 1000); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function formatSizeFromKB(num: number): string { |
|
|
|
@ -88,6 +92,7 @@ export const useTransferDataStore = defineStore('transfer', () => {
@@ -88,6 +92,7 @@ export const useTransferDataStore = defineStore('transfer', () => {
|
|
|
|
|
onMounted(() => { |
|
|
|
|
worker.subscribe(getDeviceTopic, getSubDevicesCb) |
|
|
|
|
checkDeviceStatus() |
|
|
|
|
document.addEventListener('visibilitychange', checkDeviceStatusFn) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const route = useRoute() |
|
|
|
@ -95,6 +100,7 @@ export const useTransferDataStore = defineStore('transfer', () => {
@@ -95,6 +100,7 @@ export const useTransferDataStore = defineStore('transfer', () => {
|
|
|
|
|
watch(() => route.path, (val) => { |
|
|
|
|
if (!['/station/data-transfer', '/station'].includes(val)) { |
|
|
|
|
clearInterval(checkDeviceStatusInterval.value) |
|
|
|
|
document.removeEventListener('visibilitychange', checkDeviceStatusFn) |
|
|
|
|
worker.unsubscribe(subDevices) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|