perf: lift UX priority when query running
This commit is contained in:
@@ -11,6 +11,7 @@ import type { StationAlarms } from './domains';
|
||||
import { useLineAlarmsStore } from '@/stores/line-alarms';
|
||||
import { CanceledError } from 'axios';
|
||||
import { LINE_ALARMS_QUERY_KEY } from '@/constants';
|
||||
import { sleep } from '@/utils/sleep';
|
||||
|
||||
export interface LineAlarms {
|
||||
[stationCode: Station['code']]: StationAlarms;
|
||||
@@ -46,7 +47,7 @@ export function useLineAlarmsQuery() {
|
||||
refetchOnReconnect: false,
|
||||
refetchOnWindowFocus: false,
|
||||
queryFn: async ({ signal }): Promise<LineAlarms> => {
|
||||
// console.time('useLineAlarmsQuery');
|
||||
console.time('useLineAlarmsQuery');
|
||||
|
||||
if (!stationList?.value) {
|
||||
lineAlarms.value = {};
|
||||
@@ -62,13 +63,13 @@ export function useLineAlarmsQuery() {
|
||||
if (!lineAlarms.value[station.code]) {
|
||||
lineAlarms.value[station.code] = createEmptyStationAlarms();
|
||||
}
|
||||
// const stationAlarms = lineAlarms.value[station.code];
|
||||
|
||||
const stationAlarms = createEmptyStationAlarms();
|
||||
|
||||
const now = dayjs();
|
||||
const todayStart = now.startOf('date').valueOf();
|
||||
const todayEnd = now.endOf('date').valueOf();
|
||||
try {
|
||||
const now = dayjs();
|
||||
const todayStart = now.startOf('date').valueOf();
|
||||
const todayEnd = now.endOf('date').valueOf();
|
||||
const { records: alarmList } = await postNdmDeviceAlarmLogPage(
|
||||
station.code,
|
||||
{
|
||||
@@ -76,6 +77,7 @@ export function useLineAlarmsQuery() {
|
||||
extra: {
|
||||
alarmDate_ge: todayStart,
|
||||
alarmDate_le: todayEnd,
|
||||
deviceId_likeRight: station.code,
|
||||
},
|
||||
size: 50000,
|
||||
current: 1,
|
||||
@@ -84,25 +86,13 @@ export function useLineAlarmsQuery() {
|
||||
},
|
||||
signal,
|
||||
);
|
||||
const cameraAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Camera);
|
||||
stationAlarms[DeviceType.Camera] = cameraAlarms;
|
||||
const decoderAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Decoder);
|
||||
stationAlarms[DeviceType.Decoder] = decoderAlarms;
|
||||
const keyboardAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Keyboard);
|
||||
stationAlarms[DeviceType.Keyboard] = keyboardAlarms;
|
||||
const mediaServerAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.MediaServer);
|
||||
stationAlarms[DeviceType.MediaServer] = mediaServerAlarms;
|
||||
const nvrAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Nvr);
|
||||
stationAlarms[DeviceType.Nvr] = nvrAlarms;
|
||||
const securityBoxAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.SecurityBox);
|
||||
stationAlarms[DeviceType.SecurityBox] = securityBoxAlarms;
|
||||
const switchAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.Switch);
|
||||
stationAlarms[DeviceType.Switch] = switchAlarms;
|
||||
const videoServerAlarms = alarmList.filter((device) => getDeviceTypeVal(device.deviceType) === DeviceType.VideoServer);
|
||||
stationAlarms[DeviceType.VideoServer] = videoServerAlarms;
|
||||
for (const alarm of alarmList) {
|
||||
const deviceType = getDeviceTypeVal(alarm.deviceType);
|
||||
stationAlarms[deviceType].push(alarm);
|
||||
}
|
||||
stationAlarms.unclassified = alarmList;
|
||||
|
||||
lineAlarms.value[station.code] = stationAlarms;
|
||||
await sleep();
|
||||
} catch (error) {
|
||||
if (error instanceof CanceledError) return lineAlarms.value;
|
||||
console.error(`获取车站 ${station.name} 设备告警数据失败:`, error);
|
||||
@@ -118,7 +108,7 @@ export function useLineAlarmsQuery() {
|
||||
}
|
||||
}
|
||||
|
||||
// console.timeEnd('useLineAlarmsQuery');
|
||||
console.timeEnd('useLineAlarmsQuery');
|
||||
|
||||
return lineAlarms.value;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user