refactor: 重构项目结构
- 优化 `车站-设备-告警` 轮询机制 - 改进设备卡片的布局 - 支持修改设备 - 告警轮询中获取完整告警数据 - 车站告警详情支持导出完整的 `今日告警列表` - 支持将状态持久化到 `IndexedDB` - 新增轮询控制 (调试模式) - 新增离线开发模式 (调试模式) - 新增 `IndexedDB` 数据控制 (调试模式)
This commit is contained in:
75
src/composables/query/use-version-check-query.ts
Normal file
75
src/composables/query/use-version-check-query.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { verifyApi, type VersionInfo } from '@/apis';
|
||||
import { VERSION_CHECK_QUERY_KEY } from '@/constants';
|
||||
import { useSettingStore, useUserStore } from '@/stores';
|
||||
import { useQuery, useQueryClient } from '@tanstack/vue-query';
|
||||
import axios from 'axios';
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { computed, h, ref, watch } from 'vue';
|
||||
|
||||
export const useVersionCheckQuery = () => {
|
||||
const localVersionInfo = ref<VersionInfo>();
|
||||
const showDialog = ref<boolean>(false);
|
||||
const themeVars = useThemeVars();
|
||||
const queryClient = useQueryClient();
|
||||
const userStore = useUserStore();
|
||||
const { userLoginResult } = storeToRefs(userStore);
|
||||
const settingStore = useSettingStore();
|
||||
const { offlineDev } = storeToRefs(settingStore);
|
||||
|
||||
const { data: remoteVersionInfo, dataUpdatedAt } = useQuery({
|
||||
queryKey: [VERSION_CHECK_QUERY_KEY],
|
||||
enabled: computed(() => !offlineDev.value),
|
||||
refetchInterval: 10 * 1000,
|
||||
queryFn: async ({ signal }) => {
|
||||
if (!!userLoginResult.value?.token) await verifyApi({ signal });
|
||||
const { data } = await axios.get<VersionInfo>(`/manifest.json?t=${Date.now()}`, { signal });
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
watch(offlineDev, (offline) => {
|
||||
if (offline) {
|
||||
queryClient.cancelQueries({ queryKey: [VERSION_CHECK_QUERY_KEY] });
|
||||
}
|
||||
});
|
||||
|
||||
watch(dataUpdatedAt, () => {
|
||||
const newVersionInfo = remoteVersionInfo.value;
|
||||
if (!newVersionInfo) return;
|
||||
|
||||
if (!localVersionInfo.value) {
|
||||
localVersionInfo.value = newVersionInfo;
|
||||
return;
|
||||
}
|
||||
|
||||
const { version: localVersion, buildTime: localBuildTime } = localVersionInfo.value;
|
||||
const { version: remoteVersion, buildTime: remoteBuildTime } = newVersionInfo;
|
||||
|
||||
if ((localVersion !== remoteVersion || localBuildTime !== remoteBuildTime) && !showDialog.value) {
|
||||
showDialog.value = true;
|
||||
window.$dialog.info({
|
||||
title: '发现新版本',
|
||||
content: () =>
|
||||
h('div', {}, [
|
||||
h('div', {}, { default: () => `当前版本:${localVersionInfo.value?.version}` }),
|
||||
h('div', {}, { default: () => `最新版本:${newVersionInfo.version}` }),
|
||||
h('div', {}, { default: () => '请点击刷新页面以更新' }),
|
||||
h('div', { style: { marginTop: '8px', fontWeight: '700', color: themeVars.value.warningColor } }, { default: () => '⚠️ 注意,更新后可能需要重新登录或调整系统设置!' }),
|
||||
]),
|
||||
positiveText: '刷新页面',
|
||||
maskClosable: false,
|
||||
onPositiveClick: () => {
|
||||
window.location.reload();
|
||||
},
|
||||
negativeText: '稍后检查',
|
||||
onNegativeClick: () => {
|
||||
showDialog.value = false;
|
||||
},
|
||||
onClose: () => {
|
||||
showDialog.value = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user