chore
This commit is contained in:
33
src/composables/query/use-station-list-query.ts
Normal file
33
src/composables/query/use-station-list-query.ts
Normal 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;
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user