feat: stationVerifyMode

This commit is contained in:
yangsy
2025-10-10 15:54:28 +08:00
parent ccdcbfd103
commit 3c69887308
3 changed files with 83 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
import type { Station } from '@/apis/domains';
import { batchVerify } from '@/apis/requests';
import { batchVerify, ndmVerify } from '@/apis/requests';
import { STATION_LIST_QUERY_KEY } from '@/constants';
import { useQueryControlStore } from '@/stores/query-control';
import { useStationStore } from '@/stores/station';
@@ -38,6 +38,8 @@ interface StationListMutationParams {
function useStationListMutation() {
const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore);
const queryControlStore = useQueryControlStore();
const { stationVerifyMode } = storeToRefs(queryControlStore);
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 });
@@ -46,13 +48,23 @@ function useStationListMutation() {
name: station.name ?? '',
online: false,
}));
const verifyList = await batchVerify(signal);
return stations.map((station) => {
return {
...station,
online: !!verifyList.find((stn) => stn.stationCode === station.code)?.onlineState,
};
});
if (stationVerifyMode.value === 'concurrent') {
// 方案一并发ping所有station
const stationPingResultList = await Promise.allSettled(stations.map((station) => ndmVerify(station.code, signal)));
stationPingResultList.forEach((pingResult, index) => {
stations[index].online = pingResult.status === 'fulfilled';
});
return stations;
} else {
// 方案二调用批量verify接口
const verifyList = await batchVerify(signal);
return stations.map((station) => {
return {
...station,
online: !!verifyList.find((stn) => stn.stationCode === station.code)?.onlineState,
};
});
}
},
onSuccess: (stations) => {
const isSame = JSON.stringify(stationList.value) === JSON.stringify(stations);