refactor: 重构项目结构

- 优化 `车站-设备-告警`  轮询机制
- 改进设备卡片的布局
- 支持修改设备
- 告警轮询中获取完整告警数据
- 车站告警详情支持导出完整的 `今日告警列表`
- 支持将状态持久化到 `IndexedDB`
- 新增轮询控制 (调试模式)
- 新增离线开发模式 (调试模式)
- 新增 `IndexedDB` 数据控制 (调试模式)
This commit is contained in:
yangsy
2025-12-11 13:42:22 +08:00
commit 37781216b2
278 changed files with 17988 additions and 0 deletions
@@ -0,0 +1,73 @@
import { batchVerifyApi, type Station } from '@/apis';
import { LINE_STATIONS_MUTATION_KEY, LINE_STATIONS_QUERY_KEY } from '@/constants';
import { usePollingStore, useStationStore } from '@/stores';
import { getAppEnvConfig, parseErrorFeedback } from '@/utils';
import { CancelledError, useMutation, useQuery } from '@tanstack/vue-query';
import axios, { isCancel } from 'axios';
import dayjs from 'dayjs';
import { storeToRefs } from 'pinia';
import { computed } from 'vue';
import { useLineDevicesQuery } from './use-line-devices-query';
import { useLineAlarmsQuery } from './use-line-alarms-query';
export const useLineStationsMutation = () => {
const stationStore = useStationStore();
return useMutation({
mutationKey: [LINE_STATIONS_MUTATION_KEY],
mutationFn: async (params: { signal?: AbortSignal }) => {
const { signal } = params;
const { data: ndmStationList } = await axios.get<{ code: string; name: string }[]>(`/minio/ndm/ndm-stations.json?_t=${dayjs().unix()}`, { signal });
const stations = ndmStationList.map<Station>((station) => ({
code: station.code ?? '',
name: station.name ?? '',
online: false,
ip: '',
}));
const verifyList = await batchVerifyApi({ signal });
return stations.map((station) => ({
...station,
online: !!verifyList.find((verify) => verify.stationCode === station.code)?.onlineState,
ip: verifyList.find((verify) => verify.stationCode === station.code)?.ipAddress ?? '',
}));
},
onSuccess: (stations) => {
stationStore.setStations(stations);
},
onError: (error) => {
console.error(error);
if (isCancel(error) || error instanceof CancelledError) return;
const errorFeedback = parseErrorFeedback(error);
window.$message.error(errorFeedback);
},
});
};
export const useLineStationsQuery = () => {
const pollingStore = usePollingStore();
const { pollingEnabled } = storeToRefs(pollingStore);
const { requestInterval } = getAppEnvConfig();
const { mutateAsync: getLineStations } = useLineStationsMutation();
const { refetch: refetchLineDevicesQuery } = useLineDevicesQuery();
const { refetch: refetchLineAlarmsQuery } = useLineAlarmsQuery();
return useQuery({
queryKey: computed(() => [LINE_STATIONS_QUERY_KEY]),
enabled: computed(() => pollingEnabled.value),
refetchInterval: requestInterval * 1000,
staleTime: (requestInterval * 1000) / 2,
queryFn: async ({ signal }) => {
console.time(LINE_STATIONS_QUERY_KEY);
await getLineStations({ signal }).catch(() => {});
console.timeEnd(LINE_STATIONS_QUERY_KEY);
if (!pollingEnabled.value) return null;
await refetchLineDevicesQuery();
if (!pollingEnabled.value) return null;
await refetchLineAlarmsQuery();
return null;
},
});
};