refactor(stores): simplify stores

This commit is contained in:
yangsy
2025-11-25 16:51:20 +08:00
parent 2dd599d2eb
commit 5e464f6e80
39 changed files with 195 additions and 212 deletions

View File

@@ -2,7 +2,7 @@
import { getCameraSnapApi, exportDeviceAlarmLogApi, pageDeviceAlarmLogApi, updateDeviceAlarmLogApi, type NdmDeviceAlarmLogResultVO } from '@/apis';
import { renderAlarmDateCell, renderAlarmTypeCell, renderDeviceTypeCell, renderFaultLevelCell } from '@/components';
import { AlarmType, DeviceType, DeviceTypeCode, DeviceTypeName, FaultLevel, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums';
import { useCurrentAlarmsStore, useStationStore } from '@/stores';
import { useAlarmStore, useStationStore } from '@/stores';
import { downloadByData } from '@/utils';
import { useMutation } from '@tanstack/vue-query';
import dayjs from 'dayjs';
@@ -29,11 +29,14 @@ import {
import { storeToRefs } from 'pinia';
import { ref, reactive, onBeforeMount, h, computed, watch } from 'vue';
const currentAlarmsStore = useCurrentAlarmsStore();
const { needReload } = storeToRefs(currentAlarmsStore);
watch(needReload, async (newVal) => {
if (newVal) {
needReload.value = false;
const alarmStore = useAlarmStore();
const { unreadAlarmCount } = storeToRefs(alarmStore);
const unreadCountCleared = computed(() => unreadAlarmCount.value === 0);
// 未读告警数量被清零时,代表需要刷新告警表格数据
watch(unreadCountCleared, (newValue, oldValue) => {
if (!oldValue && newValue) {
onClickReset();
}
});

View File

@@ -2,7 +2,7 @@
import { exportIcmpApi } from '@/apis';
import { DeviceStatisticCard } from '@/components';
import { useLineAlarmsQuery, useLineDevicesQuery } from '@/composables';
import { useLineDevicesStore, useStationStore } from '@/stores';
import { useDeviceStore, useStationStore } from '@/stores';
import { downloadByData } from '@/utils';
import { useMutation } from '@tanstack/vue-query';
import dayjs from 'dayjs';
@@ -11,7 +11,7 @@ import { watch } from 'vue';
const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore);
const lineDevicesStore = useLineDevicesStore();
const lineDevicesStore = useDeviceStore();
const { lineDevices } = storeToRefs(lineDevicesStore);
const { error: lineDevicesQueryError } = useLineDevicesQuery();

View File

@@ -1,12 +1,12 @@
<script setup lang="ts">
import { useQueryControlStore } from '@/stores';
import { usePollingStore } from '@/stores';
import { NLayout, NLayoutContent } from 'naive-ui';
import { onBeforeUnmount } from 'vue';
const queryControlStore = useQueryControlStore();
queryControlStore.disablePolling();
const pollingStore = usePollingStore();
pollingStore.disablePolling();
onBeforeUnmount(() => {
queryControlStore.enablePolling();
pollingStore.enablePolling();
});
</script>

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import { DeviceRenderer, DeviceTree } from '@/components';
import { useDeviceSelection, useLineDevicesQuery } from '@/composables';
import { useLineDevicesStore, useStationStore } from '@/stores';
import { useDeviceStore, useStationStore } from '@/stores';
import { ChevronBack } from '@vicons/ionicons5';
import { watchDebounced } from '@vueuse/core';
import { NEmpty, NIcon, NLayout, NLayoutContent, NLayoutSider, NPageHeader, NScrollbar } from 'naive-ui';
@@ -13,7 +13,7 @@ import { useRoute, useRouter } from 'vue-router';
const { error: lineDevicesQueryError } = useLineDevicesQuery();
const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore);
const lineDevicesStore = useLineDevicesStore();
const lineDevicesStore = useDeviceStore();
const { lineDevices } = storeToRefs(lineDevicesStore);
const route = useRoute();

View File

@@ -2,22 +2,22 @@
import type { Station } from '@/apis';
import { DeviceAlarmDetailModal, DeviceParamsConfigModal, OfflineDeviceDetailModal, StationCard } from '@/components';
import { useLineAlarmsQuery, useLineDevicesQuery } from '@/composables';
import { useLayoutStore, useLineAlarmsStore, useLineDevicesStore, useStationStore } from '@/stores';
import { useAlarmStore, useDeviceStore, useSettingStore, useStationStore } from '@/stores';
import { NGrid, NGi } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { ref, watch } from 'vue';
const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore);
const lineDevicesStore = useLineDevicesStore();
const { lineDevices } = storeToRefs(lineDevicesStore);
const lineAlarmsStore = useLineAlarmsStore();
const { lineAlarmCounts } = storeToRefs(lineAlarmsStore);
const deviceStore = useDeviceStore();
const { lineDevices } = storeToRefs(deviceStore);
const alarmStore = useAlarmStore();
const { lineAlarmCounts } = storeToRefs(alarmStore);
const { error: lineDevicesQueryError } = useLineDevicesQuery();
const { error: lineAlarmsQueryError } = useLineAlarmsQuery();
const layoutStore = useLayoutStore();
const { stationGridColumns } = storeToRefs(layoutStore);
const settingStore = useSettingStore();
const { stationGridColumns } = storeToRefs(settingStore);
watch([lineDevicesQueryError, lineAlarmsQueryError], ([newLineDevicesQueryError, newLineAlarmsQueryError]) => {
if (newLineDevicesQueryError) {