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

2
.env
View File

@@ -16,7 +16,7 @@ VITE_LAMP_PASSWORD = fjoc(1KHP(Ls&Bje)C
VITE_LAMP_AUTHORIZATION = Y3VlZGVzX2FkbWluOmN1ZWRlc19hZG1pbl9zZWNyZXQ= VITE_LAMP_AUTHORIZATION = Y3VlZGVzX2FkbWluOmN1ZWRlc19hZG1pbl9zZWNyZXQ=
# 当需要重置localStorage时, 修改此变量 # 当需要重置localStorage时, 修改此变量
VITE_STORAGE_VERSION = 1 VITE_STORAGE_VERSION = 2
# 调试授权码 # 调试授权码
VITE_DEBUG_CODE = ndm_debug VITE_DEBUG_CODE = ndm_debug

View File

@@ -13,13 +13,13 @@ const GlobalFeedback = defineComponent({
<script setup lang="ts"> <script setup lang="ts">
import { dateZhCN, NConfigProvider, NDialogProvider, NLoadingBarProvider, NMessageProvider, NNotificationProvider, useDialog, useLoadingBar, useMessage, useNotification, zhCN } from 'naive-ui'; import { dateZhCN, NConfigProvider, NDialogProvider, NLoadingBarProvider, NMessageProvider, NNotificationProvider, useDialog, useLoadingBar, useMessage, useNotification, zhCN } from 'naive-ui';
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { useThemeStore } from '@/stores/theme'; import { useSettingStore } from '@/stores';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { VueQueryDevtools } from '@tanstack/vue-query-devtools'; import { VueQueryDevtools } from '@tanstack/vue-query-devtools';
import { useVersionCheckQuery } from './composables/query'; import { useVersionCheckQuery } from './composables/query';
const themeStore = useThemeStore(); const settingStore = useSettingStore();
const { themeMode } = storeToRefs(themeStore); const { themeMode } = storeToRefs(settingStore);
useVersionCheckQuery(); useVersionCheckQuery();
</script> </script>

View File

@@ -1,18 +1,19 @@
<script setup lang="ts"> <script setup lang="ts">
import type { NdmCameraDiagInfo, NdmCameraResultVO } from '@/apis'; import type { NdmCameraDiagInfo, NdmCameraResultVO } from '@/apis';
import { useDebugModeStore } from '@/stores'; import { CameraHistoryDiagCard, DeviceCommonCard, DeviceHeaderCard } from '@/components';
import destr from 'destr'; import { useSettingStore } from '@/stores';
import { destr } from 'destr';
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui'; import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
import { computed, ref, toRefs } from 'vue'; import { computed, ref, toRefs } from 'vue';
import { DeviceCommonCard, DeviceHeaderCard } from './current-diag-card'; import { storeToRefs } from 'pinia';
import { CameraHistoryDiagCard } from './history-diag-card';
const props = defineProps<{ const props = defineProps<{
stationCode: string; stationCode: string;
ndmCamera: NdmCameraResultVO; ndmCamera: NdmCameraResultVO;
}>(); }>();
const debugModeStore = useDebugModeStore(); const settingStore = useSettingStore();
const { debugModeEnabled } = storeToRefs(settingStore);
const { stationCode, ndmCamera } = toRefs(props); const { stationCode, ndmCamera } = toRefs(props);
@@ -74,7 +75,7 @@ const selectedTab = ref('设备状态');
<CameraHistoryDiagCard :station-code="stationCode" :ndm-camera="ndmCamera" :key="ndmCamera.id" /> <CameraHistoryDiagCard :station-code="stationCode" :ndm-camera="ndmCamera" :key="ndmCamera.id" />
</NTabPane> </NTabPane>
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> --> <!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
<NTabPane v-if="debugModeStore.debugEnabled" name="原始数据" tab="原始数据"> <NTabPane v-if="debugModeEnabled" name="原始数据" tab="原始数据">
<pre class="raw-data">{{ { ...ndmCamera, lastDiagInfo } }}</pre> <pre class="raw-data">{{ { ...ndmCamera, lastDiagInfo } }}</pre>
</NTabPane> </NTabPane>
</NTabs> </NTabs>

View File

@@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { detailDeviceApi, probeDeviceApi, type NdmDeviceResultVO } from '@/apis'; import { detailDeviceApi, probeDeviceApi, type NdmDeviceResultVO } from '@/apis';
import { DeviceType, DeviceTypeName, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums'; import { DeviceType, DeviceTypeName, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums';
import { useLineDevicesStore } from '@/stores'; import { useDeviceStore } from '@/stores';
import { useMutation } from '@tanstack/vue-query'; import { useMutation } from '@tanstack/vue-query';
import { ApiOutlined, ReloadOutlined } from '@vicons/antd'; import { ApiOutlined, ReloadOutlined } from '@vicons/antd';
import { NButton, NCard, NFlex, NIcon, NTag, NTooltip } from 'naive-ui'; import { NButton, NCard, NFlex, NIcon, NTag, NTooltip } from 'naive-ui';
@@ -62,7 +62,7 @@ const { mutate: getDeviceDetail, isPending: loading } = useMutation({
}, },
onSuccess: (device) => { onSuccess: (device) => {
if (device) { if (device) {
useLineDevicesStore().patch(stationCode.value, device); useDeviceStore().patch(stationCode.value, device);
} }
}, },
onError: (error) => { onError: (error) => {

View File

@@ -1,9 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import type { NdmDecoderDiagInfo, NdmDecoderResultVO } from '@/apis'; import type { NdmDecoderDiagInfo, NdmDecoderResultVO } from '@/apis';
import { DecoderHistoryDiagCard, DeviceCommonCard, DeviceHardwareCard, DeviceHeaderCard } from '@/components'; import { DecoderHistoryDiagCard, DeviceCommonCard, DeviceHardwareCard, DeviceHeaderCard } from '@/components';
import { useDebugModeStore } from '@/stores'; import { useSettingStore } from '@/stores';
import { destr } from 'destr'; import { destr } from 'destr';
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui'; import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { computed, ref, toRefs } from 'vue'; import { computed, ref, toRefs } from 'vue';
const props = defineProps<{ const props = defineProps<{
@@ -11,7 +12,8 @@ const props = defineProps<{
ndmDecoder: NdmDecoderResultVO; ndmDecoder: NdmDecoderResultVO;
}>(); }>();
const debugModeStore = useDebugModeStore(); const settingStore = useSettingStore();
const { debugModeEnabled } = storeToRefs(settingStore);
const { stationCode, ndmDecoder } = toRefs(props); const { stationCode, ndmDecoder } = toRefs(props);
@@ -53,7 +55,7 @@ const selectedTab = ref('设备状态');
<DecoderHistoryDiagCard :station-code="stationCode" :ndm-decoder="ndmDecoder" :key="ndmDecoder.id" /> <DecoderHistoryDiagCard :station-code="stationCode" :ndm-decoder="ndmDecoder" :key="ndmDecoder.id" />
</NTabPane> </NTabPane>
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> --> <!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
<NTabPane v-if="debugModeStore.debugEnabled" name="原始数据" tab="原始数据"> <NTabPane v-if="debugModeEnabled" name="原始数据" tab="原始数据">
<pre class="raw-data">{{ { ...ndmDecoder, lastDiagInfo } }}</pre> <pre class="raw-data">{{ { ...ndmDecoder, lastDiagInfo } }}</pre>
</NTabPane> </NTabPane>
</NTabs> </NTabs>

View File

@@ -1,8 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import type { NdmKeyboardResultVO } from '@/apis'; import type { NdmKeyboardResultVO } from '@/apis';
import { DeviceHeaderCard, KeyboardHistoryDiagCard } from '@/components'; import { DeviceHeaderCard, KeyboardHistoryDiagCard } from '@/components';
import { useDebugModeStore } from '@/stores'; import { useSettingStore } from '@/stores';
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui'; import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { ref, toRefs } from 'vue'; import { ref, toRefs } from 'vue';
const props = defineProps<{ const props = defineProps<{
@@ -10,7 +11,8 @@ const props = defineProps<{
ndmKeyboard: NdmKeyboardResultVO; ndmKeyboard: NdmKeyboardResultVO;
}>(); }>();
const debugModeStore = useDebugModeStore(); const settingStore = useSettingStore();
const { debugModeEnabled } = storeToRefs(settingStore);
const { stationCode, ndmKeyboard } = toRefs(props); const { stationCode, ndmKeyboard } = toRefs(props);
@@ -30,7 +32,7 @@ const selectedTab = ref('设备状态');
<KeyboardHistoryDiagCard :station-code="stationCode" :ndm-keyboard="ndmKeyboard" :key="ndmKeyboard.id" /> <KeyboardHistoryDiagCard :station-code="stationCode" :ndm-keyboard="ndmKeyboard" :key="ndmKeyboard.id" />
</NTabPane> </NTabPane>
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> --> <!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
<NTabPane v-if="debugModeStore.debugEnabled" name="原始数据" tab="原始数据"> <NTabPane v-if="debugModeEnabled" name="原始数据" tab="原始数据">
<pre class="raw-data">{{ { ...ndmKeyboard } }}</pre> <pre class="raw-data">{{ { ...ndmKeyboard } }}</pre>
</NTabPane> </NTabPane>
</NTabs> </NTabs>

View File

@@ -1,9 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import type { NdmNvrDiagInfo, NdmNvrResultVO } from '@/apis'; import type { NdmNvrDiagInfo, NdmNvrResultVO } from '@/apis';
import { DeviceCommonCard, DeviceHardwareCard, DeviceHeaderCard, isNvrCluster, NvrDiskCard, NvrHistoryDiagCard, NvrRecordDiagCard } from '@/components'; import { DeviceCommonCard, DeviceHardwareCard, DeviceHeaderCard, isNvrCluster, NvrDiskCard, NvrHistoryDiagCard, NvrRecordDiagCard } from '@/components';
import { useDebugModeStore } from '@/stores'; import { useSettingStore } from '@/stores';
import { destr } from 'destr'; import { destr } from 'destr';
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui'; import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { computed, ref, toRefs } from 'vue'; import { computed, ref, toRefs } from 'vue';
const props = defineProps<{ const props = defineProps<{
@@ -11,7 +12,8 @@ const props = defineProps<{
ndmNvr: NdmNvrResultVO; ndmNvr: NdmNvrResultVO;
}>(); }>();
const debugModeStore = useDebugModeStore(); const settingStore = useSettingStore();
const { debugModeEnabled } = storeToRefs(settingStore);
const { stationCode, ndmNvr } = toRefs(props); const { stationCode, ndmNvr } = toRefs(props);
@@ -63,7 +65,7 @@ const selectedTab = ref('设备状态');
<NvrHistoryDiagCard :station-code="stationCode" :ndm-nvr="ndmNvr" :key="ndmNvr.id" /> <NvrHistoryDiagCard :station-code="stationCode" :ndm-nvr="ndmNvr" :key="ndmNvr.id" />
</NTabPane> </NTabPane>
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> --> <!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
<NTabPane v-if="debugModeStore.debugEnabled" name="原始数据" tab="原始数据"> <NTabPane v-if="debugModeEnabled" name="原始数据" tab="原始数据">
<pre class="raw-data">{{ { ...ndmNvr, lastDiagInfo } }}</pre> <pre class="raw-data">{{ { ...ndmNvr, lastDiagInfo } }}</pre>
</NTabPane> </NTabPane>
</NTabs> </NTabs>

View File

@@ -1,9 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import type { NdmSecurityBoxDiagInfo, NdmSecurityBoxResultVO } from '@/apis'; import type { NdmSecurityBoxDiagInfo, NdmSecurityBoxResultVO } from '@/apis';
import { DeviceCommonCard, DeviceHardwareCard, DeviceHeaderCard, SecurityBoxCircuitCard, SecurityBoxHistoryDiagCard, SecurityBoxInfoCard } from '@/components'; import { DeviceCommonCard, DeviceHardwareCard, DeviceHeaderCard, SecurityBoxCircuitCard, SecurityBoxHistoryDiagCard, SecurityBoxInfoCard } from '@/components';
import { useDebugModeStore } from '@/stores'; import { useSettingStore } from '@/stores';
import { destr } from 'destr'; import { destr } from 'destr';
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui'; import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { computed, ref, toRefs } from 'vue'; import { computed, ref, toRefs } from 'vue';
const props = defineProps<{ const props = defineProps<{
@@ -11,7 +12,8 @@ const props = defineProps<{
ndmSecurityBox: NdmSecurityBoxResultVO; ndmSecurityBox: NdmSecurityBoxResultVO;
}>(); }>();
const debugModeStore = useDebugModeStore(); const settingStore = useSettingStore();
const { debugModeEnabled } = storeToRefs(settingStore);
const { stationCode, ndmSecurityBox } = toRefs(props); const { stationCode, ndmSecurityBox } = toRefs(props);
@@ -62,7 +64,7 @@ const selectedTab = ref('设备状态');
<SecurityBoxHistoryDiagCard :station-code="stationCode" :ndm-security-box="ndmSecurityBox" :key="ndmSecurityBox.id" /> <SecurityBoxHistoryDiagCard :station-code="stationCode" :ndm-security-box="ndmSecurityBox" :key="ndmSecurityBox.id" />
</NTabPane> </NTabPane>
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> --> <!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
<NTabPane v-if="debugModeStore.debugEnabled" name="原始数据" tab="原始数据"> <NTabPane v-if="debugModeEnabled" name="原始数据" tab="原始数据">
<pre class="raw-data">{{ { ...ndmSecurityBox, lastDiagInfo } }}</pre> <pre class="raw-data">{{ { ...ndmSecurityBox, lastDiagInfo } }}</pre>
</NTabPane> </NTabPane>
</NTabs> </NTabs>

View File

@@ -1,9 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import type { NdmServerDiagInfo, NdmServerResultVO } from '@/apis'; import type { NdmServerDiagInfo, NdmServerResultVO } from '@/apis';
import { DeviceHardwareCard, DeviceHeaderCard, ServerHistoryDiagCard } from '@/components'; import { DeviceHardwareCard, DeviceHeaderCard, ServerHistoryDiagCard } from '@/components';
import { useDebugModeStore } from '@/stores'; import { useSettingStore } from '@/stores';
import { destr } from 'destr'; import { destr } from 'destr';
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui'; import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { computed, ref, toRefs } from 'vue'; import { computed, ref, toRefs } from 'vue';
const props = defineProps<{ const props = defineProps<{
@@ -11,7 +12,8 @@ const props = defineProps<{
ndmServer: NdmServerResultVO; ndmServer: NdmServerResultVO;
}>(); }>();
const debugModeStore = useDebugModeStore(); const settingStore = useSettingStore();
const { debugModeEnabled } = storeToRefs(settingStore);
const { stationCode, ndmServer } = toRefs(props); const { stationCode, ndmServer } = toRefs(props);
@@ -44,7 +46,7 @@ const selectedTab = ref('设备状态');
<ServerHistoryDiagCard :station-code="stationCode" :ndm-server="ndmServer" :key="ndmServer.id" /> <ServerHistoryDiagCard :station-code="stationCode" :ndm-server="ndmServer" :key="ndmServer.id" />
</NTabPane> </NTabPane>
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> --> <!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
<NTabPane v-if="debugModeStore.debugEnabled" name="原始数据" tab="原始数据"> <NTabPane v-if="debugModeEnabled" name="原始数据" tab="原始数据">
<pre class="raw-data">{{ { ...ndmServer, lastDiagInfo } }}</pre> <pre class="raw-data">{{ { ...ndmServer, lastDiagInfo } }}</pre>
</NTabPane> </NTabPane>
</NTabs> </NTabs>

View File

@@ -1,9 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import type { NdmSwitchDiagInfo, NdmSwitchResultVO } from '@/apis'; import type { NdmSwitchDiagInfo, NdmSwitchResultVO } from '@/apis';
import { DeviceHardwareCard, DeviceHeaderCard, SwitchHistoryDiagCard, SwitchPortCard } from '@/components'; import { DeviceHardwareCard, DeviceHeaderCard, SwitchHistoryDiagCard, SwitchPortCard } from '@/components';
import { useDebugModeStore } from '@/stores'; import { useSettingStore } from '@/stores';
import { destr } from 'destr'; import { destr } from 'destr';
import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui'; import { NCard, NFlex, NTabPane, NTabs } from 'naive-ui';
import { storeToRefs } from 'pinia';
import { computed, ref, toRefs } from 'vue'; import { computed, ref, toRefs } from 'vue';
const props = defineProps<{ const props = defineProps<{
@@ -11,7 +12,8 @@ const props = defineProps<{
ndmSwitch: NdmSwitchResultVO; ndmSwitch: NdmSwitchResultVO;
}>(); }>();
const debugModeStore = useDebugModeStore(); const settingStore = useSettingStore();
const { debugModeEnabled } = storeToRefs(settingStore);
const { stationCode, ndmSwitch } = toRefs(props); const { stationCode, ndmSwitch } = toRefs(props);
@@ -45,7 +47,7 @@ const selectedTab = ref('设备状态');
<SwitchHistoryDiagCard :station-code="stationCode" :ndm-switch="ndmSwitch" :key="ndmSwitch.id" /> <SwitchHistoryDiagCard :station-code="stationCode" :ndm-switch="ndmSwitch" :key="ndmSwitch.id" />
</NTabPane> </NTabPane>
<!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> --> <!-- <NTabPane name="设备配置" tab="设备配置"></NTabPane> -->
<NTabPane v-if="debugModeStore.debugEnabled" name="原始数据" tab="原始数据"> <NTabPane v-if="debugModeEnabled" name="原始数据" tab="原始数据">
<pre class="raw-data">{{ { ...ndmSwitch, lastDiagInfo } }}</pre> <pre class="raw-data">{{ { ...ndmSwitch, lastDiagInfo } }}</pre>
</NTabPane> </NTabPane>
</NTabs> </NTabs>

View File

@@ -1,8 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
import type { VersionInfo } from '@/apis'; import type { VersionInfo } from '@/apis';
import { ThemeSwitch } from '@/components'; import { ThemeSwitch } from '@/components';
import { STATION_LIST_QUERY_KEY } from '@/constants'; import { LINE_STATIONS_QUERY_KEY } from '@/constants';
import { useDebugModeStore, useLayoutStore, useQueryControlStore } from '@/stores'; import { useSettingStore, usePollingStore } from '@/stores';
import { getAppEnvConfig } from '@/utils'; import { getAppEnvConfig } from '@/utils';
import { useQueryClient } from '@tanstack/vue-query'; import { useQueryClient } from '@tanstack/vue-query';
import { useEventListener } from '@vueuse/core'; import { useEventListener } from '@vueuse/core';
@@ -16,16 +16,16 @@ const route = useRoute();
const show = defineModel<boolean>('show'); const show = defineModel<boolean>('show');
const layoutStore = useLayoutStore(); const settingStore = useSettingStore();
const { stationGridColumns } = storeToRefs(layoutStore); const { stationGridColumns, debugModeEnabled } = storeToRefs(settingStore);
const queryControlStore = useQueryControlStore(); const pollingStore = usePollingStore();
const { stationVerifyMode } = storeToRefs(queryControlStore); const { stationVerifyMode } = storeToRefs(pollingStore);
const queryClient = useQueryClient(); const queryClient = useQueryClient();
watch(stationVerifyMode, () => { watch(stationVerifyMode, () => {
queryClient.cancelQueries({ queryKey: [STATION_LIST_QUERY_KEY] }); queryClient.cancelQueries({ queryKey: [LINE_STATIONS_QUERY_KEY] });
queryClient.invalidateQueries({ queryKey: [STATION_LIST_QUERY_KEY] }); queryClient.invalidateQueries({ queryKey: [LINE_STATIONS_QUERY_KEY] });
queryClient.refetchQueries({ queryKey: [STATION_LIST_QUERY_KEY] }); queryClient.refetchQueries({ queryKey: [LINE_STATIONS_QUERY_KEY] });
}); });
const versionInfo = ref<VersionInfo>({ version: '', buildTime: '' }); const versionInfo = ref<VersionInfo>({ version: '', buildTime: '' });
@@ -35,8 +35,6 @@ onMounted(async () => {
versionInfo.value = data; versionInfo.value = data;
}); });
const debugModeStore = useDebugModeStore();
const { debugEnabled } = storeToRefs(debugModeStore);
const debugCodeModalShow = ref(false); const debugCodeModalShow = ref(false);
const debugCode = ref(''); const debugCode = ref('');
const enableDebug = () => { const enableDebug = () => {
@@ -47,11 +45,11 @@ const enableDebug = () => {
} }
debugCodeModalShow.value = false; debugCodeModalShow.value = false;
debugCode.value = ''; debugCode.value = '';
debugModeStore.enableDebug(); settingStore.enableDebugMode();
}; };
const disableDebug = () => { const disableDebug = () => {
debugCodeModalShow.value = false; debugCodeModalShow.value = false;
debugModeStore.disableDebug(); settingStore.disableDebugMode();
}; };
useEventListener('keydown', (event) => { useEventListener('keydown', (event) => {
@@ -76,7 +74,7 @@ useEventListener('keydown', (event) => {
<NInputNumber v-model:value="stationGridColumns" :min="1" :max="10" /> <NInputNumber v-model:value="stationGridColumns" :min="1" :max="10" />
</NFormItem> </NFormItem>
</template> </template>
<template v-if="debugEnabled"> <template v-if="debugModeEnabled">
<NDivider>调试</NDivider> <NDivider>调试</NDivider>
<NFormItem label="车站Ping模式" label-placement="left"> <NFormItem label="车站Ping模式" label-placement="left">
<NRadioGroup v-model:value="stationVerifyMode"> <NRadioGroup v-model:value="stationVerifyMode">
@@ -96,13 +94,13 @@ useEventListener('keydown', (event) => {
<NModal v-model:show="debugCodeModalShow" preset="dialog" type="info"> <NModal v-model:show="debugCodeModalShow" preset="dialog" type="info">
<template #header> <template #header>
<NText v-if="!debugEnabled">请输入调试授权码</NText> <NText v-if="!debugModeEnabled">请输入调试授权码</NText>
<NText v-else>确认关闭调试模式</NText> <NText v-else>确认关闭调试模式</NText>
</template> </template>
<NInput v-if="!debugEnabled" v-model:value="debugCode" placeholder="输入授权码" /> <NInput v-if="!debugModeEnabled" v-model:value="debugCode" placeholder="输入授权码" />
<template #action> <template #action>
<NButton @click="debugCodeModalShow = false">取消</NButton> <NButton @click="debugCodeModalShow = false">取消</NButton>
<NButton v-if="!debugEnabled" type="primary" @click="enableDebug">启用</NButton> <NButton v-if="!debugModeEnabled" type="primary" @click="enableDebug">启用</NButton>
<NButton v-else type="primary" @click="disableDebug">确认</NButton> <NButton v-else type="primary" @click="disableDebug">确认</NButton>
</template> </template>
</NModal> </NModal>

View File

@@ -1,12 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { useThemeStore } from '@/stores'; import { useSettingStore } from '@/stores';
import { MoonOutline, SunnyOutline } from '@vicons/ionicons5'; import { MoonOutline, SunnyOutline } from '@vicons/ionicons5';
import { NIcon, NSwitch } from 'naive-ui'; import { NIcon, NSwitch } from 'naive-ui';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import type { ComponentInstance } from 'vue'; import type { ComponentInstance } from 'vue';
const themeStore = useThemeStore(); const settingStore = useSettingStore();
const { darkThemeEnabled } = storeToRefs(themeStore); const { darkThemeEnabled } = storeToRefs(settingStore);
defineExpose({} as ComponentInstance<typeof NSwitch>); defineExpose({} as ComponentInstance<typeof NSwitch>);
</script> </script>

View File

@@ -1 +0,0 @@
export * from './use-line-alarms-query';

View File

@@ -1 +0,0 @@
export * from './use-line-devices-query';

View File

@@ -1,4 +1,4 @@
export * from './alarm'; export * from './use-line-alarms-query';
export * from './device'; export * from './use-line-devices-query';
export * from './station'; export * from './use-station-list-query';
export * from './system'; export * from './use-version-check-query';

View File

@@ -1 +0,0 @@
export * from './use-station-list-query';

View File

@@ -1 +0,0 @@
export * from './use-version-check-query';

View File

@@ -1,7 +1,7 @@
import { pageDeviceAlarmLogApi, type Station, type StationAlarmCounts } from '@/apis'; import { pageDeviceAlarmLogApi, type Station, type StationAlarmCounts } from '@/apis';
import { LINE_ALARMS_QUERY_KEY } from '@/constants'; import { LINE_ALARMS_QUERY_KEY } from '@/constants';
import { DeviceType, tryGetDeviceTypeVal } from '@/enums'; import { DeviceType, tryGetDeviceTypeVal } from '@/enums';
import { useLineAlarmsStore, useQueryControlStore, useStationStore } from '@/stores'; import { useAlarmStore, usePollingStore, useStationStore } from '@/stores';
import { runTask } from '@/utils'; import { runTask } from '@/utils';
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query'; import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@@ -25,8 +25,8 @@ const createEmptyStationAlarmCounts = () => {
export function useLineAlarmsQuery() { export function useLineAlarmsQuery() {
const stationStore = useStationStore(); const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore); const { stationList } = storeToRefs(stationStore);
const queryControlStore = useQueryControlStore(); const pollingStore = usePollingStore();
const { alarmQueryStamp } = storeToRefs(queryControlStore); const { alarmQueryStamp } = storeToRefs(pollingStore);
const { mutateAsync: getStationAlarmCounts } = useStationAlarmCountsMutation(); const { mutateAsync: getStationAlarmCounts } = useStationAlarmCountsMutation();
return useQuery({ return useQuery({
@@ -42,7 +42,7 @@ export function useLineAlarmsQuery() {
await getStationAlarmCounts({ station, signal }); await getStationAlarmCounts({ station, signal });
} }
console.timeEnd('useLineALarmCountsQuery'); console.timeEnd('useLineALarmCountsQuery');
// queryControlStore.updateAlarmQueryUpdatedAt(); // pollingStore.updateAlarmQueryUpdatedAt();
return null; return null;
}, },
}); });
@@ -54,7 +54,7 @@ interface StationAlarmCountsMutationParams {
} }
function useStationAlarmCountsMutation() { function useStationAlarmCountsMutation() {
const lineAlarmsStore = useLineAlarmsStore(); const lineAlarmsStore = useAlarmStore();
const { lineAlarmCounts } = storeToRefs(lineAlarmsStore); const { lineAlarmCounts } = storeToRefs(lineAlarmsStore);
return useMutation<StationAlarmCounts, Error, StationAlarmCountsMutationParams>({ return useMutation<StationAlarmCounts, Error, StationAlarmCountsMutationParams>({

View File

@@ -1,7 +1,7 @@
import { ndmClient, type Station, type StationDevices } from '@/apis'; import { ndmClient, type Station, type StationDevices } from '@/apis';
import { LINE_DEVICES_QUERY_KEY } from '@/constants'; import { LINE_DEVICES_QUERY_KEY } from '@/constants';
import { DeviceType } from '@/enums'; import { DeviceType } from '@/enums';
import { useLineDevicesStore, useQueryControlStore, useStationStore } from '@/stores'; import { useDeviceStore, usePollingStore, useStationStore } from '@/stores';
import { runTask } from '@/utils'; import { runTask } from '@/utils';
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query'; import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
@@ -32,8 +32,8 @@ const getNdmDevicesAll = async (stationCode: string, signal?: AbortSignal) => {
export function useLineDevicesQuery() { export function useLineDevicesQuery() {
const stationStore = useStationStore(); const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore); const { stationList } = storeToRefs(stationStore);
const queryControlStore = useQueryControlStore(); const pollingStore = usePollingStore();
const { deviceQueryStamp } = storeToRefs(queryControlStore); const { deviceQueryStamp } = storeToRefs(pollingStore);
const { mutateAsync: getStationDevices } = useStationDevicesMutation(); const { mutateAsync: getStationDevices } = useStationDevicesMutation();
return useQuery({ return useQuery({
@@ -49,7 +49,7 @@ export function useLineDevicesQuery() {
await getStationDevices({ station, signal }); await getStationDevices({ station, signal });
} }
console.timeEnd('useLineDevicesQuery'); console.timeEnd('useLineDevicesQuery');
// queryControlStore.updateDeviceQueryUpdatedAt(); // pollingStore.updateDeviceQueryUpdatedAt();
return null; return null;
}, },
}); });
@@ -61,7 +61,7 @@ interface StationDevicesMutationParams {
} }
function useStationDevicesMutation() { function useStationDevicesMutation() {
const lineDevicesStore = useLineDevicesStore(); const lineDevicesStore = useDeviceStore();
const { lineDevices } = storeToRefs(lineDevicesStore); const { lineDevices } = storeToRefs(lineDevicesStore);
return useMutation<StationDevices, Error, StationDevicesMutationParams>({ return useMutation<StationDevices, Error, StationDevicesMutationParams>({

View File

@@ -1,6 +1,6 @@
import { batchVerifyApi, verifyApi, type Station } from '@/apis'; import { batchVerifyApi, verifyApi, type Station } from '@/apis';
import { STATION_LIST_QUERY_KEY } from '@/constants'; import { LINE_STATIONS_QUERY_KEY } from '@/constants';
import { useQueryControlStore, useStationStore } from '@/stores'; import { usePollingStore, useStationStore } from '@/stores';
import { getAppEnvConfig } from '@/utils'; import { getAppEnvConfig } from '@/utils';
import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query'; import { isCancelledError, useMutation, useQuery } from '@tanstack/vue-query';
import axios from 'axios'; import axios from 'axios';
@@ -8,13 +8,13 @@ import dayjs from 'dayjs';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { computed } from 'vue'; import { computed } from 'vue';
export function useStationListQuery() { export function useLineStationsQuery() {
const queryControlStore = useQueryControlStore(); const pollingStore = usePollingStore();
const { pollingEnabled } = storeToRefs(queryControlStore); const { pollingEnabled } = storeToRefs(pollingStore);
const { mutateAsync: getStationList } = useStationListMutation(); const { mutateAsync: getStationList } = useLineStationsMutation();
return useQuery({ return useQuery({
queryKey: computed(() => [STATION_LIST_QUERY_KEY]), queryKey: computed(() => [LINE_STATIONS_QUERY_KEY]),
enabled: computed(() => pollingEnabled.value), enabled: computed(() => pollingEnabled.value),
refetchInterval: getAppEnvConfig().requestInterval * 1000, refetchInterval: getAppEnvConfig().requestInterval * 1000,
staleTime: getAppEnvConfig().requestInterval * 1000, staleTime: getAppEnvConfig().requestInterval * 1000,
@@ -22,8 +22,8 @@ export function useStationListQuery() {
console.time('useStationListQuery'); console.time('useStationListQuery');
await getStationList({ signal }); await getStationList({ signal });
console.timeEnd('useStationListQuery'); console.timeEnd('useStationListQuery');
queryControlStore.updateDeviceQueryStamp(); pollingStore.updateDeviceQueryStamp();
queryControlStore.updateAlarmQueryStamp(); pollingStore.updateAlarmQueryStamp();
return null; return null;
}, },
}); });
@@ -33,11 +33,11 @@ interface StationListMutationParams {
signal?: AbortSignal; signal?: AbortSignal;
} }
function useStationListMutation() { function useLineStationsMutation() {
const stationStore = useStationStore(); const stationStore = useStationStore();
const { stationList } = storeToRefs(stationStore); const { stationList } = storeToRefs(stationStore);
const queryControlStore = useQueryControlStore(); const pollingStore = usePollingStore();
const { stationVerifyMode } = storeToRefs(queryControlStore); const { stationVerifyMode } = storeToRefs(pollingStore);
return useMutation<Station[], Error, StationListMutationParams>({ return useMutation<Station[], Error, StationListMutationParams>({
mutationFn: async ({ signal }) => { mutationFn: async ({ signal }) => {
const { data: ndmStationList } = await axios.get<{ code: string; name: string }[]>(`/minio/ndm/ndm-stations.json?_t=${dayjs().unix()}`, { signal }); const { data: ndmStationList } = await axios.get<{ code: string; name: string }[]>(`/minio/ndm/ndm-stations.json?_t=${dayjs().unix()}`, { signal });

View File

@@ -1,6 +1,6 @@
import type { NdmDeviceAlarmLogResultVO } from '@/apis'; import type { NdmDeviceAlarmLogResultVO } from '@/apis';
import { TOPIC_DEVICE_ALARM } from '@/constants'; import { TOPIC_DEVICE_ALARM } from '@/constants';
import { useCurrentAlarmsStore } from '@/stores'; import { useAlarmStore } from '@/stores';
import { Client } from '@stomp/stompjs'; import { Client } from '@stomp/stompjs';
import { destr } from 'destr'; import { destr } from 'destr';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
@@ -15,8 +15,8 @@ const getBrokerUrl = () => {
}; };
export const useStompClient = () => { export const useStompClient = () => {
const currentAlarmsStore = useCurrentAlarmsStore(); const alarmStore = useAlarmStore();
const { currentAlarmCount } = storeToRefs(currentAlarmsStore); const { unreadAlarmCount } = storeToRefs(alarmStore);
const stompClient = ref<Client | null>(null); const stompClient = ref<Client | null>(null);
onMounted(() => { onMounted(() => {
@@ -30,7 +30,7 @@ export const useStompClient = () => {
stompClient.value?.subscribe(TOPIC_DEVICE_ALARM, (message) => { stompClient.value?.subscribe(TOPIC_DEVICE_ALARM, (message) => {
const alarm = destr<NdmDeviceAlarmLogResultVO>(message.body); const alarm = destr<NdmDeviceAlarmLogResultVO>(message.body);
if (alarm.alarmCategory === '1') { if (alarm.alarmCategory === '1') {
currentAlarmCount.value++; unreadAlarmCount.value++;
} }
}); });
}, },

View File

@@ -1,4 +1,3 @@
export const STATION_LIST_QUERY_KEY = 'station-list'; export const LINE_STATIONS_QUERY_KEY = 'line-stations';
export const LINE_DEVICES_QUERY_KEY = 'line-devices'; export const LINE_DEVICES_QUERY_KEY = 'line-devices';
export const LINE_ALARMS_QUERY_KEY = 'line-alarms'; export const LINE_ALARMS_QUERY_KEY = 'line-alarms';
export const DEVICE_SNMP_LOGS_QUERY_KEY = 'device-snmp-logs';

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,10 +2,13 @@ import type { LineAlarmCounts } from '@/apis';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { ref } from 'vue'; import { ref } from 'vue';
export const useLineAlarmsStore = defineStore('ndm-line-alarms-store', () => { export const useAlarmStore = defineStore('ndm-alarm-store', () => {
const lineAlarmCounts = ref<LineAlarmCounts>({}); const lineAlarmCounts = ref<LineAlarmCounts>({});
const unreadAlarmCount = ref(0);
return { return {
lineAlarmCounts, lineAlarmCounts,
unreadAlarmCount,
}; };
}); });

View File

@@ -1,12 +0,0 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useCurrentAlarmsStore = defineStore('ndm-current-alarms-store', () => {
const currentAlarmCount = ref(0);
const needReload = ref(false);
return {
currentAlarmCount,
needReload,
};
});

View File

@@ -1,24 +0,0 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useDebugModeStore = defineStore(
'ndm-debug-mode-store',
() => {
const debugEnabled = ref(false);
const enableDebug = () => (debugEnabled.value = true);
const disableDebug = () => (debugEnabled.value = false);
return {
debugEnabled,
enableDebug,
disableDebug,
};
},
{
persist: {
pick: ['debugEnabled'],
storage: window.sessionStorage,
},
},
);

View File

@@ -3,14 +3,14 @@ import { tryGetDeviceTypeVal } from '@/enums';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { ref } from 'vue'; import { ref } from 'vue';
export const useLineDevicesStore = defineStore('ndm-line-devices-store', () => { export const useDeviceStore = defineStore('ndm-device-store', () => {
const lineDevices = ref<LineDevices>({}); const lineDevices = ref<LineDevices>({});
const patch = (stationCode: string, device: NdmDeviceResultVO) => { const patch = (stationCode: string, device: NdmDeviceResultVO) => {
const deviceTypeVal = tryGetDeviceTypeVal(device.deviceType); const deviceTypeVal = tryGetDeviceTypeVal(device.deviceType);
if (!!deviceTypeVal) { if (!!deviceTypeVal) {
if (lineDevices.value[stationCode]) { if (lineDevices.value[stationCode]) {
const index = lineDevices.value[stationCode][deviceTypeVal].findIndex((d) => d.id === device.id); const index = lineDevices.value[stationCode][deviceTypeVal].findIndex((dev) => dev.id === device.id);
if (index > -1) { if (index > -1) {
lineDevices.value[stationCode][deviceTypeVal][index] = device; lineDevices.value[stationCode][deviceTypeVal][index] = device;
} }

View File

@@ -1,9 +1,6 @@
export * from './current-alarms'; export * from './alarm';
export * from './debug-mode'; export * from './device';
export * from './layout'; export * from './polling';
export * from './line-alarms';
export * from './line-devices';
export * from './query-control';
export * from './station'; export * from './station';
export * from './theme'; export * from './setting';
export * from './user'; export * from './user';

View File

@@ -1,16 +0,0 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useLayoutStore = defineStore(
'ndm-layout-store',
() => {
const stationGridColumns = ref(6);
return {
stationGridColumns,
};
},
{
persist: true,
},
);

View File

@@ -2,8 +2,8 @@ import dayjs from 'dayjs';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { ref } from 'vue'; import { ref } from 'vue';
export const useQueryControlStore = defineStore( export const usePollingStore = defineStore(
'ndm-query-control-store', 'ndm-polling-store',
() => { () => {
const pollingEnabled = ref(true); const pollingEnabled = ref(true);
const enablePolling = () => (pollingEnabled.value = true); const enablePolling = () => (pollingEnabled.value = true);

46
src/stores/setting.ts Normal file
View File

@@ -0,0 +1,46 @@
import { darkTheme, lightTheme } from 'naive-ui';
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
export const useSettingStore = defineStore(
'ndm-setting-store',
() => {
const darkThemeEnabled = ref(true);
const themeMode = computed(() => {
return darkThemeEnabled.value ? darkTheme : lightTheme;
});
const stationGridColumns = ref(6);
const debugModeEnabled = ref(false);
const enableDebugMode = () => {
debugModeEnabled.value = true;
};
const disableDebugMode = () => {
debugModeEnabled.value = false;
};
return {
darkThemeEnabled,
themeMode,
stationGridColumns,
debugModeEnabled,
enableDebugMode,
disableDebugMode,
};
},
{
persist: [
{
omit: ['debugModeEnabled'],
storage: window.localStorage,
},
{
pick: ['debugModeEnabled'],
storage: window.sessionStorage,
},
],
},
);

View File

@@ -1,21 +0,0 @@
import { ref, computed } from 'vue';
import { defineStore } from 'pinia';
import { darkTheme, lightTheme } from 'naive-ui';
export const useThemeStore = defineStore(
'ndm-theme-store',
() => {
const darkThemeEnabled = ref(true);
const themeMode = computed(() => {
return darkThemeEnabled.value ? darkTheme : lightTheme;
});
return {
darkThemeEnabled,
themeMode,
};
},
{
persist: true,
},
);

View File

@@ -6,7 +6,7 @@ import { defineStore } from 'pinia';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { useStationStore } from './station'; import { useStationStore } from './station';
import { useQueryControlStore } from './query-control'; import { usePollingStore } from './polling';
const getHeaders = () => { const getHeaders = () => {
const { lampAuthorization, lampClientId, lampClientSecret } = getAppEnvConfig(); const { lampAuthorization, lampClientId, lampClientSecret } = getAppEnvConfig();
@@ -131,8 +131,8 @@ export const useUserStore = defineStore(
window.location.reload(); window.location.reload();
}, },
}); });
const queryControlStore = useQueryControlStore(); const pollingStore = usePollingStore();
queryControlStore.disablePolling(); pollingStore.disablePolling();
throw new AxiosError(respData.msg, `${respData.code}`); throw new AxiosError(respData.msg, `${respData.code}`);
} else { } else {
if (lampLoginResultRecord.value === null) { if (lampLoginResultRecord.value === null) {