- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8.3k
feat: increase support for multiple time zones #6839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
0a8339a
              b029f77
              61ce53b
              e3e5755
              e01803c
              4d713db
              3eed51f
              212144f
              f46ae02
              bff0a72
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { eventHandler } from 'h3'; | ||
| import { TIME_ZONE_OPTIONS } from '~/utils/mock-data'; | ||
| import { useResponseSuccess } from '~/utils/response'; | ||
|  | ||
| export default eventHandler(() => { | ||
| return useResponseSuccess(TIME_ZONE_OPTIONS); | ||
| }); | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { eventHandler, readBody } from 'h3'; | ||
| import { verifyAccessToken } from '~/utils/jwt-utils'; | ||
| import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response'; | ||
| import { setTimezone } from '~/utils/timezone-utils'; | ||
|  | ||
| export default eventHandler(async (event) => { | ||
| const userinfo = verifyAccessToken(event); | ||
| if (!userinfo) { | ||
| return unAuthorizedResponse(event); | ||
| } | ||
| const { timezone } = await readBody(event); | ||
| setTimezone(timezone); | ||
| return useResponseSuccess(); | ||
| }); | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { eventHandler } from 'h3'; | ||
| import { verifyAccessToken } from '~/utils/jwt-utils'; | ||
| import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response'; | ||
| import { getTimezone } from '~/utils/timezone-utils'; | ||
|  | ||
| export default eventHandler((event) => { | ||
| const userinfo = verifyAccessToken(event); | ||
| if (!userinfo) { | ||
| return unAuthorizedResponse(event); | ||
| } | ||
| return useResponseSuccess(getTimezone()); | ||
| }); | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| let mockTimeZone: null | string = null; | ||
|  | ||
| export const setTimezone = (timeZone: string) => { | ||
| mockTimeZone = timeZone; | ||
| }; | ||
|  | ||
| export const getTimezone = () => { | ||
| return mockTimeZone; | ||
| }; | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './auth'; | ||
| export * from './menu'; | ||
| export * from './user'; | ||
| export * from './user-profile'; | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { TimezoneOption } from '@vben/types'; | ||
|  | ||
| import { requestClient } from '#/api/request'; | ||
|  | ||
| /** | ||
| * 获取系统支持的时区列表 | ||
| */ | ||
| export async function getTimezoneOptionsApi() { | ||
| return requestClient.get<TimezoneOption[]>('/profile/timezone'); | ||
| } | ||
| /** | ||
| * 获取用户时区 | ||
| */ | ||
| export async function getUserTimezoneApi(): Promise<null | string | undefined> { | ||
| return requestClient.get<null | string | undefined>('/user/timezone'); | ||
| } | ||
| /** | ||
| * 设置用户时区 | ||
| * @param timezone 时区 | ||
| */ | ||
| export async function setUserTimezoneApi(timezone: string) { | ||
| return requestClient.post('/user/setTimezone', { timezone }); | ||
| } | 
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,8 @@ | ||||||
| <script lang="ts" setup> | ||||||
| import type { ExtendedModalApi } from '@vben/common-ui'; | ||||||
|          | ||||||
| import type { ExtendedModalApi } from '@vben/common-ui'; | |
| import type { ExtendedModalApi } from '@vben-core/popup-ui'; | 
🤖 Prompt for AI Agents
In apps/web-antd/src/layouts/basic.vue around line 2, the ExtendedModalApi type
is imported from '@vben/common-ui' but should be unified with the widget's
popup-ui; change the import source to the widget module (e.g.
'@vben/widget/popup-ui'), update the import statement accordingly, and ensure
TypeScript path/module resolution is correct so the new module compiles.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './auth'; | ||
| export * from './user-profile'; | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { ref } from 'vue'; | ||
|  | ||
| import { getTimezone, setDefaultTimezone } from '@vben/utils'; | ||
|  | ||
| import { acceptHMRUpdate, defineStore } from 'pinia'; | ||
|  | ||
| import { getUserTimezoneApi, setUserTimezoneApi } from '#/api'; | ||
|  | ||
| const useUserProfileStore = defineStore('user-profile', () => { | ||
| const timezoneRef = ref( | ||
| getTimezone() || new Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
| ); | ||
|  | ||
| /** | ||
| * 设置用户时区 | ||
| * Set the user's timezone | ||
| * @param timezone 时区字符串 | ||
| */ | ||
| async function setTimezone(timezone: string) { | ||
| // 保存用户的时区设置 | ||
| await setUserTimezoneApi(timezone); | ||
| timezoneRef.value = timezone; | ||
| // 设置dayjs默认时区 | ||
| setDefaultTimezone(timezone); | ||
| } | ||
|  | ||
| /** | ||
| * 初始化用户时区 | ||
| * Initialize the user's timezone | ||
| */ | ||
| async function initTimezone() { | ||
| // 从服务器获取用户时区 | ||
| const timezone = await getUserTimezoneApi(); | ||
| if (timezone) { | ||
| timezoneRef.value = timezone; | ||
| // 设置dayjs默认时区 | ||
| setDefaultTimezone(timezone); | ||
| } | ||
| } | ||
|          | ||
|  | ||
| initTimezone(); | ||
|  | ||
| return { | ||
| timezone: timezoneRef, | ||
| setTimezone, | ||
| initTimezone, | ||
| }; | ||
| }); | ||
|  | ||
| export { useUserProfileStore }; | ||
|  | ||
| // 解决热更新问题 | ||
| const hot = import.meta.hot; | ||
| if (hot) { | ||
| hot.accept(acceptHMRUpdate(useUserProfileStore, hot)); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './auth'; | ||
| export * from './menu'; | ||
| export * from './user'; | ||
| export * from './user-profile'; | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { TimezoneOption } from '@vben/types'; | ||
|  | ||
| import { requestClient } from '#/api/request'; | ||
|  | ||
| /** | ||
| * 获取系统支持的时区列表 | ||
| */ | ||
| export async function getTimezoneOptionsApi() { | ||
| return requestClient.get<TimezoneOption[]>('/profile/timezone'); | ||
| } | ||
| /** | ||
| * 获取用户时区 | ||
| */ | ||
| export async function getUserTimezoneApi(): Promise<null | string | undefined> { | ||
| return requestClient.get<null | string | undefined>('/user/timezone'); | ||
| } | ||
| /** | ||
| * 设置用户时区 | ||
| * @param timezone 时区 | ||
| */ | ||
| export async function setUserTimezoneApi(timezone: string) { | ||
| return requestClient.post('/user/setTimezone', { timezone }); | ||
| } | 
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,8 @@ | ||||||
| <script lang="ts" setup> | ||||||
| import type { ExtendedModalApi } from '@vben/common-ui'; | ||||||
|          | ||||||
| import type { ExtendedModalApi } from '@vben/common-ui'; | |
| import type { ExtendedModalApi } from '@vben-core/popup-ui'; | 
🤖 Prompt for AI Agents
In apps/web-ele/src/layouts/basic.vue around line 2, the file imports
ExtendedModalApi from '@vben/common-ui' which is a different modal API than the
one used by TimezoneButton; replace this import with the same ExtendedModalApi
export used by the popup-ui widget source (the exact module used by
TimezoneButton, e.g. import type { ExtendedModalApi } from '@popup-ui/common-ui'
or the popup-ui package path in the repo) so both components reference the
identical type and avoid TypeScript incompatibility.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './auth'; | ||
| export * from './user-profile'; | 
Uh oh!
There was an error while loading. Please reload this page.