refactor: reorganize files
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import type { NdmDeviceResultVO } from '@/apis/models';
|
||||
import { DeviceType, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums/device-type';
|
||||
import type { LineDevices, NdmDeviceResultVO } from '@/apis';
|
||||
import { DeviceType, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums';
|
||||
import { ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import type { LineDevices } from '../query';
|
||||
|
||||
export function useDeviceSelection() {
|
||||
const route = useRoute();
|
||||
|
||||
3
src/composables/index.ts
Normal file
3
src/composables/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './device';
|
||||
export * from './query';
|
||||
export * from './stomp';
|
||||
@@ -1,34 +0,0 @@
|
||||
import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
|
||||
import type { DeviceType } from '@/enums/device-type';
|
||||
|
||||
export interface StationAlarms {
|
||||
[DeviceType.Camera]: NdmDeviceAlarmLogResultVO[];
|
||||
[DeviceType.Decoder]: NdmDeviceAlarmLogResultVO[];
|
||||
[DeviceType.Keyboard]: NdmDeviceAlarmLogResultVO[];
|
||||
[DeviceType.MediaServer]: NdmDeviceAlarmLogResultVO[];
|
||||
[DeviceType.Nvr]: NdmDeviceAlarmLogResultVO[];
|
||||
[DeviceType.SecurityBox]: NdmDeviceAlarmLogResultVO[];
|
||||
[DeviceType.Switch]: NdmDeviceAlarmLogResultVO[];
|
||||
[DeviceType.VideoServer]: NdmDeviceAlarmLogResultVO[];
|
||||
unclassified: NdmDeviceAlarmLogResultVO[];
|
||||
}
|
||||
|
||||
export interface LineAlarms {
|
||||
[stationCode: string]: StationAlarms;
|
||||
}
|
||||
|
||||
export interface StationAlarmCounts {
|
||||
[DeviceType.Camera]: number;
|
||||
[DeviceType.Decoder]: number;
|
||||
[DeviceType.Keyboard]: number;
|
||||
[DeviceType.MediaServer]: number;
|
||||
[DeviceType.Nvr]: number;
|
||||
[DeviceType.SecurityBox]: number;
|
||||
[DeviceType.Switch]: number;
|
||||
[DeviceType.VideoServer]: number;
|
||||
unclassified: number;
|
||||
}
|
||||
|
||||
export interface LineAlarmCounts {
|
||||
[stationCode: string]: StationAlarmCounts;
|
||||
}
|
||||
@@ -1,3 +1 @@
|
||||
export * from './domains';
|
||||
|
||||
export * from './use-line-alarms-query';
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import type { StationAlarmCounts } from './domains';
|
||||
import type { Station } from '@/apis/domains';
|
||||
import { postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
||||
import { postNdmDeviceAlarmLogPage, type Station, type StationAlarmCounts } from '@/apis';
|
||||
import { LINE_ALARMS_QUERY_KEY } from '@/constants';
|
||||
import { DeviceType, tryGetDeviceTypeVal } from '@/enums/device-type';
|
||||
import { useLineAlarmsStore } from '@/stores/line-alarms';
|
||||
import { useQueryControlStore } from '@/stores/query-control';
|
||||
import { useStationStore } from '@/stores/station';
|
||||
import { DeviceType, tryGetDeviceTypeVal } from '@/enums';
|
||||
import { useLineAlarmsStore, useQueryControlStore, useStationStore } from '@/stores';
|
||||
import { runTask } from '@/utils';
|
||||
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import { runTask } from '@/utils/run-task';
|
||||
import dayjs from 'dayjs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
const createEmptyStationAlarmCounts = () => {
|
||||
return {
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import type {
|
||||
NdmCameraResultVO,
|
||||
NdmDecoderResultVO,
|
||||
NdmKeyboardResultVO,
|
||||
NdmMediaServerResultVO,
|
||||
NdmNvrResultVO,
|
||||
NdmSecurityBoxResultVO,
|
||||
NdmSwitchResultVO,
|
||||
NdmVideoServerResultVO,
|
||||
} from '@/apis/models';
|
||||
import type { DeviceType } from '@/enums/device-type';
|
||||
|
||||
export interface StationDevices {
|
||||
[DeviceType.Camera]: NdmCameraResultVO[];
|
||||
[DeviceType.Decoder]: NdmDecoderResultVO[];
|
||||
[DeviceType.Keyboard]: NdmKeyboardResultVO[];
|
||||
[DeviceType.MediaServer]: NdmMediaServerResultVO[];
|
||||
[DeviceType.Nvr]: NdmNvrResultVO[];
|
||||
[DeviceType.SecurityBox]: NdmSecurityBoxResultVO[];
|
||||
[DeviceType.Switch]: NdmSwitchResultVO[];
|
||||
[DeviceType.VideoServer]: NdmVideoServerResultVO[];
|
||||
}
|
||||
|
||||
export interface LineDevices {
|
||||
[stationCode: string]: StationDevices;
|
||||
}
|
||||
@@ -1,3 +1 @@
|
||||
export * from './domains';
|
||||
|
||||
export * from './use-line-devices-query';
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import type { StationDevices } from './domains';
|
||||
import { ndmClient } from '@/apis/client';
|
||||
import type { Station } from '@/apis/domains';
|
||||
import { ndmClient, type Station, type StationDevices } from '@/apis';
|
||||
import { LINE_DEVICES_QUERY_KEY } from '@/constants';
|
||||
import { DeviceType } from '@/enums/device-type';
|
||||
import { useLineDevicesStore } from '@/stores/line-devices';
|
||||
import { useQueryControlStore } from '@/stores/query-control';
|
||||
import { useStationStore } from '@/stores/station';
|
||||
import { DeviceType } from '@/enums';
|
||||
import { useLineDevicesStore, useQueryControlStore, useStationStore } from '@/stores';
|
||||
import { runTask } from '@/utils';
|
||||
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import { runTask } from '@/utils/run-task';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
|
||||
@@ -41,7 +37,7 @@ export function useLineDevicesQuery() {
|
||||
const { mutateAsync: getStationDevices } = useStationDevicesMutation();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [LINE_DEVICES_QUERY_KEY, deviceQueryStamp],
|
||||
queryKey: computed(() => [LINE_DEVICES_QUERY_KEY, deviceQueryStamp.value]),
|
||||
enabled: computed(() => deviceQueryStamp.value > 0),
|
||||
staleTime: Infinity,
|
||||
refetchOnMount: false,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { Station } from '@/apis/domains';
|
||||
import { batchVerify, ndmVerify } from '@/apis/requests';
|
||||
import { batchVerify, ndmVerify, type Station } from '@/apis';
|
||||
import { STATION_LIST_QUERY_KEY } from '@/constants';
|
||||
import { useQueryControlStore } from '@/stores/query-control';
|
||||
import { useStationStore } from '@/stores/station';
|
||||
import { getAppEnvConfig } from '@/utils/env';
|
||||
import { useQueryControlStore, useStationStore } from '@/stores';
|
||||
import { getAppEnvConfig } from '@/utils';
|
||||
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import axios from 'axios';
|
||||
import dayjs from 'dayjs';
|
||||
@@ -16,7 +14,7 @@ export function useStationListQuery() {
|
||||
const { mutateAsync: getStationList } = useStationListMutation();
|
||||
|
||||
return useQuery({
|
||||
queryKey: [STATION_LIST_QUERY_KEY],
|
||||
queryKey: computed(() => [STATION_LIST_QUERY_KEY]),
|
||||
enabled: computed(() => pollingEnabled.value),
|
||||
refetchInterval: getAppEnvConfig().requestInterval * 1000,
|
||||
staleTime: getAppEnvConfig().requestInterval * 1000,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { VersionInfo } from '@/apis/domains/version-info';
|
||||
import type { VersionInfo } from '@/apis';
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import axios from 'axios';
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
|
||||
61
src/composables/stomp/index.ts
Normal file
61
src/composables/stomp/index.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import type { NdmDeviceAlarmLogResultVO } from '@/apis';
|
||||
import { TOPIC_DEVICE_ALARM } from '@/constants';
|
||||
import { useCurrentAlarmsStore } from '@/stores';
|
||||
import { Client } from '@stomp/stompjs';
|
||||
import { destr } from 'destr';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
|
||||
const getBrokerUrl = () => {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const { host } = window.location;
|
||||
const endpoint = '/ws';
|
||||
const brokerURL = `${protocol}//${host}${endpoint}`;
|
||||
return brokerURL;
|
||||
};
|
||||
|
||||
export const useStompClient = () => {
|
||||
const currentAlarmsStore = useCurrentAlarmsStore();
|
||||
const { currentAlarmCount } = storeToRefs(currentAlarmsStore);
|
||||
const stompClient = ref<Client | null>(null);
|
||||
|
||||
onMounted(() => {
|
||||
stompClient.value = new Client({
|
||||
brokerURL: getBrokerUrl(),
|
||||
reconnectDelay: 5000,
|
||||
heartbeatIncoming: 10000,
|
||||
heartbeatOutgoing: 10000,
|
||||
onConnect: () => {
|
||||
console.log('Stomp连接成功');
|
||||
stompClient.value?.subscribe(TOPIC_DEVICE_ALARM, (message) => {
|
||||
const alarm = destr<NdmDeviceAlarmLogResultVO>(message.body);
|
||||
if (alarm.alarmCategory === '1') {
|
||||
currentAlarmCount.value++;
|
||||
}
|
||||
});
|
||||
},
|
||||
onDisconnect: () => {
|
||||
console.log('Stomp连接断开');
|
||||
stompClient.value?.unsubscribe(TOPIC_DEVICE_ALARM);
|
||||
},
|
||||
onStompError: (frame) => {
|
||||
console.log('Stomp错误', frame);
|
||||
window.$message.error('Stomp错误');
|
||||
},
|
||||
onWebSocketError: (event: Event) => {
|
||||
console.log('WebSocket错误', event);
|
||||
window.$message.error('WebSocket错误');
|
||||
},
|
||||
});
|
||||
stompClient.value.activate();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stompClient.value?.deactivate();
|
||||
stompClient.value = null;
|
||||
});
|
||||
|
||||
return {
|
||||
stompClient,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user