Files
ndm-web-platform/src/stores/polling.ts
T
yangsy 37781216b2 refactor: 重构项目结构
- 优化 `车站-设备-告警`  轮询机制
- 改进设备卡片的布局
- 支持修改设备
- 告警轮询中获取完整告警数据
- 车站告警详情支持导出完整的 `今日告警列表`
- 支持将状态持久化到 `IndexedDB`
- 新增轮询控制 (调试模式)
- 新增离线开发模式 (调试模式)
- 新增 `IndexedDB` 数据控制 (调试模式)
2025-12-11 13:42:22 +08:00

36 lines
1.1 KiB
TypeScript

import { LINE_ALARMS_QUERY_KEY, LINE_DEVICES_QUERY_KEY, LINE_STATIONS_QUERY_KEY, NDM_POLLIING_STORE_ID } from '@/constants';
import { useQueryClient } from '@tanstack/vue-query';
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const usePollingStore = defineStore(
NDM_POLLIING_STORE_ID,
() => {
const queryClient = useQueryClient();
// 允许控制轮询
const pollingEnabled = ref(true);
const startPolling = () => {
pollingEnabled.value = true;
};
const stopPolling = () => {
pollingEnabled.value = false;
queryClient.cancelQueries({ queryKey: [LINE_STATIONS_QUERY_KEY] });
queryClient.cancelQueries({ queryKey: [LINE_DEVICES_QUERY_KEY] });
queryClient.cancelQueries({ queryKey: [LINE_ALARMS_QUERY_KEY] });
queryClient.invalidateQueries({ queryKey: [LINE_STATIONS_QUERY_KEY] });
queryClient.invalidateQueries({ queryKey: [LINE_DEVICES_QUERY_KEY] });
queryClient.invalidateQueries({ queryKey: [LINE_ALARMS_QUERY_KEY] });
};
return {
pollingEnabled,
startPolling,
stopPolling,
};
},
{
persist: true,
},
);