fix: resolve the issue of logout failure caused by the timezone store

This commit is contained in:
zhongming4762
2025-10-30 17:01:49 +08:00
parent ac6de0324c
commit 565be77e96
3 changed files with 183 additions and 18 deletions

View File

@@ -1,7 +1,10 @@
import { ref, unref } from 'vue';
import { DEFAULT_TIME_ZONE_OPTIONS } from '@vben-core/preferences';
import { getTimezone, setDefaultTimezone } from '@vben-core/shared/utils';
import {
getCurrentTimezone,
setCurrentTimezone,
} from '@vben-core/shared/utils';
import { acceptHMRUpdate, defineStore } from 'pinia';
@@ -59,9 +62,7 @@ const getTimezoneHandler = () => {
const useTimezoneStore = defineStore(
'core-timezone',
() => {
const timezoneRef = ref(
getTimezone() || new Intl.DateTimeFormat().resolvedOptions().timeZone,
);
const timezoneRef = ref(getCurrentTimezone());
/**
* 初始化时区
@@ -74,7 +75,7 @@ const useTimezoneStore = defineStore(
timezoneRef.value = timezone;
}
// 设置dayjs默认时区
setDefaultTimezone(unref(timezoneRef));
setCurrentTimezone(unref(timezoneRef));
}
/**
@@ -87,7 +88,7 @@ const useTimezoneStore = defineStore(
await timezoneHandler.setTimezone?.(timezone);
timezoneRef.value = timezone;
// 设置dayjs默认时区
setDefaultTimezone(timezone);
setCurrentTimezone(timezone);
}
/**
@@ -103,10 +104,15 @@ const useTimezoneStore = defineStore(
console.error('Failed to initialize timezone during store setup:', error);
});
function $reset() {
timezoneRef.value = getCurrentTimezone();
}
return {
timezone: timezoneRef,
setTimezone,
getTimezoneOptions,
$reset,
};
},
{