feat: increase support for multiple time zones

This commit is contained in:
zhongming4762
2025-10-22 19:52:01 +08:00
parent 03ce030e7c
commit 0a8339a405
32 changed files with 577 additions and 9 deletions

View File

@@ -1,7 +1,8 @@
<script lang="ts" setup>
import type { ExtendedModalApi } from '@vben/common-ui';
import type { NotificationItem } from '@vben/layouts';
import { computed, ref, watch } from 'vue';
import { computed, onMounted, ref, watch } from 'vue';
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
@@ -11,16 +12,21 @@ import {
BasicLayout,
LockScreen,
Notification,
TimezoneButton,
UserDropdown,
} from '@vben/layouts';
import { preferences } from '@vben/preferences';
import { useAccessStore, useUserStore } from '@vben/stores';
import { openWindow } from '@vben/utils';
import { useMessage } from 'naive-ui';
import { getTimezoneOptionsApi } from '#/api';
import { $t } from '#/locales';
import { useAuthStore } from '#/store';
import { useAuthStore, useUserProfileStore } from '#/store';
import LoginForm from '#/views/_core/authentication/login.vue';
const message = useMessage();
const notifications = ref<NotificationItem[]>([
{
avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB',
@@ -60,6 +66,29 @@ const showDot = computed(() =>
notifications.value.some((item) => !item.isRead),
);
const userProfileStore = useUserProfileStore();
const computedTimezone = computed(() => userProfileStore.timezone);
const timezoneOptions = ref<string[]>([]);
onMounted(async () => {
timezoneOptions.value = ((await getTimezoneOptionsApi()) || []).map(
(item) => item.timezone,
);
});
const handleSetTimezone = async (
timezone: string,
modalApi: ExtendedModalApi,
) => {
try {
modalApi.setState({ confirmLoading: true });
await userProfileStore.setTimezone(timezone);
message.success($t('ui.widgets.timezone.setSuccess'));
modalApi.close();
} finally {
modalApi.setState({ confirmLoading: false });
}
};
const menus = computed(() => [
{
handler: () => {
@@ -148,6 +177,14 @@ watch(
@make-all="handleMakeAll"
/>
</template>
<template #timezone>
<TimezoneButton
:ok-handler="handleSetTimezone"
:timezone="computedTimezone"
:timezone-options="timezoneOptions"
name="out"
/>
</template>
<template #extra>
<AuthenticationLoginExpiredModal
v-model:open="accessStore.loginExpired"