refactor: extract constants
This commit is contained in:
@@ -9,6 +9,8 @@ import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
import type { StationDevices } from './domains';
|
||||
import { useLineDevicesStore } from '@/stores/line-devices';
|
||||
import { CanceledError } from 'axios';
|
||||
import { LINE_DEVICES_QUERY_KEY } from '@/constants';
|
||||
|
||||
export interface LineDevices {
|
||||
[stationCode: Station['code']]: StationDevices;
|
||||
@@ -36,7 +38,7 @@ export function useLineDevicesQuery() {
|
||||
const { lineDevices } = storeToRefs(lineDevicesStore);
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['line-devices'],
|
||||
queryKey: [LINE_DEVICES_QUERY_KEY],
|
||||
enabled: computed(() => onlineStationList.value.length > 0 && pollingEnabled.value),
|
||||
staleTime: Infinity,
|
||||
refetchOnMount: false,
|
||||
@@ -74,6 +76,7 @@ export function useLineDevicesQuery() {
|
||||
stationDevices[DeviceType.Camera] = records;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof CanceledError) return;
|
||||
console.error(`获取车站 ${station.name} 摄像机数据失败:`, error);
|
||||
stationDevices[DeviceType.Camera] = [];
|
||||
}),
|
||||
@@ -82,6 +85,7 @@ export function useLineDevicesQuery() {
|
||||
stationDevices[DeviceType.Decoder] = records;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof CanceledError) return;
|
||||
console.error(`获取车站 ${station.name} 解码器数据失败:`, error);
|
||||
stationDevices[DeviceType.Decoder] = [];
|
||||
}),
|
||||
@@ -90,6 +94,7 @@ export function useLineDevicesQuery() {
|
||||
stationDevices[DeviceType.Keyboard] = records;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof CanceledError) return;
|
||||
console.error(`获取车站 ${station.name} 网络键盘数据失败:`, error);
|
||||
stationDevices[DeviceType.Keyboard] = [];
|
||||
}),
|
||||
@@ -98,6 +103,7 @@ export function useLineDevicesQuery() {
|
||||
stationDevices[DeviceType.MediaServer] = records;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof CanceledError) return;
|
||||
console.error(`获取车站 ${station.name} 媒体服务器数据失败:`, error);
|
||||
stationDevices[DeviceType.MediaServer] = [];
|
||||
}),
|
||||
@@ -106,6 +112,7 @@ export function useLineDevicesQuery() {
|
||||
stationDevices[DeviceType.Nvr] = records;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof CanceledError) return;
|
||||
console.error(`获取车站 ${station.name} 录像机数据失败:`, error);
|
||||
stationDevices[DeviceType.Nvr] = [];
|
||||
}),
|
||||
@@ -114,6 +121,7 @@ export function useLineDevicesQuery() {
|
||||
stationDevices[DeviceType.SecurityBox] = records;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof CanceledError) return;
|
||||
console.error(`获取车站 ${station.name} 安防箱数据失败:`, error);
|
||||
stationDevices[DeviceType.SecurityBox] = [];
|
||||
}),
|
||||
@@ -122,6 +130,7 @@ export function useLineDevicesQuery() {
|
||||
stationDevices[DeviceType.Switch] = records;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof CanceledError) return;
|
||||
console.error(`获取车站 ${station.name} 交换机数据失败:`, error);
|
||||
stationDevices[DeviceType.Switch] = [];
|
||||
}),
|
||||
@@ -130,6 +139,7 @@ export function useLineDevicesQuery() {
|
||||
stationDevices[DeviceType.VideoServer] = records;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof CanceledError) return;
|
||||
console.error(`获取车站 ${station.name} 视频服务器数据失败:`, error);
|
||||
stationDevices[DeviceType.VideoServer] = [];
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user