feat: check version
This commit is contained in:
@@ -16,9 +16,12 @@ import { defineComponent } from 'vue';
|
||||
import { useThemeStore } from '@/stores/theme';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { VueQueryDevtools } from '@tanstack/vue-query-devtools';
|
||||
import { useVersionCheckQuery } from './composables/query';
|
||||
|
||||
const themeStore = useThemeStore();
|
||||
const { themeMode } = storeToRefs(themeStore);
|
||||
|
||||
useVersionCheckQuery();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { tgz, zip } from 'compressing';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import packageJson from '../../package.json';
|
||||
|
||||
const now = dayjs();
|
||||
|
||||
const fileName = `${packageJson.name}_v${packageJson.version}_${now.format('YYMMDD-HHmmss')}`;
|
||||
|
||||
try {
|
||||
await zip.compressDir('./dist', `${fileName}.zip`);
|
||||
await tgz.compressDir('./dist', `${fileName}.tar`);
|
||||
await tgz.compressDir('./dist', `${fileName}.tar.gz`);
|
||||
} catch (error) {
|
||||
console.error('压缩失败:', error);
|
||||
}
|
||||
Reference in New Issue
Block a user