refactor(stores): simplify stores
This commit is contained in:
@@ -7,9 +7,9 @@ function renderIcon(icon: Component): () => VNode {
|
||||
<script setup lang="ts">
|
||||
import { SettingsDrawer } from '@/components';
|
||||
import { useStompClient } from '@/composables';
|
||||
import { useStationListQuery } from '@/composables';
|
||||
import { STATION_LIST_QUERY_KEY, LINE_DEVICES_QUERY_KEY, LINE_ALARMS_QUERY_KEY } from '@/constants';
|
||||
import { useCurrentAlarmsStore, useUserStore } from '@/stores';
|
||||
import { useLineStationsQuery } from '@/composables';
|
||||
import { LINE_STATIONS_QUERY_KEY, LINE_DEVICES_QUERY_KEY, LINE_ALARMS_QUERY_KEY } from '@/constants';
|
||||
import { useAlarmStore, useUserStore } from '@/stores';
|
||||
import { useIsFetching } from '@tanstack/vue-query';
|
||||
import { AlertFilled, BugFilled, CaretDownFilled, EnvironmentFilled, /* AreaChartOutlined, */ FileTextFilled, FundFilled, HddFilled, LogoutOutlined, SettingOutlined } from '@vicons/antd';
|
||||
import type { AxiosError } from 'axios';
|
||||
@@ -23,10 +23,10 @@ useStompClient();
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
|
||||
const currentAlarmsStore = useCurrentAlarmsStore();
|
||||
const { currentAlarmCount, needReload } = storeToRefs(currentAlarmsStore);
|
||||
const alarmStore = useAlarmStore();
|
||||
const { unreadAlarmCount } = storeToRefs(alarmStore);
|
||||
|
||||
const { error: stationListQueryError } = useStationListQuery();
|
||||
const { error: stationListQueryError } = useLineStationsQuery();
|
||||
|
||||
watch(stationListQueryError, (newStationListQueryError) => {
|
||||
if (newStationListQueryError) {
|
||||
@@ -34,11 +34,11 @@ watch(stationListQueryError, (newStationListQueryError) => {
|
||||
}
|
||||
});
|
||||
|
||||
const stationListFetchingCount = useIsFetching({ queryKey: [STATION_LIST_QUERY_KEY] });
|
||||
const lineStationsFetchingCount = useIsFetching({ queryKey: [LINE_STATIONS_QUERY_KEY] });
|
||||
const lineDevicesFetchingCount = useIsFetching({ queryKey: [LINE_DEVICES_QUERY_KEY] });
|
||||
const lineAlarmsFetchingCount = useIsFetching({ queryKey: [LINE_ALARMS_QUERY_KEY] });
|
||||
const fetchingCount = computed(() => {
|
||||
return stationListFetchingCount.value + lineDevicesFetchingCount.value + lineAlarmsFetchingCount.value;
|
||||
return lineStationsFetchingCount.value + lineDevicesFetchingCount.value + lineAlarmsFetchingCount.value;
|
||||
});
|
||||
|
||||
onBeforeMount(() => {
|
||||
@@ -119,12 +119,13 @@ const selectDropdownOption = (key: string, option: DropdownOption) => {
|
||||
}
|
||||
};
|
||||
|
||||
const toDashboardPage = () => router.push('/');
|
||||
const toAlarmPage = () => {
|
||||
currentAlarmCount.value = 0;
|
||||
if (route.path === '/alarm') {
|
||||
needReload.value = true;
|
||||
} else {
|
||||
const routeToDashboardPage = () => {
|
||||
router.push('/dashboard');
|
||||
};
|
||||
|
||||
const routeToAlarmPage = () => {
|
||||
unreadAlarmCount.value = 0;
|
||||
if (route.path !== '/alarm') {
|
||||
router.push('/alarm');
|
||||
}
|
||||
};
|
||||
@@ -145,7 +146,7 @@ const openSettingsDrawer = () => {
|
||||
<NLayoutHeader bordered class="app-layout-header">
|
||||
<NFlex justify="space-between" align="center" :size="8" style="width: 100%; height: 100%">
|
||||
<NFlex>
|
||||
<div style="font-size: 16px; font-weight: 500; margin-left: 16px; cursor: pointer" @click="toDashboardPage">网络设备管理平台</div>
|
||||
<div style="font-size: 16px; font-weight: 500; margin-left: 16px; cursor: pointer" @click="routeToDashboardPage">网络设备管理平台</div>
|
||||
<NButton text size="tiny" :loading="fetchingCount > 0" />
|
||||
</NFlex>
|
||||
<NFlex align="center" :size="0" style="height: 100%">
|
||||
@@ -173,8 +174,8 @@ const openSettingsDrawer = () => {
|
||||
</NLayoutContent>
|
||||
<NLayoutFooter bordered class="app-layout-footer">
|
||||
<NFlex :align="'center'" style="height: 100%; margin: 0 16px">
|
||||
<NBadge :value="currentAlarmCount">
|
||||
<NButton secondary strong @click="toAlarmPage">
|
||||
<NBadge :value="unreadAlarmCount">
|
||||
<NButton secondary strong @click="routeToAlarmPage">
|
||||
<template #icon>
|
||||
<NIcon :component="AlertFilled" />
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user