fix(version-check): clear localStorage if need

This commit is contained in:
yangsy
2025-11-19 13:54:41 +08:00
parent 5fa668acd3
commit dfbdc6d828
4 changed files with 17 additions and 1 deletions

3
.env
View File

@@ -15,5 +15,8 @@ VITE_LAMP_PASSWORD = fjoc(1KHP(Ls&Bje)C
# 如果 Authorization 已存在则会直接采用, 否则会根据 clientId 和 clientSecret 生成
VITE_LAMP_AUTHORIZATION = Y3VlZGVzX2FkbWluOmN1ZWRlc19hZG1pbl9zZWNyZXQ=
# 当需要重置localStorage时, 修改此变量
VITE_STORAGE_VERSION = 1
# 调试授权码
VITE_DEBUG_CODE = ndm_debug

View File

@@ -1,11 +1,13 @@
import type { VersionInfo } from '@/apis/domains/version-info';
import { useQuery } from '@tanstack/vue-query';
import axios from 'axios';
import { useThemeVars } from 'naive-ui';
import { h, ref, watch } from 'vue';
export function useVersionCheckQuery() {
const localVersionInfo = ref<VersionInfo>();
const dialogShow = ref<boolean>(false);
const themeVars = useThemeVars();
const { data: remoteVersionInfo, dataUpdatedAt } = useQuery({
queryKey: ['version-check'],
@@ -37,6 +39,7 @@ export function useVersionCheckQuery() {
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,

View File

@@ -1,13 +1,21 @@
import { getAppEnvConfig } from '@/utils/env';
import { VueQueryPlugin } from '@tanstack/vue-query';
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import persist from 'pinia-plugin-persistedstate';
import { VueQueryPlugin } from '@tanstack/vue-query';
import App from './App.vue';
import router from './router';
import '@/styles/reset.scss';
const { storageVersion } = getAppEnvConfig();
const localStorageVersion = window.localStorage.getItem('ndm-storage-version');
if (localStorageVersion !== storageVersion) {
window.localStorage.clear();
window.localStorage.setItem('ndm-storage-version', storageVersion);
}
const app = createApp(App);
app.use(createPinia().use(persist));

View File

@@ -10,6 +10,7 @@ export const getAppEnvConfig = () => {
VITE_LAMP_PASSWORD,
VITE_LAMP_AUTHORIZATION,
VITE_DEBUG_CODE,
VITE_STORAGE_VERSION,
} = env;
return {
requestInterval: Number.parseInt(VITE_REQUEST_INTERVAL as string),
@@ -20,5 +21,6 @@ export const getAppEnvConfig = () => {
lampPassword: VITE_LAMP_PASSWORD as string,
lampAuthorization: VITE_LAMP_AUTHORIZATION as string,
debugCode: VITE_DEBUG_CODE as string,
storageVersion: VITE_STORAGE_VERSION as string,
};
};