refactor: add store to save data from queries progressively

This commit is contained in:
yangsy
2025-08-26 03:27:06 +08:00
parent 55e9efce7e
commit c2ebe34a05
8 changed files with 141 additions and 54 deletions

View File

@@ -3,7 +3,7 @@ import { ndmVerify } from '@/apis/requests';
import { useQueryControlStore } from '@/stores/query-control';
import { useStationStore } from '@/stores/station';
import { getAppEnvConfig } from '@/utils/env';
import { useQuery } from '@tanstack/vue-query';
import { useQuery, useQueryClient } from '@tanstack/vue-query';
import axios from 'axios';
import dayjs from 'dayjs';
import { storeToRefs } from 'pinia';
@@ -11,7 +11,7 @@ import { computed } from 'vue';
export function useStationListQuery() {
const stationStore = useStationStore();
const { updatedTime, stationList } = storeToRefs(stationStore);
const { stationList } = storeToRefs(stationStore);
const queryControlStore = useQueryControlStore();
const { pollingEnabled } = storeToRefs(queryControlStore);
@@ -45,7 +45,11 @@ export function useStationListQuery() {
stationList.value.splice(0, stationList.value.length, ...stations);
}
updatedTime.value = dayjs().toJSON();
const queryClient = useQueryClient();
queryClient.invalidateQueries({ queryKey: ['station-devices'] });
queryClient.invalidateQueries({ queryKey: ['station-alarms'] });
// queryClient.invalidateQueries({ queryKey: ['line-devices'] });
// queryClient.invalidateQueries({ queryKey: ['line-alarms'] });
return stations;
},