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