- 优化 `车站-设备-告警` 轮询机制 - 改进设备卡片的布局 - 支持修改设备 - 告警轮询中获取完整告警数据 - 车站告警详情支持导出完整的 `今日告警列表` - 支持将状态持久化到 `IndexedDB` - 新增轮询控制 (调试模式) - 新增离线开发模式 (调试模式) - 新增 `IndexedDB` 数据控制 (调试模式)
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import { initStationAlarms, type LineAlarms, type NdmDeviceAlarmLogResultVO, type Station, type StationAlarms } from '@/apis';
|
|
import { NDM_ALARM_STORE_ID } from '@/constants';
|
|
import { tryGetDeviceType } from '@/enums';
|
|
import { defineStore } from 'pinia';
|
|
import { computed, shallowRef, triggerRef } from 'vue';
|
|
|
|
export const useAlarmStore = defineStore(
|
|
NDM_ALARM_STORE_ID,
|
|
() => {
|
|
// 全线所有车站的告警
|
|
const lineAlarms = shallowRef<LineAlarms>({}); // 数据量很大所以用shallowRef配合triggerRef优化性能
|
|
const setLineAlarms = (alarms: LineAlarms) => {
|
|
lineAlarms.value = alarms;
|
|
triggerRef(lineAlarms);
|
|
};
|
|
const setStationAlarms = (stationCode: Station['code'], alarms: StationAlarms) => {
|
|
lineAlarms.value[stationCode] = alarms;
|
|
triggerRef(lineAlarms);
|
|
};
|
|
|
|
// 全线所有车站的未读告警 (来自stomp订阅)
|
|
const unreadLineAlarms = shallowRef<LineAlarms>({});
|
|
const unreadAlarmCount = computed(() => {
|
|
let count = 0;
|
|
Object.values(unreadLineAlarms.value).forEach((stationAlarms) => {
|
|
count += stationAlarms['unclassified'].length;
|
|
});
|
|
return count;
|
|
});
|
|
const pushUnreadAlarm = (alarm: NdmDeviceAlarmLogResultVO) => {
|
|
const stationCode = alarm.stationCode;
|
|
if (!stationCode) return;
|
|
if (!unreadLineAlarms.value[stationCode]) {
|
|
unreadLineAlarms.value[stationCode] = initStationAlarms();
|
|
}
|
|
const deviceType = tryGetDeviceType(alarm.deviceType);
|
|
if (!deviceType) return;
|
|
const stationAlarms = unreadLineAlarms.value[stationCode];
|
|
stationAlarms[deviceType].push(alarm);
|
|
stationAlarms['unclassified'].push(alarm);
|
|
triggerRef(unreadLineAlarms);
|
|
};
|
|
const clearUnreadAlarms = () => {
|
|
unreadLineAlarms.value = {};
|
|
triggerRef(unreadLineAlarms);
|
|
};
|
|
|
|
return {
|
|
lineAlarms,
|
|
setLineAlarms,
|
|
setStationAlarms,
|
|
|
|
unreadLineAlarms,
|
|
unreadAlarmCount,
|
|
pushUnreadAlarm,
|
|
clearUnreadAlarms,
|
|
};
|
|
},
|
|
{
|
|
persistToIndexedDB: true,
|
|
},
|
|
);
|