refactor(stores): simplify stores
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export * from './use-line-alarms-query';
|
||||
@@ -1 +0,0 @@
|
||||
export * from './use-line-devices-query';
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './alarm';
|
||||
export * from './device';
|
||||
export * from './station';
|
||||
export * from './system';
|
||||
export * from './use-line-alarms-query';
|
||||
export * from './use-line-devices-query';
|
||||
export * from './use-station-list-query';
|
||||
export * from './use-version-check-query';
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from './use-station-list-query';
|
||||
@@ -1 +0,0 @@
|
||||
export * from './use-version-check-query';
|
||||
@@ -1,7 +1,7 @@
|
||||
import { pageDeviceAlarmLogApi, type Station, type StationAlarmCounts } from '@/apis';
|
||||
import { LINE_ALARMS_QUERY_KEY } from '@/constants';
|
||||
import { DeviceType, tryGetDeviceTypeVal } from '@/enums';
|
||||
import { useLineAlarmsStore, useQueryControlStore, useStationStore } from '@/stores';
|
||||
import { useAlarmStore, usePollingStore, useStationStore } from '@/stores';
|
||||
import { runTask } from '@/utils';
|
||||
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import dayjs from 'dayjs';
|
||||
@@ -25,8 +25,8 @@ const createEmptyStationAlarmCounts = () => {
|
||||
export function useLineAlarmsQuery() {
|
||||
const stationStore = useStationStore();
|
||||
const { stationList } = storeToRefs(stationStore);
|
||||
const queryControlStore = useQueryControlStore();
|
||||
const { alarmQueryStamp } = storeToRefs(queryControlStore);
|
||||
const pollingStore = usePollingStore();
|
||||
const { alarmQueryStamp } = storeToRefs(pollingStore);
|
||||
const { mutateAsync: getStationAlarmCounts } = useStationAlarmCountsMutation();
|
||||
|
||||
return useQuery({
|
||||
@@ -42,7 +42,7 @@ export function useLineAlarmsQuery() {
|
||||
await getStationAlarmCounts({ station, signal });
|
||||
}
|
||||
console.timeEnd('useLineALarmCountsQuery');
|
||||
// queryControlStore.updateAlarmQueryUpdatedAt();
|
||||
// pollingStore.updateAlarmQueryUpdatedAt();
|
||||
return null;
|
||||
},
|
||||
});
|
||||
@@ -54,7 +54,7 @@ interface StationAlarmCountsMutationParams {
|
||||
}
|
||||
|
||||
function useStationAlarmCountsMutation() {
|
||||
const lineAlarmsStore = useLineAlarmsStore();
|
||||
const lineAlarmsStore = useAlarmStore();
|
||||
const { lineAlarmCounts } = storeToRefs(lineAlarmsStore);
|
||||
|
||||
return useMutation<StationAlarmCounts, Error, StationAlarmCountsMutationParams>({
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ndmClient, type Station, type StationDevices } from '@/apis';
|
||||
import { LINE_DEVICES_QUERY_KEY } from '@/constants';
|
||||
import { DeviceType } from '@/enums';
|
||||
import { useLineDevicesStore, useQueryControlStore, useStationStore } from '@/stores';
|
||||
import { useDeviceStore, usePollingStore, useStationStore } from '@/stores';
|
||||
import { runTask } from '@/utils';
|
||||
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import { storeToRefs } from 'pinia';
|
||||
@@ -32,8 +32,8 @@ const getNdmDevicesAll = async (stationCode: string, signal?: AbortSignal) => {
|
||||
export function useLineDevicesQuery() {
|
||||
const stationStore = useStationStore();
|
||||
const { stationList } = storeToRefs(stationStore);
|
||||
const queryControlStore = useQueryControlStore();
|
||||
const { deviceQueryStamp } = storeToRefs(queryControlStore);
|
||||
const pollingStore = usePollingStore();
|
||||
const { deviceQueryStamp } = storeToRefs(pollingStore);
|
||||
const { mutateAsync: getStationDevices } = useStationDevicesMutation();
|
||||
|
||||
return useQuery({
|
||||
@@ -49,7 +49,7 @@ export function useLineDevicesQuery() {
|
||||
await getStationDevices({ station, signal });
|
||||
}
|
||||
console.timeEnd('useLineDevicesQuery');
|
||||
// queryControlStore.updateDeviceQueryUpdatedAt();
|
||||
// pollingStore.updateDeviceQueryUpdatedAt();
|
||||
return null;
|
||||
},
|
||||
});
|
||||
@@ -61,7 +61,7 @@ interface StationDevicesMutationParams {
|
||||
}
|
||||
|
||||
function useStationDevicesMutation() {
|
||||
const lineDevicesStore = useLineDevicesStore();
|
||||
const lineDevicesStore = useDeviceStore();
|
||||
const { lineDevices } = storeToRefs(lineDevicesStore);
|
||||
|
||||
return useMutation<StationDevices, Error, StationDevicesMutationParams>({
|
||||
@@ -1,6 +1,6 @@
|
||||
import { batchVerifyApi, verifyApi, type Station } from '@/apis';
|
||||
import { STATION_LIST_QUERY_KEY } from '@/constants';
|
||||
import { useQueryControlStore, useStationStore } from '@/stores';
|
||||
import { LINE_STATIONS_QUERY_KEY } from '@/constants';
|
||||
import { usePollingStore, useStationStore } from '@/stores';
|
||||
import { getAppEnvConfig } from '@/utils';
|
||||
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
|
||||
import axios from 'axios';
|
||||
@@ -8,13 +8,13 @@ import dayjs from 'dayjs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export function useStationListQuery() {
|
||||
const queryControlStore = useQueryControlStore();
|
||||
const { pollingEnabled } = storeToRefs(queryControlStore);
|
||||
const { mutateAsync: getStationList } = useStationListMutation();
|
||||
export function useLineStationsQuery() {
|
||||
const pollingStore = usePollingStore();
|
||||
const { pollingEnabled } = storeToRefs(pollingStore);
|
||||
const { mutateAsync: getStationList } = useLineStationsMutation();
|
||||
|
||||
return useQuery({
|
||||
queryKey: computed(() => [STATION_LIST_QUERY_KEY]),
|
||||
queryKey: computed(() => [LINE_STATIONS_QUERY_KEY]),
|
||||
enabled: computed(() => pollingEnabled.value),
|
||||
refetchInterval: getAppEnvConfig().requestInterval * 1000,
|
||||
staleTime: getAppEnvConfig().requestInterval * 1000,
|
||||
@@ -22,8 +22,8 @@ export function useStationListQuery() {
|
||||
console.time('useStationListQuery');
|
||||
await getStationList({ signal });
|
||||
console.timeEnd('useStationListQuery');
|
||||
queryControlStore.updateDeviceQueryStamp();
|
||||
queryControlStore.updateAlarmQueryStamp();
|
||||
pollingStore.updateDeviceQueryStamp();
|
||||
pollingStore.updateAlarmQueryStamp();
|
||||
return null;
|
||||
},
|
||||
});
|
||||
@@ -33,11 +33,11 @@ interface StationListMutationParams {
|
||||
signal?: AbortSignal;
|
||||
}
|
||||
|
||||
function useStationListMutation() {
|
||||
function useLineStationsMutation() {
|
||||
const stationStore = useStationStore();
|
||||
const { stationList } = storeToRefs(stationStore);
|
||||
const queryControlStore = useQueryControlStore();
|
||||
const { stationVerifyMode } = storeToRefs(queryControlStore);
|
||||
const pollingStore = usePollingStore();
|
||||
const { stationVerifyMode } = storeToRefs(pollingStore);
|
||||
return useMutation<Station[], Error, StationListMutationParams>({
|
||||
mutationFn: async ({ signal }) => {
|
||||
const { data: ndmStationList } = await axios.get<{ code: string; name: string }[]>(`/minio/ndm/ndm-stations.json?_t=${dayjs().unix()}`, { signal });
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { NdmDeviceAlarmLogResultVO } from '@/apis';
|
||||
import { TOPIC_DEVICE_ALARM } from '@/constants';
|
||||
import { useCurrentAlarmsStore } from '@/stores';
|
||||
import { useAlarmStore } from '@/stores';
|
||||
import { Client } from '@stomp/stompjs';
|
||||
import { destr } from 'destr';
|
||||
import { storeToRefs } from 'pinia';
|
||||
@@ -15,8 +15,8 @@ const getBrokerUrl = () => {
|
||||
};
|
||||
|
||||
export const useStompClient = () => {
|
||||
const currentAlarmsStore = useCurrentAlarmsStore();
|
||||
const { currentAlarmCount } = storeToRefs(currentAlarmsStore);
|
||||
const alarmStore = useAlarmStore();
|
||||
const { unreadAlarmCount } = storeToRefs(alarmStore);
|
||||
const stompClient = ref<Client | null>(null);
|
||||
|
||||
onMounted(() => {
|
||||
@@ -30,7 +30,7 @@ export const useStompClient = () => {
|
||||
stompClient.value?.subscribe(TOPIC_DEVICE_ALARM, (message) => {
|
||||
const alarm = destr<NdmDeviceAlarmLogResultVO>(message.body);
|
||||
if (alarm.alarmCategory === '1') {
|
||||
currentAlarmCount.value++;
|
||||
unreadAlarmCount.value++;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user