This commit is contained in:
yangsy
2025-08-14 13:06:22 +08:00
parent a1a73180b4
commit dd317df58a
9 changed files with 267 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import type { Station } from '@/apis/domains';
import { ndmVerify } from '@/apis/requests';
import { useQuery } from '@tanstack/vue-query';
import { useStationStore } from '@/stores/station';
import axios from 'axios';
import dayjs from 'dayjs';
import { storeToRefs } from 'pinia';
export function useStationListQuery() {
const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore);
useQuery({
queryKey: ['station-list'],
queryFn: async () => {
const { data: ndmStationList } = await axios.get<{ code: string; name: string }[]>(`/minio/ndm/ndm-stations.json?_t=${dayjs().unix()}`);
stationList.value = ndmStationList.map<Station>((record) => ({
code: record.code ?? '',
name: record.name ?? '',
online: false,
}));
const pingResultList = await Promise.allSettled(stationList.value.map((station) => ndmVerify(station.code)));
stationList.value = stationList.value.map((station, index) => ({
...station,
online: pingResultList[index].status === 'fulfilled',
}));
return stationList.value;
},
});
}