feat: check version
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export * from './alarm';
|
||||
export * from './device';
|
||||
export * from './station';
|
||||
export * from './system';
|
||||
|
||||
1
src/composables/query/system/index.ts
Normal file
1
src/composables/query/system/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './use-version-check-query';
|
||||
53
src/composables/query/system/use-version-check-query.ts
Normal file
53
src/composables/query/system/use-version-check-query.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { useQuery } from '@tanstack/vue-query';
|
||||
import axios from 'axios';
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
export function useVersionCheckQuery() {
|
||||
interface VersionInfo {
|
||||
version: string;
|
||||
buildTime: string;
|
||||
}
|
||||
|
||||
const localVersionInfo = ref<VersionInfo>();
|
||||
const dialogShow = ref<boolean>(false);
|
||||
|
||||
const { data: remoteVersionInfo, dataUpdatedAt } = useQuery({
|
||||
queryKey: ['version-check'],
|
||||
queryFn: async () => {
|
||||
const { data } = await axios.get<VersionInfo>(`/version.json?t=${Date.now()}`);
|
||||
return data;
|
||||
},
|
||||
refetchInterval: 10 * 1000,
|
||||
});
|
||||
|
||||
watch(dataUpdatedAt, () => {
|
||||
const newVersionInfo = remoteVersionInfo.value;
|
||||
if (!newVersionInfo) return;
|
||||
|
||||
if (!localVersionInfo.value) {
|
||||
localVersionInfo.value = newVersionInfo;
|
||||
return;
|
||||
}
|
||||
|
||||
if (localVersionInfo.value.version !== newVersionInfo.version && !dialogShow.value) {
|
||||
dialogShow.value = true;
|
||||
window.$dialog.info({
|
||||
title: '发现新版本',
|
||||
content: '请刷新网页更新',
|
||||
positiveText: '刷新页面',
|
||||
onPositiveClick: () => {
|
||||
window.location.reload();
|
||||
},
|
||||
negativeText: '稍后检查',
|
||||
onNegativeClick: () => {
|
||||
// window.$dialog.destroyAll();
|
||||
dialogShow.value = false;
|
||||
},
|
||||
onClose: () => {
|
||||
// window.$dialog.destroyAll();
|
||||
dialogShow.value = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user